From 4cf54971a2f8620f960c45293b773b45beb9d3f3 Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Wed, 23 Jun 2021 17:16:17 +0100 Subject: [PATCH 1/4] Added a command to check if the stage is moving --- .gitignore | 1 + src/modules/stage/stage.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 89cc49c..933c44f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .vscode/c_cpp_properties.json .vscode/launch.json .vscode/ipch +.venv/ \ No newline at end of file diff --git a/src/modules/stage/stage.cpp b/src/modules/stage/stage.cpp index c37c1f0..4949ddc 100644 --- a/src/modules/stage/stage.cpp +++ b/src/modules/stage/stage.cpp @@ -267,6 +267,12 @@ void stage_stop(String command) Serial.println("Move aborted"); } +void is_stage_moving(String command) +{ + //TODO: should I bother checking for a ? + Serial.println(stage_moving?"true":"false"); +} + //TODO: move help strings to program memory //F() cannot be used outside block context though extern const Command stage_commands[] = { @@ -279,6 +285,7 @@ extern const Command stage_commands[] = { {"ramp_time", stage_ramp_time}, {"min_step_delay", stage_min_step_delay}, {"dt", stage_min_step_delay}, - {"zero", stage_min_step_delay}, + {"zero", stage_zero}, {"stop", stage_stop}, + {"moving", is_stage_moving}, END_COMMAND}; \ No newline at end of file From 71f0da35a231f2bf23ac91a37411120b1e59f4d6 Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Wed, 23 Jun 2021 18:54:29 +0100 Subject: [PATCH 2/4] Added command to notify when stage stops This allows simpler emulation of blocking moves. We may want to improve the way this works... --- src/modules/stage/stage.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/modules/stage/stage.cpp b/src/modules/stage/stage.cpp index 4949ddc..8118aea 100644 --- a/src/modules/stage/stage.cpp +++ b/src/modules/stage/stage.cpp @@ -21,6 +21,7 @@ signed long current_pos[n_motors]; long steps_remaining[n_motors]; bool stage_moving = false; +bool notify_on_stop = false; void stage_setup() { @@ -164,6 +165,11 @@ void stage_loop() } } } + if (!stage_moving && notify_on_stop) + { + Serial.println("stopped"); + notify_on_stop = false; + } } void stage_move_single_axis(uint8_t axis, String command) @@ -273,6 +279,11 @@ void is_stage_moving(String command) Serial.println(stage_moving?"true":"false"); } +void activate_notify_on_stop(String command) +{ + notify_on_stop = true; +} + //TODO: move help strings to program memory //F() cannot be used outside block context though extern const Command stage_commands[] = { @@ -288,4 +299,5 @@ extern const Command stage_commands[] = { {"zero", stage_zero}, {"stop", stage_stop}, {"moving", is_stage_moving}, + {"notify_on_stop", activate_notify_on_stop}, END_COMMAND}; \ No newline at end of file From 165f61986910588cb62add5b1467a88c5ed60e78 Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Wed, 23 Jun 2021 19:55:14 +0100 Subject: [PATCH 3/4] notify_on_stop errors if not moving notify_on_stop now gives an error if it's called while the stage is not moving. This means you can safely issue the command and await a response. If the stage is moving, it will block until the stage stops. If it's not moving, it will return immediately. --- src/modules/stage/stage.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/modules/stage/stage.cpp b/src/modules/stage/stage.cpp index 8118aea..555db65 100644 --- a/src/modules/stage/stage.cpp +++ b/src/modules/stage/stage.cpp @@ -281,7 +281,14 @@ void is_stage_moving(String command) void activate_notify_on_stop(String command) { - notify_on_stop = true; + if (!stage_moving) + { + Serial.println("Error: stage is not moving"); + } + else + { + notify_on_stop = true; + } } //TODO: move help strings to program memory From 83aa9c113a30aacdd27f1cdd58e1e688cc444efa Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Wed, 23 Jun 2021 20:13:41 +0100 Subject: [PATCH 4/4] Add a command to make moves blocking if desired --- src/modules/stage/stage.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/modules/stage/stage.cpp b/src/modules/stage/stage.cpp index 555db65..350e8a3 100644 --- a/src/modules/stage/stage.cpp +++ b/src/modules/stage/stage.cpp @@ -16,12 +16,14 @@ const int min_step_delay_eeprom = sizeof(long) * n_motors; long ramp_time; const int ramp_time_eeprom = sizeof(long) * (n_motors + 1); const int axis_max_eeprom = sizeof(long) * (n_motors + 2); +const int blocking_moves_eeprom = sizeof(long) * (n_motors + 3); Stepper *motors[n_motors]; signed long current_pos[n_motors]; long steps_remaining[n_motors]; bool stage_moving = false; bool notify_on_stop = false; +bool blocking_moves = false; void stage_setup() { @@ -49,6 +51,8 @@ void stage_setup() ramp_time = 0; EEPROM.put(ramp_time_eeprom, ramp_time); } + EEPROM.get(blocking_moves_eeprom, blocking_moves); + // TODO: do we need to do something to initialise this? register_module(stage_commands, stage_loop); } @@ -111,7 +115,13 @@ void start_move(long displ[n_motors]) move_start_time = micros(); final_scaled_t = (float)max_steps * min_step_delay; //NB total time taken will be final_scaled_t + 2*ramp_time stage_moving = true; - Serial.println("done."); + if (blocking_moves){ + notify_on_stop = true; + } + else + { + Serial.println("done."); + } } void stage_loop() @@ -260,6 +270,23 @@ void stage_ramp_time(String command) free(args[0]); } +void update_blocking_moves(String command) +{ + char * args[1]; + parse_arguments(args, command, 1); + if (args[0][0] == '?') + { + Serial.print("blocking_moves "); + Serial.println(blocking_moves ? "true" : "false"); + } + else + { + blocking_moves = args[0][0] == 't'; + EEPROM.put(blocking_moves_eeprom, blocking_moves); + Serial.println("done."); + } +} + void stage_zero(String command) { EACH_MOTOR current_pos[i] = 0; @@ -307,4 +334,5 @@ extern const Command stage_commands[] = { {"stop", stage_stop}, {"moving", is_stage_moving}, {"notify_on_stop", activate_notify_on_stop}, + {"blocking_moves", update_blocking_moves}, END_COMMAND}; \ No newline at end of file