Merge branch 'check-if-moving'

Move commands were blocking in the original firmware, non-blocking moves
break some pysangaboard functions so this adds blocking moves as an
option along moving? command to check if a move is in progress and
notify-on-stop command which responds when a command finishes.

See !1 for more details.
This commit is contained in:
Filip Ayazi 2021-07-14 00:55:02 +01:00
commit 638c13676b
2 changed files with 57 additions and 2 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
.venv/

View file

@ -16,11 +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()
{
@ -48,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);
}
@ -110,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;
if (blocking_moves){
notify_on_stop = true;
}
else
{
Serial.println("done.");
}
}
void stage_loop()
@ -164,6 +175,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)
@ -254,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;
@ -267,6 +300,24 @@ 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");
}
void activate_notify_on_stop(String command)
{
if (!stage_moving)
{
Serial.println("Error: stage is not moving");
}
else
{
notify_on_stop = true;
}
}
//TODO: move help strings to program memory
//F() cannot be used outside block context though
extern const Command stage_commands[] = {
@ -279,6 +330,9 @@ 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},
{"notify_on_stop", activate_notify_on_stop},
{"blocking_moves", update_blocking_moves},
END_COMMAND};