Michael Marzano / Mbed 2 deprecated Linear_Stepper_Motor_Nema17

Dependencies:   mbed

Revision:
7:0d941d1140ad
Parent:
5:955bbc08ee78
Child:
8:f1d869d9b8df
--- a/lin_step_mtr.h	Mon Apr 27 14:42:19 2020 +0000
+++ b/lin_step_mtr.h	Mon Apr 27 17:26:51 2020 +0000
@@ -15,7 +15,6 @@
 #define MBED_LIN_STEP_MTR
  
 #include "mbed.h"
-#include "rtos.h"
 
 
  
@@ -25,6 +24,8 @@
 #define DEFAULT_RPM 300   // RPM (1rpm = 3.333 steps/sec)
 #define MAX_RPM 400       // RPM
 #define MIN_RPM 150       // in RPM
+#define MAX_DOUBLE_VAL 9223372036854775800
+#define MIN_DOUBLE_VAL -9223372036854775800
  
 /** Linear Stepper Motor control class
  *
@@ -37,25 +38,9 @@
  *  @endcode
  */
  
-class Step {
- public:
- 
- private:
- 
- }; 
- 
 class LinStepMtr {
  
 public:
-
-    /** Constants for motor rotate control */
-    typedef enum  {
-        COIL_A_FOR = 0,         // Forward Polarity in H-Bright Port A
-        COIL_B_FOR = 1,         // Forward Polarity in H-Bright Port B
-        COIL_A_REV = 2,         // Reverse Polarity in H-Bright Port A
-        COIL_B_REV = 3,         // Reverse Polarity in H-Bright Port B
-        STOP_MOTOR = 4         // Turn Off Both Coils
-    } Polarity;
     
     /** Direction Control **/
     typedef enum {
@@ -101,15 +86,27 @@
      */
     float get_speed();
     
+    
     /** Sets the value of speed in RPM 
      */
-    //void set_speed(float f);
+    void set_speed(float rpm);
     
     /** Gets the number of revolutions since motor was initialized.
      *  Positive means more CW than CCW movement, negative is opposite
      */
     double get_rev();
     
+    /** Getters and Setters for {min,max}_rev_cnt
+     *
+     */
+    void set_min_rev_cnt(double rc);
+    double get_min_rev_cnt();
+    void set_max_rev_cnt(double rc);
+    double get_max_rev_cnt();
+    
+    
+    void RESET_rev_cnts();
+    
     
     /** Gets the current direction
      *
@@ -121,50 +118,14 @@
      */
     //void set_dir(Direction d);
     
-    /** Initializes the rotate thread and sets parameters before you begin
-     *
-     */
-    void init(double rpm=DEFAULT_RPM, Direction d=CW);
-    
-    /** Ends possibility of motion
-     *
-     */
-    void end();
        
-    /** Rotates the motor for a set number of rotations
-     *
-     */
-    //double rotate(float num_rev);
-    
-    /** Starts continuous motion in the current direction
+    /** Rotates the motor for a set number of rotations in the given direction
      *
      */
-    void start();
-    
-     /** Starts continuous motion in the given direction
-     *
-     */
-    void start(Direction d);
-    
-    /** Stops continuous motion
-     *
-     */
-    void stop();
-    
-    /** Changes the direction of motion
-     * 
-     */
-    void change_dir(Direction d);
-    
-    /** Changes the speed
-     *
-     */
-    void change_speed(float rpm);
-
+    double rotate(Direction d, float rev=.25);
     
     
-
-
+//private:
     class Step {
      public:     
         //constructior
@@ -180,20 +141,13 @@
         Step_Num get_cur_step();
         
      private:
-        static const int step_one =     0b1100;
+/*        static const int step_one =     0b1100;
         static const int step_two =     0b0110;
         static const int step_three =   0b0011;
-        static const int step_four =    0b1001;
-        volatile Step_Num cur_step;
+        static const int step_four =    0b1001; */
+        Step_Num cur_step;
      
      }; 
-//private:
-
-    /** Continuously rotates the motor in the specified direction
-     *  lives in it's own thread
-     */
-    void rotate();
-    static void rotate_help(void const *args);
     
     /** Spins up the motor by stepping up from min speed to desired speed
      *
@@ -211,18 +165,13 @@
     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
+        = (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 
-    volatile Direction dir;                 // The direction for the motor to run
-    
-    Thread *rotate_th;                       // Thread to run the rotate function
-    volatile bool stop_mtr;                 // Flag for if motor should be off;
-    volatile bool terminate;                // Flag for if the rotate function should stop executing
-   
- private:   
-    volatile Polarity cur_state;            // Current State of H-Brige Controls
+    volatile int speed;                          // Speed of Rotation (in steps per second)
+    volatile double rev_cnt;                     // Current Revolution of motor
+    volatile double min_rev_cnt;                 // software limit for lowest rev count the moter can reach.
+    volatile double max_rev_cnt;                 // software limit for highest rev count the moter can reach. 
+    Step cur_step;                      // Current Step, i.e. which one was just written to the motor 
+    Direction dir;                      // The direction for the motor to run
 };
 #endif
\ No newline at end of file