EEEN21000
GROUP 30 Line Following Buggy
Loading...
Searching...
No Matches
motor.h
Go to the documentation of this file.
1#ifndef MOTOR_H
2#define MOTOR_H
3
4#include "encoder.h"
5#include "helper.h"
6#include "mbed.h"
7#include <utility>
8
10#define FAST_PWM 0.6
12#define HALF_PWM 0.5
14#define SLOW_PWM 0.3
15
22class Motor {
23 private:
25 DigitalOut m_direction_left;
26
29
31 DigitalOut m_enable;
32
37 float m_period;
38
39 public:
41 PwmOut left_motor;
42
45
57 Motor(PinName left, PinName right, PinName direction_left, PinName direction_right, PinName enable);
58
66 void setEnable(int enable);
67
73 void setEnable();
74
82 int getEnable();
83
89 void setFrequency(float frequency);
90
96 float getFrequency() const;
97
109 void setDirection(char c, int direction);
110
120 void setDirection(char c);
121
127 std::pair<int, int> getDirection() const;
128
140 void setDutycycle(char c, float dutycycle);
141
147 std::pair<float, float> getDutycycle();
148
166
174 static void forward(const double distance, Motor *const motor,
175 Encoder *const left_encoder, Encoder *const right_encoder);
176
185 static void reverse(const double distance, Motor *const motor,
186 Encoder *const left_encoder, Encoder *const right_encoder);
187
196 static void turnleft(const double angle, Motor *const motor,
197 Encoder *const left_encoder, Encoder *const right_encoder);
198
207 static void turnright(const double angle, Motor *const motor,
208 Encoder *const left_encoder, Encoder *const right_encoder);
209
211};
212
213#endif
Encoder class with helper functions, derived from QEI.
Definition: encoder.h:28
Motor class to control the motors.
Definition: motor.h:22
float getFrequency() const
Get the frequency of the PwmOut.
DigitalOut m_direction_left
Direction for the left motor.
Definition: motor.h:25
static void turnleft(const double angle, Motor *const motor, Encoder *const left_encoder, Encoder *const right_encoder)
Control the motor to turn left.
PwmOut right_motor
Right motor PwmOut.
Definition: motor.h:44
static void reverse(const double distance, Motor *const motor, Encoder *const left_encoder, Encoder *const right_encoder)
Control the motor to cruise backwards.
void setDutycycle(char c, float dutycycle)
Set the duty cycle of the motors.
void setEnable()
Toggle the enable pin of the motor driver board, if no argument is given.
PwmOut left_motor
Left motor PwmOut.
Definition: motor.h:41
void setEnable(int enable)
Set the enable pin of the motor driver board, given the enable.
void setFrequency(float frequency)
Set the frequency of the PwmOut.
DigitalOut m_direction_right
Direction for the right motor.
Definition: motor.h:28
Motor(PinName left, PinName right, PinName direction_left, PinName direction_right, PinName enable)
Constructor.
int getEnable()
Get the enable status of the motor driver board.
void setDirection(char c)
Toggle the direction of the motors, if no direction given.
void setDirection(char c, int direction)
Set the direction of the motors, provided the direction.
static void forward(const double distance, Motor *const motor, Encoder *const left_encoder, Encoder *const right_encoder)
Control the motor to cruise forward.
static void turnright(const double angle, Motor *const motor, Encoder *const left_encoder, Encoder *const right_encoder)
Control the motor to turn right.
DigitalOut m_enable
Enable pin to motor driver board.
Definition: motor.h:31
std::pair< float, float > getDutycycle()
Get the duty cycle of the motors.
float m_period
Period of PWM output.
Definition: motor.h:37
std::pair< int, int > getDirection() const
Get the direction of the motors.