From 29b20f388bad9c6e3c48cdb0b5d8f3c02d226a00 Mon Sep 17 00:00:00 2001
From: Malaurie Bernard <mbernard@kinouby>
Date: Fri, 28 Jul 2023 11:11:49 +0200
Subject: [PATCH] Adding a few methods in motor.cpp to have the distinction
 between move and moveTo from the Accelstepper librairie. In fact I created
 same methods using moveTo but using move and I change comments t explin how
 it works.

I think it would be useful to see later if we are using all these methods
or if some of them can be deleted.
---
 motor.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 motor.h   | 10 ++++++-
 2 files changed, 79 insertions(+), 10 deletions(-)

diff --git a/motor.cpp b/motor.cpp
index e196547..5543a0e 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 3ad86aa..972cba9 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
-- 
GitLab