My Version of the Crealab MotorLib.
Fork of MotorLib by
Revision 0:bd05fd602a6e, committed 2016-06-17
- Comitter:
- garphil
- Date:
- Fri Jun 17 11:16:07 2016 +0000
- Child:
- 1:9519ac966b79
- Commit message:
- Class first template
Changed in this revision
motor.cpp | Show annotated file Show diff for this revision Revisions of this file |
motor.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/motor.cpp Fri Jun 17 11:16:07 2016 +0000 @@ -0,0 +1,15 @@ +#include "motor.h" + + + +Motor::Motor(PinName _MPh0, PinName _MPh1, PinName _MPh2, PinName _MPh3):DigitalOut(_MPh0), DigitalOut(_MPh1), DigitalOut(_MPh2), DigitalOut(_MPh3) { + + MotorIndex = 0; + +} + +void Motor::StopMotor() // --- Stop Motor +{ + MPh0 = 0; MPh1 = 0; MPh2 = 0; MPh3 = 0; + MotorIndex = 0; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/motor.h Fri Jun 17 11:16:07 2016 +0000 @@ -0,0 +1,42 @@ +// -------------------- Motor --------------------------- +#include "mbed.h" + +enum MotorStateList { // Define Motor States for the State Machine + Motor_IDLE = 0, + Motor_RUN, + Motor_PAUSE, + Motor_ZERO, + Motor_CALIB + } MotorState = Motor_IDLE; + +enum MotorCommandList { // Define Motor State Machine Commands + k_nop = 0, + k_wire, + k_pause, + k_restart, + k_stop, + k_zero + } MotorCommand; + +enum MotorDirectionList { // Define Motor Clockwise or Anticlockwise + d_clock = 0, + d_anti + } MotorDir; + +class Motor { + + Motor(PinName _MPh0, PinName _MPh1, PinName _MPh2, PinName _MPh3); + + DigitalOut *MPh0, *MPh1, *MPh2, *MPh3; + + + int MotorIndex; // --- Motor Variable + + + Ticker MotorSystemTick; // System Callback for Motor + timestamp_t MotorStepTime; // Time in µs for one motor step + uint32_t MotorFullTurn; // Number of step for a complete turn + uint32_t NumWires; // Number of Wires + uint32_t NumSteps; // Number of Steps = NumWire * MotorFullTurn + +} \ No newline at end of file