myWRIO
C++ framework for NationalInstruments myRIO
|
This class can be used to regulate a motor speed. More...
#include <MotorPID.h>
Public Member Functions | |
MotorPID (double kp, double ki) | |
Set the PI coefficients of the motors. More... | |
double | compute (long enc) |
Refresh the PID output. More... | |
void | setSetpoint (double setpoint) |
Set the setpoint. More... | |
double | getSetpoint () |
Get the setpoint. More... | |
double | getAvgSpeed () |
Calculate the average of the last NB_AVG speeds. More... | |
~MotorPID () | |
Destructor (Does nothing) More... | |
Private Attributes | |
Time | stopwatch |
Timer to get the elapsed tiem since the last refresh. More... | |
const double | toAngularSpeed = 360./(12.*52.734) |
The encoder gives 12 clock edges for a complete turn (360°). More... | |
double | lastSpeeds [NB_AVG] |
Moving average filter. More... | |
long | lastEnc |
The value of the encoder, last time mesured. More... | |
double | setpoint |
The setpoint of the motors. More... | |
double | errSum |
The sum of the errors Errors from integration. More... | |
double | kp |
Proportional coefficient. More... | |
double | ki |
integral coefficient More... | |
This class can be used to regulate a motor speed.
Definition at line 14 of file MotorPID.h.
MotorPID::MotorPID | ( | double | kp, |
double | ki | ||
) |
Set the PI coefficients of the motors.
kp | proportional coefficient |
ki | integral coefficicent This functions sets the coefficients of the PI motor corrector. And initialises a vector with 0's. |
Definition at line 11 of file MotorPID.cpp.
MotorPID::~MotorPID | ( | ) |
Destructor (Does nothing)
Definition at line 83 of file MotorPID.cpp.
double MotorPID::compute | ( | long | enc | ) |
Refresh the PID output.
enc | The current encoder value |
Definition at line 38 of file MotorPID.cpp.
double MotorPID::getAvgSpeed | ( | ) |
Calculate the average of the last NB_AVG speeds.
Definition at line 73 of file MotorPID.cpp.
double MotorPID::getSetpoint | ( | ) |
void MotorPID::setSetpoint | ( | double | setpoint | ) |
Set the setpoint.
setpoint | the setpoint that we want to give to the motor |
Definition at line 22 of file MotorPID.cpp.
|
private |
The sum of the errors Errors from integration.
Definition at line 35 of file MotorPID.h.
|
private |
integral coefficient
Definition at line 40 of file MotorPID.h.
|
private |
Proportional coefficient.
Definition at line 39 of file MotorPID.h.
|
private |
The value of the encoder, last time mesured.
Definition at line 33 of file MotorPID.h.
|
private |
Moving average filter.
Definition at line 31 of file MotorPID.h.
|
private |
The setpoint of the motors.
Definition at line 34 of file MotorPID.h.
|
private |
Timer to get the elapsed tiem since the last refresh.
Definition at line 26 of file MotorPID.h.
|
private |
The encoder gives 12 clock edges for a complete turn (360°).
The gear ratio is 1/52.734 ; hence, an edge is 0.568893°
Definition at line 28 of file MotorPID.h.