A class for driving a stepper motor via driver with indexer.

Dependents:   StepperTest

Revision:
1:9888802e71b9
Parent:
0:12be56dc6182
Child:
2:70f593d34039
--- a/StepperDriver.h	Thu Dec 01 13:35:45 2016 +0000
+++ b/StepperDriver.h	Fri Dec 02 08:35:20 2016 +0000
@@ -3,14 +3,82 @@
 
 #include "mbed.h"
 
+/** A class for driving a stepper motor in open loop.
+  * A driver must contain an indexer and sequencer.
+  * Each generated pulse moves the rotor by one step in a given direction.
+  */
 class StepperDriver {
+    
     public:
-    StepperDriver(PinName, PinName);
-    void setPosition(uint32_t);
+    
+    /** Constructor receives output pin and direction pin.
+      * @param outputPin DigitalOut pin for sending pulses to the driver.
+      * @param directionPin DigitalOut pin for setting a direction of rotation.
+      */
+    StepperDriver(PinName outputPin, PinName directionPin);
+    
+    /** Sets the motor resolution in steps per revolution (uint32_t) and minimum and maximum 
+      * angle in degrees (angles range).
+      * @param resolution Resolution of the stepper motor in steps per revolution (uint32_t). 
+      * Typical value is 200 steps per revolution, and that value is set by default in this class.
+      * @param minDegrees Minimum angle in degrees.
+      * @param maxDegrees Maximum angle in degrees.
+      */
+    void configure(uint32_t resolution, float minDegrees, float maxDegrees);
+    
+    /** Sets the motor resolution in degrees per step (float) and minimum and maximum 
+      * angle in degrees (angles range). 
+      * @param resolution Resolution of the stepper motor in degrees per step (float).
+      * Typical value is 1.8 degrees per step, and that value is set by default in this class.
+      * @param minDegrees Minimum angle in degrees.
+      * @param maxDegrees Maximum angle in degrees.
+      */
+    void configure(float resolution, float minDegrees, float maxDegrees);
+    
+    /** Sets the position in degrees.
+      * @param desiredPosition Desired position in degrees.
+      */
+    void setPosition(float desiredPosition);
     
-    private:
+    /** Get the current position in degrees.
+      * @returns Current position in degrees.
+      */
+    float getPosition();
+    
+    /** Set the speed in rpm (revolutions per minute). 
+      * @param speedRPM Motor speed in rpm (revolutions per minute).
+      */
+    void setSpeedRPM(float speedRPM);
+    
+    /** Set the speed in revolutions per second. 
+      * @param speedRPS Motor speed in revolutions per second.
+      */
+    void setSpeedRPS(float speedRPS);
+    
+    /** Set the speed in steps per second. 
+      * @param speedSPS Motor speed in rpm (revolutions per minute).
+      */
+    void setSpeedSPS(float speedSPS);
+    
+    /** Get the speed in rpm (revolutions per minute). 
+      * @returns Motor speed in rpm (revolutions per minute).
+      */
+    float getSpeedRPM();
+    
+    /** Get the speed in revolutions per second. 
+      * @returns Motor speed in revolutions per second.
+      */
+    float getSpeedRPS();
+    
+    /** Get the speed in steps per second. 
+      * @returns Motor speed in steps per second.
+      */
+    float getSpeedSPS();
+    
+    protected:
     DigitalOut output, direction;
     uint32_t currentPosition, previousPosition, homePosition, minPosition, maxPosition, desiredPosition;
+    float degreesPerStep, pulseWidth, speed;
     Ticker ticker;
     Timeout timeout;
     void update();
@@ -19,6 +87,9 @@
     void generateImpulse();
     void turnOutputOff();
     bool isTickerAttached;
+    void setResolution(uint32_t resolution);
+    void setResolution(float resolution);
+    void setDegreesRange(float minDegrees, float maxDegrees);
 };
 
 #endif
\ No newline at end of file