EEEN21000
GROUP 30 Line Following Buggy
|
Motor class to control the motors. More...
#include <motor.h>
Public Member Functions | |
Motor (PinName left, PinName right, PinName direction_left, PinName direction_right, PinName enable) | |
Constructor. More... | |
void | setEnable (int enable) |
Set the enable pin of the motor driver board, given the enable. More... | |
void | setEnable () |
Toggle the enable pin of the motor driver board, if no argument is given. More... | |
int | getEnable () |
Get the enable status of the motor driver board. More... | |
void | setFrequency (float frequency) |
Set the frequency of the PwmOut. More... | |
float | getFrequency () const |
Get the frequency of the PwmOut. More... | |
void | setDirection (char c, int direction) |
Set the direction of the motors, provided the direction. More... | |
void | setDirection (char c) |
Toggle the direction of the motors, if no direction given. More... | |
std::pair< int, int > | getDirection () const |
Get the direction of the motors. More... | |
void | setDutycycle (char c, float dutycycle) |
Set the duty cycle of the motors. More... | |
std::pair< float, float > | getDutycycle () |
Get the duty cycle of the motors. More... | |
Static Public Member Functions | |
Cruising Methods | |
All cruising methods to control the motors include forward, reverse, turnleft and turnright. All methods apply the following sequence:
| |
static void | forward (const double distance, Motor *const motor, Encoder *const left_encoder, Encoder *const right_encoder) |
Control the motor to cruise forward. More... | |
static void | reverse (const double distance, Motor *const motor, Encoder *const left_encoder, Encoder *const right_encoder) |
Control the motor to cruise backwards. More... | |
static void | turnleft (const double angle, Motor *const motor, Encoder *const left_encoder, Encoder *const right_encoder) |
Control the motor to turn left. More... | |
static void | turnright (const double angle, Motor *const motor, Encoder *const left_encoder, Encoder *const right_encoder) |
Control the motor to turn right. More... | |
Public Attributes | |
PwmOut | left_motor |
Left motor PwmOut. More... | |
PwmOut | right_motor |
Right motor PwmOut. More... | |
Private Attributes | |
DigitalOut | m_direction_left |
Direction for the left motor. More... | |
DigitalOut | m_direction_right |
Direction for the right motor. More... | |
DigitalOut | m_enable |
Enable pin to motor driver board. More... | |
float | m_period |
Period of PWM output. More... | |
Motor class to control the motors.
This class includes configuration method of left and right motors. It also features cruising methods to move forward, backwards, turn left and turn left.
Motor::Motor | ( | PinName | left, |
PinName | right, | ||
PinName | direction_left, | ||
PinName | direction_right, | ||
PinName | enable | ||
) |
Constructor.
Construct a motor object. Using unipolar mode (0), pins are sunk to ground instead of using DigitalOut.write(0).
left | Left motor pin. |
right | Right motor pin. |
direction_left | Direction left motor. |
direction_right | Direction right motor. |
enable | Enable pin. |
void Motor::setEnable | ( | int | enable | ) |
Set the enable pin of the motor driver board, given the enable.
enable |
|
void Motor::setEnable | ( | ) |
Toggle the enable pin of the motor driver board, if no argument is given.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
int Motor::getEnable | ( | ) |
Get the enable status of the motor driver board.
void Motor::setFrequency | ( | float | frequency | ) |
Set the frequency of the PwmOut.
frequency | Frequency of the PWM. |
float Motor::getFrequency | ( | ) | const |
Get the frequency of the PwmOut.
void Motor::setDirection | ( | char | c, |
int | direction | ||
) |
Set the direction of the motors, provided the direction.
c | Which motor direction to change.
|
direction |
|
void Motor::setDirection | ( | char | c | ) |
Toggle the direction of the motors, if no direction given.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
c | Which motor direction to change.
|
std::pair< int, int > Motor::getDirection | ( | ) | const |
Get the direction of the motors.
void Motor::setDutycycle | ( | char | c, |
float | dutycycle | ||
) |
Set the duty cycle of the motors.
c | Which motor to set duty cycle.
|
dutycycle | Duty cycle in percentange within [0.0,1.0]. If duty cycle is out of range, it saturates at 0 and 1. |
std::pair< float, float > Motor::getDutycycle | ( | ) |
Get the duty cycle of the motors.
|
private |
Direction for the left motor.
|
private |
Direction for the right motor.
|
private |
Enable pin to motor driver board.
|
private |
Period of PWM output.
\({m\_period} = \frac{1}{frequency}\\\)
PwmOut Motor::left_motor |
Left motor PwmOut.
PwmOut Motor::right_motor |
Right motor PwmOut.