Library for the VNH5019 Motor Driver, with a helper class for the Pololu Dual VNH5019 Dual Motor Driver Shield http://www.pololu.com/product/2502

Dependents:   VNH5019_second VNH5019_second1

Committer:
ianmcc
Date:
Sat Feb 01 14:46:45 2014 +0000
Revision:
1:5e8d9ed18f0f
Parent:
0:5d3ab0ea7f27
Child:
2:d670a4b999ab
Refactor into a VNH5019 class to control a single motor, and a helper class for the dual shield.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ianmcc 0:5d3ab0ea7f27 1 #ifndef DualVNH5019MotorShield_h
ianmcc 0:5d3ab0ea7f27 2 #define DualVNH5019MotorShield_h
ianmcc 0:5d3ab0ea7f27 3
ianmcc 0:5d3ab0ea7f27 4 #include <mbed.h>
ianmcc 0:5d3ab0ea7f27 5
ianmcc 1:5e8d9ed18f0f 6 class VNH5019
ianmcc 1:5e8d9ed18f0f 7 {
ianmcc 1:5e8d9ed18f0f 8 public:
ianmcc 1:5e8d9ed18f0f 9 VNH5019(PinName INA_, PinName INB_, PinName ENDIAG_, PinName CS_, PinName PWM_);
ianmcc 1:5e8d9ed18f0f 10
ianmcc 1:5e8d9ed18f0f 11 // set motor speed from -1.0 to +1.0
ianmcc 1:5e8d9ed18f0f 12 void speed(float Speed);
ianmcc 1:5e8d9ed18f0f 13
ianmcc 1:5e8d9ed18f0f 14 // stop (no current to the motors)
ianmcc 1:5e8d9ed18f0f 15 void stop();
ianmcc 1:5e8d9ed18f0f 16
ianmcc 1:5e8d9ed18f0f 17 // Brake, with strength 0..1
ianmcc 1:5e8d9ed18f0f 18 void brake(float Brake);
ianmcc 1:5e8d9ed18f0f 19
ianmcc 1:5e8d9ed18f0f 20 // returns the current through the motor, in mA
ianmcc 1:5e8d9ed18f0f 21 float get_current_mA();
ianmcc 1:5e8d9ed18f0f 22
ianmcc 1:5e8d9ed18f0f 23 // returns true if there has been a fault
ianmcc 1:5e8d9ed18f0f 24 bool is_fault();
ianmcc 1:5e8d9ed18f0f 25
ianmcc 1:5e8d9ed18f0f 26 // Clears the fault condition
ianmcc 1:5e8d9ed18f0f 27 // PRECONDITION: is_fault()
ianmcc 1:5e8d9ed18f0f 28 void clear_fault();
ianmcc 1:5e8d9ed18f0f 29
ianmcc 1:5e8d9ed18f0f 30 // disable the motor, and set outputs to zero. This is a low power mode.
ianmcc 1:5e8d9ed18f0f 31 void disable();
ianmcc 1:5e8d9ed18f0f 32
ianmcc 1:5e8d9ed18f0f 33 // enable the motor.
ianmcc 1:5e8d9ed18f0f 34 void enable();
ianmcc 1:5e8d9ed18f0f 35
ianmcc 1:5e8d9ed18f0f 36 private:
ianmcc 1:5e8d9ed18f0f 37 void init(); // Initialize TIMER 1, set the PWM to 20kHZ.
ianmcc 1:5e8d9ed18f0f 38
ianmcc 1:5e8d9ed18f0f 39 DigitalOut INA;
ianmcc 1:5e8d9ed18f0f 40 DigitalOut INB;
ianmcc 1:5e8d9ed18f0f 41 DigitalInOut ENDIAG;
ianmcc 1:5e8d9ed18f0f 42 AnalogIn CS;
ianmcc 1:5e8d9ed18f0f 43 PwmOut PWM;
ianmcc 1:5e8d9ed18f0f 44 };
ianmcc 1:5e8d9ed18f0f 45
ianmcc 1:5e8d9ed18f0f 46 // Helper class for the Pololu dual VNH5019 motor shield.
ianmcc 1:5e8d9ed18f0f 47 // The default constructor uses the default arduino pins.
ianmcc 1:5e8d9ed18f0f 48 // The motors can be accessed either by .m1 or .m2, or by operator()(i) where i is 1 or 2.
ianmcc 0:5d3ab0ea7f27 49 class DualVNH5019MotorShield
ianmcc 0:5d3ab0ea7f27 50 {
ianmcc 0:5d3ab0ea7f27 51 public:
ianmcc 0:5d3ab0ea7f27 52 // default pin selection
ianmcc 0:5d3ab0ea7f27 53 DualVNH5019MotorShield(); // Default pin selection.
ianmcc 0:5d3ab0ea7f27 54
ianmcc 0:5d3ab0ea7f27 55 // User-defined pin selection.
ianmcc 0:5d3ab0ea7f27 56 DualVNH5019MotorShield(PinName INA1_, PinName INB1_, PinName ENDIAG1_, PinName CS1_, PinName PWM1_,
ianmcc 0:5d3ab0ea7f27 57 PinName INA2_, PinName INB2_, PinName ENDIAG2_, PinName CS2_, PinName PWM2_);
ianmcc 0:5d3ab0ea7f27 58
ianmcc 1:5e8d9ed18f0f 59 // returns the given motor object, 1 or 2.
ianmcc 1:5e8d9ed18f0f 60 VNH5019& operator()(int m);
ianmcc 0:5d3ab0ea7f27 61
ianmcc 1:5e8d9ed18f0f 62 VNH5019 m1;
ianmcc 1:5e8d9ed18f0f 63 VNH5019 m2;
ianmcc 0:5d3ab0ea7f27 64 };
ianmcc 0:5d3ab0ea7f27 65
ianmcc 0:5d3ab0ea7f27 66 #endif