Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MotorLib by
motor.h
- Committer:
- garphil
- Date:
- 2017-07-17
- Revision:
- 8:4dd59b6f4e92
- Parent:
- 7:439458133bba
- Child:
- 9:5983c10d5f8e
File content as of revision 8:4dd59b6f4e92:
// -------------------- Motor ---------------------------
#ifdef MOTOR_H
#else
#define MOTOR_H
#include "mbed.h"
typedef enum MotorStateList { // Define Motor States for the State Machine
Motor_IDLE = 0,
Motor_RUN,
Motor_PAUSE,
Motor_ZERO,
Motor_CALIB
} MotorState;
typedef enum MotorCommandList { // Define Motor State Machine Commands
MOTOR_nop = 0,
MOTOR_start,
MOTOR_pause,
MOTOR_restart,
MOTOR_stop,
MOTOR_zero
} MotorCommand;
typedef enum MotorDirectionList { // Define Motor Clockwise or Anticlockwise
CLOCKWISE = 0,
COUNTERCLOCKWISE
} MotorDir;
class Motor {
MotorState state;
MotorCommand command;
MotorDir direction;
public:
Motor(PinName _MPh0, PinName _MPh1, PinName _MPh2, PinName _MPh3, uint32_t TickTime);
void RunSteps(MotorDir direction, uint32_t steps);
void RunDegrees(MotorDir direction, float steps);
void RunInfinite(MotorDir direction);
void SetDirection(MotorDir dir);
void TestMotor();
void RunMotor();
void Start();
void Stop();
void Pause();
void Restart();
void SetZero();
MotorStateList getState();
private:
void StopMotor();
void StartMotor();
void SetCommand(MotorCommand cmd);
void LeftMotor();
void RightMotor();
void ProcessMotorStateMachine();
DigitalOut *MPh0, *MPh1, *MPh2, *MPh3;
int MotorIndex; // --- Motor Variable
bool init;
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
int32_t NumSteps; // Number of Steps = NumWire * MotorFullTurn
};
#endif
