Tarek Lule / MotorLib

Fork of MotorLib by CreaLab

Committer:
garphil
Date:
Fri Jun 17 11:44:22 2016 +0000
Revision:
1:9519ac966b79
Parent:
0:bd05fd602a6e
Child:
2:c91c5ef00d25
Still few errors to correct on class Motor

Who changed what in which revision?

UserRevisionLine numberNew contents of line
garphil 0:bd05fd602a6e 1 // -------------------- Motor ---------------------------
garphil 0:bd05fd602a6e 2 #include "mbed.h"
garphil 0:bd05fd602a6e 3
garphil 0:bd05fd602a6e 4 enum MotorStateList { // Define Motor States for the State Machine
garphil 0:bd05fd602a6e 5 Motor_IDLE = 0,
garphil 0:bd05fd602a6e 6 Motor_RUN,
garphil 0:bd05fd602a6e 7 Motor_PAUSE,
garphil 0:bd05fd602a6e 8 Motor_ZERO,
garphil 0:bd05fd602a6e 9 Motor_CALIB
garphil 0:bd05fd602a6e 10 } MotorState = Motor_IDLE;
garphil 0:bd05fd602a6e 11
garphil 0:bd05fd602a6e 12 enum MotorCommandList { // Define Motor State Machine Commands
garphil 0:bd05fd602a6e 13 k_nop = 0,
garphil 0:bd05fd602a6e 14 k_wire,
garphil 0:bd05fd602a6e 15 k_pause,
garphil 0:bd05fd602a6e 16 k_restart,
garphil 0:bd05fd602a6e 17 k_stop,
garphil 0:bd05fd602a6e 18 k_zero
garphil 0:bd05fd602a6e 19 } MotorCommand;
garphil 0:bd05fd602a6e 20
garphil 0:bd05fd602a6e 21 enum MotorDirectionList { // Define Motor Clockwise or Anticlockwise
garphil 0:bd05fd602a6e 22 d_clock = 0,
garphil 0:bd05fd602a6e 23 d_anti
garphil 0:bd05fd602a6e 24 } MotorDir;
garphil 0:bd05fd602a6e 25
garphil 0:bd05fd602a6e 26 class Motor {
garphil 0:bd05fd602a6e 27
garphil 0:bd05fd602a6e 28 Motor(PinName _MPh0, PinName _MPh1, PinName _MPh2, PinName _MPh3);
garphil 1:9519ac966b79 29 void StopMotor();
garphil 1:9519ac966b79 30 void RunMotor();
garphil 1:9519ac966b79 31 void LeftMotor();
garphil 1:9519ac966b79 32 void RightMotor();
garphil 1:9519ac966b79 33 void TurnMotor(uint32_t NumTurns);
garphil 1:9519ac966b79 34 void ProcessMotorStateMachine();
garphil 0:bd05fd602a6e 35
garphil 0:bd05fd602a6e 36 DigitalOut *MPh0, *MPh1, *MPh2, *MPh3;
garphil 0:bd05fd602a6e 37
garphil 0:bd05fd602a6e 38 int MotorIndex; // --- Motor Variable
garphil 1:9519ac966b79 39
garphil 0:bd05fd602a6e 40 Ticker MotorSystemTick; // System Callback for Motor
garphil 0:bd05fd602a6e 41 timestamp_t MotorStepTime; // Time in µs for one motor step
garphil 0:bd05fd602a6e 42 uint32_t MotorFullTurn; // Number of step for a complete turn
garphil 0:bd05fd602a6e 43 uint32_t NumWires; // Number of Wires
garphil 0:bd05fd602a6e 44 uint32_t NumSteps; // Number of Steps = NumWire * MotorFullTurn
garphil 0:bd05fd602a6e 45
garphil 0:bd05fd602a6e 46 }