Michael Marzano / Mbed 2 deprecated Linear_Stepper_Motor_Nema17

Dependencies:   mbed

Revision:
3:2138b69ee3bd
Parent:
1:757a52db1604
Child:
4:1dc350268172
--- a/lin_step_mtr.h	Mon Apr 20 02:54:17 2020 +0000
+++ b/lin_step_mtr.h	Mon Apr 20 03:54:54 2020 +0000
@@ -22,9 +22,9 @@
 /**********
 * Defines *
 **********/
-#define DEFAULT_SPEED 300   // RPM (1rpm = 3.333 steps/sec)
-#define MAX_SPEED 400       // RPM
-#define MIN_SPEED 150       // in RPM
+#define DEFAULT_RPM 300   // RPM (1rpm = 3.333 steps/sec)
+#define MAX_RPM 400       // RPM
+#define MIN_RPM 150       // in RPM
  
 /** Linear Stepper Motor control class
  *
@@ -88,9 +88,9 @@
      *  @param A_r DigitalOut pin for Reverse Control of H-Brigde Port A (AIN2)
      *  @param B_f DigitalOut pin for Forward Control of H-Brigde Port B (BIN1)
      *  @param B_r DigitalOut pin for Reverse Control of H-Brigde Port B (BIN2)
-     *  @param m_speed Sets the max speed  in RPM of the motor
+     *  @param m_rpm Sets the max speed  in RPM of the motor
      */
-    LinStepMtr(PinName A_f, PinName A_r, PinName B_f, PinName B_r, int m_speed);
+    LinStepMtr(PinName A_f, PinName A_r, PinName B_f, PinName B_r, int m_rpm);
     
     /** Destructor
      */
@@ -124,7 +124,7 @@
     /** Initializes the rotate thread and sets parameters before you begin
      *
      */
-    void init(double rpm=DEFAULT_SPEED, Direction d=CW);
+    void init(double rpm=DEFAULT_RPM, Direction d=CW);
     
     /** Ends possibility of motion
      *
@@ -154,19 +154,7 @@
     /** Changes the speed
      *
      */
-    void change_speed(float s);
-    
-    /** Spins up the motor by stepping up from min speed to current speed
-     *
-     */
-    void spin_up();
-    void spin_up(double rpm);
-    
-    /** Spins down the motor by stepping speed down from current speed to 0
-     *
-     */
-    void spin_down();
-    void spin_down(double rpm);
+    void change_speed(float rpm);
 
     
     
@@ -202,21 +190,24 @@
     void rotate();
     static void rotate_help(void const *args);
     
-    /** Spins up the motor by stepping up from min speed to current speed
+    /** Spins up the motor by stepping up from min speed to desired speed
      *
      */
-    void spin_up(float rpm);
+    void spin_up(float rpm=-1);
     
-    /** Spins down the motor by stepping speed down from current speed to 0
+    /** Spins down the motor by stepping speed down from current speed to min_speed
      *
      */
-    void spin_down(float rpm);
+    int spin_down(float rpm=-1);
         
     /** Variables **/
     BusOut mtr_ctrl;                  // 4-bit Bus Controlling the H-Brigde
                                             // form A B A' B'
-    const int max_speed;                    // Software Limit for max rpm in RPM
-    static const int min_speed = MIN_SPEED; // Software Limit for min rpm in RPM
+    const int max_speed;                    // Software Limit for max rpm in steps/second
+    const float max_rpm;
+    static const int min_speed 
+        = (float)MIN_RPM * 10 / 3; // Software Limit for min rpm in steps/sec
+    static const int min_rpm = MIN_RPM;
     volatile int speed;                     // Speed of Rotation (in steps per second)
     volatile double rev_cnt;                // Current Revolution of motor
     Step cur_step;                 // Current Step, i.e. which one was just written to the motor