Combination of PWM and Encoder to work with motors.
More...
#include <Motor.h>
|
double | speed |
| The duty cycle of the motor. More...
|
|
double | angularCoef |
| Angular coefficient of the motors The relation between the angular speed and the duty cycle. More...
|
|
bool | defaultDirection |
| Default direction of the motors In our case : ClockWise for the left motor and Conter ClockWise for the right motor. More...
|
|
bool | direction |
| Direction of the motors. More...
|
|
PWM * | channel |
| The pin where the PWM will be generated. More...
|
|
Encoder * | enc |
| Attached encodeur In our case : Encoder A attached to the PWMA_0 (PWM0) and Encoder B attached to the PWMA_1 (PWM1). More...
|
|
uint8_t | pin |
| The pin where the PWM will be generated. More...
|
|
Combination of PWM and Encoder to work with motors.
- Examples
- example_motor_pid_encoder.cpp, project_car.cpp, and project_pendulum.cpp.
Definition at line 22 of file Motor.h.
◆ Motor()
Motor::Motor |
( |
uint32_t |
port, |
|
|
bool |
defaultDirection, |
|
|
double |
angularCoef |
|
) |
| |
Motors configuration.
- Parameters
-
port | the PWM port (PWM[A:C]_[0:2]) |
defaultDirection | the default direction of the motor |
angularCoef | the angular coefficient of the motor In our case : code to configurate only two motors. The code can be easly changed to control more motors |
Definition at line 12 of file Motor.cpp.
◆ ~Motor()
Destructor Stop the motor by seting the speed to 0.
Stop the thread of the encoders.
Definition at line 103 of file Motor.cpp.
◆ getDefaultDirection()
bool Motor::getDefaultDirection |
( |
| ) |
|
◆ getEncoderPulses()
long Motor::getEncoderPulses |
( |
| ) |
|
Get the Encoder values.
- Returns
- return the value of the encoder
Definition at line 29 of file Motor.cpp.
◆ getSpeed()
double Motor::getSpeed |
( |
| ) |
|
Get the speed of the motor.
- Returns
- the speed of the motor
Definition at line 74 of file Motor.cpp.
◆ setAngularSpeed()
void Motor::setAngularSpeed |
( |
double |
speed | ) |
|
Set the speed in angular speed.
- Parameters
-
speed | the speed (angular speed) of the motor In this function the changment of the speed is done from a value °/s [0:850]. |
- Examples
- example_motor_pid_encoder.cpp.
Definition at line 48 of file Motor.cpp.
◆ setAngularSpeedAndDirection()
void Motor::setAngularSpeedAndDirection |
( |
double |
speed | ) |
|
Set the speed in angular speed and the direction.
- Parameters
-
speed | the speed (angular speed) and the direction of the motor In this function the changment of the speed is done from a value °/s [0:850]. The direction is done with the the funtion setDirection |
- Examples
- example_motor_pid_encoder.cpp.
Definition at line 60 of file Motor.cpp.
◆ setDirection()
void Motor::setDirection |
( |
bool |
dir | ) |
|
Set the direction of the motor.
- Parameters
-
dir | the direction; CW -> 1 , CCW -> 0 |
Definition at line 87 of file Motor.cpp.
◆ setInterrupt()
void Motor::setInterrupt |
( |
std::function< void(long, bool)> |
func, |
|
|
unsigned int |
threshold |
|
) |
| |
◆ setSpeed()
void Motor::setSpeed |
( |
double |
speed | ) |
|
Set the speed in duty cycle.
- Parameters
-
speed | the speed (duty cycle) of the motor In this function the changment of the speed is done from a value in percentage [0:100]. |
Definition at line 39 of file Motor.cpp.
◆ angularCoef
double myRIO::Motor::angularCoef |
|
private |
Angular coefficient of the motors The relation between the angular speed and the duty cycle.
For exemple for our motor for the 100% duty cycle we had an angular speed of 884,6 °/s. Which means that our coeffient is angular speed * 100% = 8,846.
Definition at line 36 of file Motor.h.
◆ channel
PWM* myRIO::Motor::channel |
|
private |
The pin where the PWM will be generated.
Definition at line 45 of file Motor.h.
◆ defaultDirection
bool myRIO::Motor::defaultDirection |
|
private |
Default direction of the motors In our case : ClockWise for the left motor and Conter ClockWise for the right motor.
Definition at line 41 of file Motor.h.
◆ direction
bool myRIO::Motor::direction |
|
private |
Direction of the motors.
Definition at line 44 of file Motor.h.
◆ enc
Attached encodeur In our case : Encoder A attached to the PWMA_0 (PWM0) and Encoder B attached to the PWMA_1 (PWM1).
Definition at line 46 of file Motor.h.
◆ pin
uint8_t myRIO::Motor::pin |
|
private |
The pin where the PWM will be generated.
Definition at line 49 of file Motor.h.
◆ speed
double myRIO::Motor::speed |
|
private |
The duty cycle of the motor.
Definition at line 35 of file Motor.h.
The documentation for this class was generated from the following files:
- C:/Users/jackb/OneDrive - etu.univ-lyon1.fr/TERi/Eclipse/workspace/APIForRIO/src/Motor.h
- C:/Users/jackb/OneDrive - etu.univ-lyon1.fr/TERi/Eclipse/workspace/APIForRIO/src/Motor.cpp