PWM/Direction Motor Driver compatible with VNH3SP30 Motor Driver Carrier MD01B
MotorDriver.h@0:be45415ffe07, 2014-09-27 (annotated)
- Committer:
- OPSHUD
- Date:
- Sat Sep 27 07:18:56 2014 +0000
- Revision:
- 0:be45415ffe07
- Child:
- 1:4b1582384e71
Created Motor Driver Library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
OPSHUD | 0:be45415ffe07 | 1 | #include "mbed.h" |
OPSHUD | 0:be45415ffe07 | 2 | /** PWM/Direction Motor Driver |
OPSHUD | 0:be45415ffe07 | 3 | * Compatible with VNH3SP30 Motor Driver Carrier MD01B |
OPSHUD | 0:be45415ffe07 | 4 | * |
OPSHUD | 0:be45415ffe07 | 5 | * Example: |
OPSHUD | 0:be45415ffe07 | 6 | * @code |
OPSHUD | 0:be45415ffe07 | 7 | * #include "MotorDriver.h" |
OPSHUD | 0:be45415ffe07 | 8 | * MotorDriver motor(p21, p5, p6); |
OPSHUD | 0:be45415ffe07 | 9 | * int main() { |
OPSHUD | 0:be45415ffe07 | 10 | * while(true) { |
OPSHUD | 0:be45415ffe07 | 11 | * motor = -0.5; |
OPSHUD | 0:be45415ffe07 | 12 | * wait(0.5); |
OPSHUD | 0:be45415ffe07 | 13 | * motor = -1; |
OPSHUD | 0:be45415ffe07 | 14 | * wait(0.5); |
OPSHUD | 0:be45415ffe07 | 15 | * motor = -0.5; |
OPSHUD | 0:be45415ffe07 | 16 | * wait(0.5); |
OPSHUD | 0:be45415ffe07 | 17 | * motor = 0; |
OPSHUD | 0:be45415ffe07 | 18 | * wait(0.5) |
OPSHUD | 0:be45415ffe07 | 19 | * motor = 0.5; |
OPSHUD | 0:be45415ffe07 | 20 | * wait(0.5) |
OPSHUD | 0:be45415ffe07 | 21 | * motor = 1; |
OPSHUD | 0:be45415ffe07 | 22 | * wait(0.5); |
OPSHUD | 0:be45415ffe07 | 23 | * motor = 0.5; |
OPSHUD | 0:be45415ffe07 | 24 | * wait(0.5); |
OPSHUD | 0:be45415ffe07 | 25 | * motor = 0; |
OPSHUD | 0:be45415ffe07 | 26 | * wait(0.5); |
OPSHUD | 0:be45415ffe07 | 27 | * } |
OPSHUD | 0:be45415ffe07 | 28 | * } |
OPSHUD | 0:be45415ffe07 | 29 | * @endcode |
OPSHUD | 0:be45415ffe07 | 30 | * @author Michael Vartan |
OPSHUD | 0:be45415ffe07 | 31 | */ |
OPSHUD | 0:be45415ffe07 | 32 | class MotorDriver { |
OPSHUD | 0:be45415ffe07 | 33 | public: |
OPSHUD | 0:be45415ffe07 | 34 | /** |
OPSHUD | 0:be45415ffe07 | 35 | * Create a PWM/Direction motor on the specified pins. |
OPSHUD | 0:be45415ffe07 | 36 | * @param PwmPin The pin which sends PWM Output to the motor driver |
OPSHUD | 0:be45415ffe07 | 37 | * @param directionPin1 The first of two direction pins to the motor driver |
OPSHUD | 0:be45415ffe07 | 38 | * @param directionPin2 The second of two direction pins to the motor driver |
OPSHUD | 0:be45415ffe07 | 39 | */ |
OPSHUD | 0:be45415ffe07 | 40 | MotorDriver(PinName PWMPin, PinName directionPin1, PinName directionPin2); |
OPSHUD | 0:be45415ffe07 | 41 | |
OPSHUD | 0:be45415ffe07 | 42 | /** |
OPSHUD | 0:be45415ffe07 | 43 | * Sets the PWM duty cycle to the absolute value of your percentage, and the direction as |
OPSHUD | 0:be45415ffe07 | 44 | * the sign of your value. |
OPSHUD | 0:be45415ffe07 | 45 | * @param value From -1.0 to 1.0, the percentage you want to run your motor at. |
OPSHUD | 0:be45415ffe07 | 46 | */ |
OPSHUD | 0:be45415ffe07 | 47 | void SetValue(float value); |
OPSHUD | 0:be45415ffe07 | 48 | |
OPSHUD | 0:be45415ffe07 | 49 | /** |
OPSHUD | 0:be45415ffe07 | 50 | * Gets the last value assigned to the motor driver. |
OPSHUD | 0:be45415ffe07 | 51 | * |
OPSHUD | 0:be45415ffe07 | 52 | * @returns motor driver value |
OPSHUD | 0:be45415ffe07 | 53 | */ |
OPSHUD | 0:be45415ffe07 | 54 | float GetValue() const; |
OPSHUD | 0:be45415ffe07 | 55 | |
OPSHUD | 0:be45415ffe07 | 56 | /** |
OPSHUD | 0:be45415ffe07 | 57 | * Shorthand for GetValue |
OPSHUD | 0:be45415ffe07 | 58 | */ |
OPSHUD | 0:be45415ffe07 | 59 | MotorDriver& operator=(float value); |
OPSHUD | 0:be45415ffe07 | 60 | private: |
OPSHUD | 0:be45415ffe07 | 61 | PwmOut mPWM; |
OPSHUD | 0:be45415ffe07 | 62 | DigitalOut mDir1; |
OPSHUD | 0:be45415ffe07 | 63 | DigitalOut mDir2; |
OPSHUD | 0:be45415ffe07 | 64 | float mValue; |
OPSHUD | 0:be45415ffe07 | 65 | }; |