Tarek Lule / MotorLib

Fork of MotorLib by CreaLab

Committer:
garphil
Date:
Mon Jul 17 11:45:44 2017 +0000
Revision:
8:4dd59b6f4e92
Parent:
7:439458133bba
Child:
9:5983c10d5f8e
Removed some warnings. Not tested!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
garphil 0:bd05fd602a6e 1 // -------------------- Motor ---------------------------
garphil 5:9886fd337a4b 2 #ifdef MOTOR_H
garphil 5:9886fd337a4b 3 #else
garphil 5:9886fd337a4b 4 #define MOTOR_H
garphil 5:9886fd337a4b 5
garphil 0:bd05fd602a6e 6 #include "mbed.h"
garphil 0:bd05fd602a6e 7
garphil 2:c91c5ef00d25 8 typedef enum MotorStateList { // Define Motor States for the State Machine
garphil 0:bd05fd602a6e 9 Motor_IDLE = 0,
garphil 0:bd05fd602a6e 10 Motor_RUN,
garphil 0:bd05fd602a6e 11 Motor_PAUSE,
garphil 0:bd05fd602a6e 12 Motor_ZERO,
garphil 0:bd05fd602a6e 13 Motor_CALIB
garphil 2:c91c5ef00d25 14 } MotorState;
garphil 2:c91c5ef00d25 15
garphil 2:c91c5ef00d25 16 typedef enum MotorCommandList { // Define Motor State Machine Commands
garphil 2:c91c5ef00d25 17 MOTOR_nop = 0,
garphil 2:c91c5ef00d25 18 MOTOR_start,
garphil 2:c91c5ef00d25 19 MOTOR_pause,
garphil 2:c91c5ef00d25 20 MOTOR_restart,
garphil 2:c91c5ef00d25 21 MOTOR_stop,
garphil 2:c91c5ef00d25 22 MOTOR_zero
garphil 2:c91c5ef00d25 23 } MotorCommand;
garphil 0:bd05fd602a6e 24
garphil 2:c91c5ef00d25 25 typedef enum MotorDirectionList { // Define Motor Clockwise or Anticlockwise
garphil 4:c009bcd5518c 26 CLOCKWISE = 0,
garphil 4:c009bcd5518c 27 COUNTERCLOCKWISE
garphil 0:bd05fd602a6e 28 } MotorDir;
garphil 0:bd05fd602a6e 29
garphil 0:bd05fd602a6e 30 class Motor {
garphil 0:bd05fd602a6e 31
garphil 2:c91c5ef00d25 32 MotorState state;
garphil 2:c91c5ef00d25 33 MotorCommand command;
garphil 2:c91c5ef00d25 34 MotorDir direction;
garphil 2:c91c5ef00d25 35
garphil 2:c91c5ef00d25 36
garphil 2:c91c5ef00d25 37 public:
garphil 4:c009bcd5518c 38
garphil 2:c91c5ef00d25 39
garphil 4:c009bcd5518c 40 Motor(PinName _MPh0, PinName _MPh1, PinName _MPh2, PinName _MPh3, uint32_t TickTime);
garphil 3:01b4c058454d 41 void RunSteps(MotorDir direction, uint32_t steps);
garphil 3:01b4c058454d 42 void RunDegrees(MotorDir direction, float steps);
garphil 6:aec892eb1b49 43 void RunInfinite(MotorDir direction);
garphil 4:c009bcd5518c 44 void SetDirection(MotorDir dir);
garphil 4:c009bcd5518c 45 void TestMotor();
garphil 4:c009bcd5518c 46 void RunMotor();
garphil 4:c009bcd5518c 47
garphil 4:c009bcd5518c 48 void Start();
garphil 4:c009bcd5518c 49 void Stop();
garphil 4:c009bcd5518c 50 void Pause();
garphil 4:c009bcd5518c 51 void Restart();
garphil 4:c009bcd5518c 52 void SetZero();
arnophilippe 7:439458133bba 53
arnophilippe 7:439458133bba 54 MotorStateList getState();
garphil 4:c009bcd5518c 55
garphil 4:c009bcd5518c 56 private:
garphil 1:9519ac966b79 57 void StopMotor();
garphil 2:c91c5ef00d25 58 void StartMotor();
garphil 2:c91c5ef00d25 59 void SetCommand(MotorCommand cmd);
garphil 1:9519ac966b79 60 void LeftMotor();
garphil 1:9519ac966b79 61 void RightMotor();
garphil 1:9519ac966b79 62 void ProcessMotorStateMachine();
garphil 4:c009bcd5518c 63
garphil 0:bd05fd602a6e 64 DigitalOut *MPh0, *MPh1, *MPh2, *MPh3;
garphil 0:bd05fd602a6e 65
garphil 0:bd05fd602a6e 66 int MotorIndex; // --- Motor Variable
garphil 1:9519ac966b79 67
garphil 3:01b4c058454d 68 bool init;
garphil 0:bd05fd602a6e 69 Ticker MotorSystemTick; // System Callback for Motor
garphil 0:bd05fd602a6e 70 timestamp_t MotorStepTime; // Time in µs for one motor step
garphil 0:bd05fd602a6e 71 uint32_t MotorFullTurn; // Number of step for a complete turn
garphil 2:c91c5ef00d25 72 // uint32_t NumWires; // Number of Wires
garphil 8:4dd59b6f4e92 73 int32_t NumSteps; // Number of Steps = NumWire * MotorFullTurn
garphil 0:bd05fd602a6e 74
garphil 5:9886fd337a4b 75 };
garphil 5:9886fd337a4b 76
garphil 5:9886fd337a4b 77 #endif