diff --git a/motor.cpp b/motor.cpp index 98bcb50a285135c074754b9973506a5a927a14fb..5b8bd36eaf1224d8b777dacd37f99dbe71c04eee 100644 --- a/motor.cpp +++ b/motor.cpp @@ -4,7 +4,7 @@ Motor :: Motor (MotorHardware_t& stepper): stepper(stepper) { set_speed_mm_per_sec(1); - set_accel_mm_per_sec_per_sec(0.5); // <----- this is not yet configured by user + retain_acceleration_mm_per_sec_per_sec(0.5); // <----- this is not yet configured by user } @@ -27,13 +27,14 @@ void Motor :: set_mm_per_revolution (float mm_per_revolution) _mm_per_revolution = mm_per_revolution; } -void Motor :: set_accel_mm_per_sec_per_sec (float acceleration_mm_per_sec_per_sec) +void Motor :: retain_acceleration_mm_per_sec_per_sec (float retain_acceleration_mm_per_sec_per_sec) +//This is useful only to use the limit switch { - if (acceleration_mm_per_sec_per_sec == 0) - acceleration_mm_per_sec_per_sec = 1000; - _acceleration_mm_per_sec_per_sec = acceleration_mm_per_sec_per_sec; + if (_retain_acceleration_mm_per_sec_per_sec == 0) + retain_acceleration_mm_per_sec_per_sec = 1000; + _retain_acceleration_mm_per_sec_per_sec = retain_acceleration_mm_per_sec_per_sec; #if !CORE_MOCK - stepper.setAcceleration(mm_to_step(acceleration_mm_per_sec_per_sec)); + stepper.setAcceleration(mm_to_step(retain_acceleration_mm_per_sec_per_sec)); #endif } @@ -66,9 +67,9 @@ bool Motor :: get_clockwise_equals_forward () return _clockwise_equals_forward; } -float Motor :: get_accel_mm_per_sec_per_sec () const +float Motor :: get_retain_acceleration_mm_per_sec_per_sec () const { - return _acceleration_mm_per_sec_per_sec; + return _retain_acceleration_mm_per_sec_per_sec; } @@ -94,7 +95,7 @@ float Motor :: step_to_mm (int step) const } //MOVEMENTS -void Motor :: move_to_step (int step) +void Motor :: move_to_step_limit_switch (int step) /*** -Argument : Number of step. -Return : / @@ -103,7 +104,7 @@ void Motor :: move_to_step (int step) { #if !CORE_MOCK cli(); - set_accel_mm_per_sec_per_sec(_acceleration_mm_per_sec_per_sec); + retain_acceleration_mm_per_sec_per_sec(_retain_acceleration_mm_per_sec_per_sec); if (_mm_per_revolution > 0 && _steps_per_revolution > 0) stepper.moveTo(_clockwise_equals_forward? step: -step); sei(); @@ -111,7 +112,20 @@ void Motor :: move_to_step (int step) Serial.printf("# move to: %d step %g mm\n", step, step_to_mm(step)); } -void Motor :: move_step (int step) +void Motor :: move_to_mm_limit_switch (float mm) +/*** +-Argument : distance in mm +-Return : / +-Action : Move to the distance required. +***/ +{ + Serial.printf("# moving to %g mm / %g steps\n", + mm, + mm_to_step(mm)); + move_to_step_limit_switch(mm_to_step(mm)); +} + +void Motor :: move_to_step (int step) /*** -Argument : Number of step. -Return : / @@ -133,19 +147,6 @@ void Motor :: move_to_mm (float mm) -Return : / -Action : Move to the distance required. ***/ -{ - Serial.printf("# moving to %g mm / %g steps\n", - mm, - mm_to_step(mm)); - move_to_step(mm_to_step(mm)); -} - -void Motor :: move_mm (float mm) -/*** --Argument : distance in mm --Return : / --Action : Move to the distance required. -***/ { Serial.printf("# moving to %g mm / %g steps\n", mm, @@ -181,7 +182,7 @@ void Motor :: stay_here () cli(); stepper.setAcceleration(1e20); stepper.moveTo(stepper.currentPosition()); // change target to here - set_accel_mm_per_sec_per_sec(_acceleration_mm_per_sec_per_sec); + retain_acceleration_mm_per_sec_per_sec(_retain_acceleration_mm_per_sec_per_sec); sei(); #endif } diff --git a/motor.h b/motor.h index b6a142b298208cd17eeb44b74464f205e2412dcf..fbb7f835b65823b176d1eb8462b702e0ca9ab256 100644 --- a/motor.h +++ b/motor.h @@ -47,7 +47,7 @@ public: void set_steps_per_revolution(float steps_per_revolution); void set_mm_per_revolution (float mm_per_revolution); - void set_accel_mm_per_sec_per_sec (float acceleration_mm_per_sec_per_sec); + void retain_acceleration_mm_per_sec_per_sec (float acceleration_mm_per_sec_per_sec); void set_clockwise_equals_forward (bool forward_clockwise); void set_speed_mm_per_sec (float mm_per_sec); @@ -56,17 +56,17 @@ public: float get_steps_per_revolution(); float get_mm_per_revolution () const; bool get_clockwise_equals_forward (); - float get_accel_mm_per_sec_per_sec () const; + float get_retain_acceleration_mm_per_sec_per_sec () const; //CONVERSIONS float mm_to_step (float mm) const; float step_to_mm (int step) const; //MOVEMENTS + void move_to_step_limit_switch (int step); + void move_to_mm_limit_switch (float mm); void move_to_step (int step); - void move_step (int step); void move_to_mm (float mm); - void move_mm (float mm); void stop (); void stay_here (); bool motor_is_running (); @@ -83,7 +83,7 @@ protected: int _steps_per_revolution = -1; float _mm_per_revolution = -1; - float _acceleration_mm_per_sec_per_sec = -1; + float _retain_acceleration_mm_per_sec_per_sec = -1; //Useful for the limit switch bool _clockwise_equals_forward; MotorHardware_t& stepper; diff --git a/syringefilled.cpp b/syringefilled.cpp index 500091f37f30416563361df5a46d15ec6ee9c7aa..f65ccfcf1cf36426e2e2136511c2618481c8334b 100644 --- a/syringefilled.cpp +++ b/syringefilled.cpp @@ -187,7 +187,7 @@ void SyringeFilled :: move() if (where_step() == 0) //If we are putting the syringe for the first time { - move_to_mm(get_syringe_pump_length_mm() - remaining_volume_mm3/section_mm2); + move_to_mm_limit_switch(get_syringe_pump_length_mm() - remaining_volume_mm3/section_mm2); } else { @@ -195,11 +195,11 @@ void SyringeFilled :: move() if (get_push()) //If we want to deliver some liquid { - move_to_mm(initial_position_mm + exchange_volume_mm3/section_mm2); + move_to_mm_limit_switch(initial_position_mm + exchange_volume_mm3/section_mm2); } else //If we want to recover some liquid { - move_to_mm(initial_position_mm - exchange_volume_mm3/section_mm2); + move_to_mm_limit_switch(initial_position_mm - exchange_volume_mm3/section_mm2); } } @@ -222,7 +222,7 @@ void SyringeFilled :: go_to_zero() { set_speed_mm_per_sec(-1); reset_position(); - move_to_mm(-200); + move_to_mm_limit_switch(-200); } } @@ -273,7 +273,7 @@ if (get_emergency()) Serial.printf("EMERGENCY: running away slowly\n"); set_speed_mm_per_sec(-1); reset_position(); - move_to_mm(200); + move_to_mm_limit_switch(200); } } diff --git a/web.cpp b/web.cpp index 6c6a46448014bc82a3591b725f3d23c2d1a4390f..f1b389e4028d7f1ef66d62acacae3ffec41f50ba 100644 --- a/web.cpp +++ b/web.cpp @@ -214,9 +214,8 @@ void fast_backward_callback (Control *sender, int type) case B_DOWN: syringe_filled.reset_position(); - syringe_filled.move_mm(-50); + syringe_filled.move_to_mm(-50); syringe_filled.set_speed_mm_per_sec(50); - syringe_filled.set_accel_mm_per_sec_per_sec(10); break; @@ -248,9 +247,8 @@ void fast_forward_callback (Control *sender, int type) Serial.printf("Forward 10 steps"); syringe_filled.reset_position(); - syringe_filled.move_mm(50); + syringe_filled.move_to_mm(50); syringe_filled.set_speed_mm_per_sec(50); - syringe_filled.set_accel_mm_per_sec_per_sec(10); break; @@ -280,9 +278,8 @@ void slow_backward_callback (Control *sender, int type) case B_DOWN: syringe_filled.reset_position(); - syringe_filled.move_mm(-50); + syringe_filled.move_to_mm(-50); syringe_filled.set_speed_mm_per_sec(0.5); - syringe_filled.set_accel_mm_per_sec_per_sec(0.2); break; @@ -312,9 +309,8 @@ void slow_forward_callback (Control *sender, int type) case B_DOWN: syringe_filled.reset_position(); - syringe_filled.move_mm(50); + syringe_filled.move_to_mm(50); syringe_filled.set_speed_mm_per_sec(0.5); - syringe_filled.set_accel_mm_per_sec_per_sec(0.2); break;