Skip to content

Commit 60b6869

Browse files
authored
Merge pull request #2 from adam-pearson-automata/feat/robot-training-cli-tool
feat: Add necessary commands for robot training cli tool.
2 parents 166a008 + 4e732c4 commit 60b6869

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/bin/mock_server.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl RobotState {
5050
free_mode: false,
5151
system_speed: 50,
5252
rail_position: Some(0.0),
53-
motion_state: "Idle".to_string(),
53+
motion_state: 1.to_string(),
5454
selected_robot: None,
5555
}
5656
}
@@ -161,15 +161,23 @@ fn process_command(command: &str, robot_state: Arc<Mutex<RobotState>>) -> String
161161
"halt" => "0 \r\n".to_string(),
162162

163163
"loc" => {
164-
let _state = robot_state.lock().unwrap();
165-
"0 1 300.0 0.0 150.0 0.0 90.0 -180.0\r\n".to_string()
164+
let state = &mut robot_state.lock().unwrap();
165+
format!(
166+
"0 0 0 {} {} {} {} {} {}\r\n",
167+
state.position[0],
168+
state.position[1],
169+
state.position[2],
170+
state.position[3],
171+
state.position[4],
172+
state.position[5]
173+
)
166174
}
167175

168176
"locXYZ" => {
169177
if parts.len() < 8 {
170178
"-1 Insufficient parameters\r\n".to_string()
171179
} else {
172-
"0 \r\n".to_string()
180+
format!("0 {}\r\n", parts[2..8].join(" "))
173181
}
174182
}
175183

@@ -191,12 +199,20 @@ fn process_command(command: &str, robot_state: Arc<Mutex<RobotState>>) -> String
191199
}
192200

193201
"movec" => {
194-
let state = robot_state.lock().unwrap();
202+
let state = &mut robot_state.lock().unwrap();
195203
if !state.power {
196204
"-1046 Robot power not enabled\r\n".to_string()
197205
} else if parts.len() < 7 {
198206
"-1 Insufficient parameters\r\n".to_string()
199207
} else {
208+
state.position = [
209+
parts[2].parse().unwrap_or(0.0),
210+
parts[3].parse().unwrap_or(0.0),
211+
parts[4].parse().unwrap_or(0.0),
212+
parts[5].parse().unwrap_or(0.0),
213+
parts[6].parse().unwrap_or(0.0),
214+
parts[7].parse().unwrap_or(0.0),
215+
];
200216
"0 \r\n".to_string()
201217
}
202218
}
@@ -324,6 +340,14 @@ fn process_command(command: &str, robot_state: Arc<Mutex<RobotState>>) -> String
324340
"0 \r\n".to_string()
325341
}
326342

343+
"rail" => {
344+
"0 \r\n".to_string()
345+
}
346+
347+
"sig" => {
348+
"0 1 \r\n".to_string()
349+
}
350+
327351
"exit" => "0 \r\n".to_string(),
328352

329353
_ => format!("-1 Unknown command: {}\r\n", cmd),

src/commands.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ pub enum TCSCommand {
2727
SystemSpeed,
2828
Payload,
2929
WaitForEOM,
30+
Rail,
31+
Signal,
3032
}
3133

3234
impl fmt::Display for TCSCommand {
@@ -56,6 +58,8 @@ impl fmt::Display for TCSCommand {
5658
TCSCommand::SystemSpeed => "mspeed",
5759
TCSCommand::Payload => "payload",
5860
TCSCommand::WaitForEOM => "waitForEOM",
61+
TCSCommand::Rail => "rail",
62+
TCSCommand::Signal => "sig"
5963
};
6064
write!(f, "{}", s)
6165
}

0 commit comments

Comments
 (0)