diff --git a/motor.cpp b/motor.cpp index e196547546695dad072e6f0b7539386c09d14e7f..5543a0e84b65c108d232311bccff17152118bf5f 100644 --- a/motor.cpp +++ b/motor.cpp @@ -97,9 +97,9 @@ float Motor :: step_to_mm (int step) const //MOVEMENTS void Motor :: move_to_step_limit_switch (int step) /*** --Argument : Number of step. +-Argument : Final position in steps. -Return : / --Action : Move the number of step required. +-Action : Move to the number of step required to go to the final position. Can manage the emergency. ***/ { #if !CORE_MOCK @@ -114,9 +114,9 @@ void Motor :: move_to_step_limit_switch (int step) void Motor :: move_to_mm_limit_switch (float mm) /*** --Argument : distance in mm +-Argument : Final position in mm. -Return : / --Action : Move to the distance required. +-Action : Move to the distance required to go to the final position. Can manage the emergency. ***/ { Serial.printf("# moving to %g mm / %g steps\n", @@ -127,9 +127,10 @@ void Motor :: move_to_mm_limit_switch (float mm) void Motor :: move_to_step (int step) /*** --Argument : Number of step. +/*** +-Argument : Final position in steps. -Return : / --Action : Move the number of step required. +-Action : Move to the number of step required to go to the final position. ***/ { #if !CORE_MOCK @@ -143,9 +144,9 @@ void Motor :: move_to_step (int step) void Motor :: move_to_mm (float mm) /*** --Argument : distance in mm +-Argument : Final position in mm. -Return : / --Action : Move to the distance required. +-Action : Move to the distance required to go to the final position. ***/ { Serial.printf("# moving to %g mm / %g steps\n", @@ -154,7 +155,6 @@ void Motor :: move_to_mm (float mm) move_to_step(mm_to_step(mm)); } - void Motor :: stop () /*** -Argument : / @@ -186,6 +186,67 @@ void Motor :: stay_here () sei(); #endif } +////////////////// +void Motor :: move_step_limit_switch (int step) +/*** +-Argument : Mouvement required in steps. +-Return : / +-Action : Move the number of step asked. Can manage the emergency. +***/ +{ +#if !CORE_MOCK + cli(); + set_retain_acceleration_mm_per_sec_per_sec(_retain_acceleration_mm_per_sec_per_sec); + if (_mm_per_revolution > 0 && _steps_per_revolution > 0) + stepper.move(_clockwise_equals_forward? step: -step); + sei(); +#endif + Serial.printf("# move to: %d step %g mm\n", step, step_to_mm(step)); +} + +void Motor :: move_mm_limit_switch (float mm) +/*** +-Argument : Mouvement required in distance in mm. +-Return : / +-Action : Move the distance asked. Can manage the emergency. +***/ +{ + Serial.printf("# moving to %g mm / %g steps\n", + mm, + mm_to_step(mm)); + move_step_limit_switch(mm_to_step(mm)); +} + + +void Motor :: move_step (int step) +/*** +-Argument : Mouvement required in steps. +-Return : / +-Action : Move to the number of step. +***/ +{ +#if !CORE_MOCK + cli(); + if (_mm_per_revolution > 0 && _steps_per_revolution > 0) + stepper.move(_clockwise_equals_forward? step: -step); + sei(); +#endif + Serial.printf("# move to: %d step %g mm\n", step, step_to_mm(step)); +} + +void Motor :: move_mm (float mm) +/*** +-Argument : Mouvement required in distance in mm. +-Return : / +-Action : Move the distance asked. +***/ +{ + Serial.printf("# moving to %g mm / %g steps\n", + mm, + mm_to_step(mm)); + move_step(mm_to_step(mm)); +} +////////////////////// bool Motor :: motor_is_running () //return true if the motor is currently running /*** diff --git a/motor.h b/motor.h index 3ad86aa05b0d255c9b1b49c60e1b366eb0407bad..972cba9c9baaca5f08073f52f13b542145e97038 100644 --- a/motor.h +++ b/motor.h @@ -67,8 +67,16 @@ public: void move_to_mm_limit_switch (float mm); void move_to_step (int step); void move_to_mm (float mm); + void stop (); - void stay_here (); + void stay_here (); + + void move_step_limit_switch (int step); + void move_mm_limit_switch (float mm); + void move_step (int step); + void move_mm (float mm); + + bool motor_is_running (); //POSITION