A PID class that stores constants and calculates the speed of a motor or motor group with respect to its current error and other internal factors.
More...
#include <PID.h>
|
| PID (float kp, float ki, float kd) |
| Construct a new PID object. When constructing a PID object, only the kp constant is required, ki and kd can be set to 0 if not used.
|
|
float | calculateSpeed (float error, float max_speed, std::string mech_id) |
| Used to calculate the velocity of a motor or motor group. The speed is calculated using PID, with integral clamping, and speed clamping.
|
|
void | setErrorRange (float degrees) |
| Set the error range in rotationUnits::deg.
|
|
int | getDelayTime () |
| Gets the delay time of this PID object in milliseconds.
|
|
void | setLowSpeedThreshold (int threshold) |
| Set the low speed threshold to determine when the system is slow. If the speed of the system is below this threshold, the loop will end if it is also within the error range. Otherwise the system will continue to correct for any error.
|
|
void | setTimeout (int timeout) |
| Set the timeout to use for PID movement. If the timeout is exceeded, the system will stop regardless of the current error or speed. A value of -1 will disable timeouts.
|
|
void | setMaxIntegral (int max_integral) |
| Set the maximum value the integral term will contribute to the speed calculations. If the integral term exceeds this value, it will be reduced to this value.
|
|
bool | unfinished (float error, int speed) |
| Checks if the movement is unfinished (error still outside the final bounds).
|
|
void | reset (void) |
| Resets the previous error and previous integral values.
|
|
PID | copy (void) |
| Duplicates the PID object by copying constants and returning a new PID object. Used as a helper for using the same constants on multiple mechanisms.
|
|
void | fileLogging (float error, float speed, float proportional, float integral, float derivative, std::string mech_id) |
| Logs the error, speed, integral and derivative values to a text file on a micro SD card on the robot.
|
|
A PID class that stores constants and calculates the speed of a motor or motor group with respect to its current error and other internal factors.
◆ PID()
wpid::PID::PID |
( |
float |
kp, |
|
|
float |
ki, |
|
|
float |
kd |
|
) |
| |
|
inline |
Construct a new PID object. When constructing a PID object, only the kp constant is required, ki and kd can be set to 0 if not used.
- Parameters
-
kp | proportional constant |
ki | integral constant |
kd | derivative constant |
◆ calculateSpeed()
float PID::calculateSpeed |
( |
float |
error, |
|
|
float |
max_speed, |
|
|
std::string |
mech_id |
|
) |
| |
Used to calculate the velocity of a motor or motor group. The speed is calculated using PID, with integral clamping, and speed clamping.
- Parameters
-
error | the remaining distance to the target |
max_speed | maximum velocity allowed in velocityUnits::pct |
mech_id | string identifier for motor group to log |
- Returns
- a calculated speed based on all PID parameters
◆ copy()
Duplicates the PID object by copying constants and returning a new PID object. Used as a helper for using the same constants on multiple mechanisms.
- Returns
- PID
◆ fileLogging()
void PID::fileLogging |
( |
float |
error, |
|
|
float |
speed, |
|
|
float |
proportional, |
|
|
float |
integral, |
|
|
float |
derivative, |
|
|
std::string |
mech_id |
|
) |
| |
Logs the error, speed, integral and derivative values to a text file on a micro SD card on the robot.
- Parameters
-
error | the robot error value |
speed | the calculated speed |
proportional | result of the proportional calculation |
integral | result of the integral calculation |
derivative | result of the derivative calculation |
mech_id | the mechanism name |
◆ getDelayTime()
int PID::getDelayTime |
( |
| ) |
|
Gets the delay time of this PID object in milliseconds.
- Returns
- int milliseconds
◆ setErrorRange()
void PID::setErrorRange |
( |
float |
degrees | ) |
|
Set the error range in rotationUnits::deg.
- Parameters
-
degrees | the absolute value of the bounds of the error range |
◆ setLowSpeedThreshold()
void PID::setLowSpeedThreshold |
( |
int |
threshold | ) |
|
Set the low speed threshold to determine when the system is slow. If the speed of the system is below this threshold, the loop will end if it is also within the error range. Otherwise the system will continue to correct for any error.
- Parameters
-
threshold | in velocityUnits::pct |
◆ setMaxIntegral()
void PID::setMaxIntegral |
( |
int |
max_integral | ) |
|
Set the maximum value the integral term will contribute to the speed calculations. If the integral term exceeds this value, it will be reduced to this value.
- Parameters
-
max_integral | in velocityUnits::pct |
◆ setTimeout()
void PID::setTimeout |
( |
int |
timeout | ) |
|
Set the timeout to use for PID movement. If the timeout is exceeded, the system will stop regardless of the current error or speed. A value of -1 will disable timeouts.
- Parameters
-
◆ unfinished()
bool PID::unfinished |
( |
float |
error, |
|
|
int |
speed |
|
) |
| |
Checks if the movement is unfinished (error still outside the final bounds).
- Parameters
-
error | the current error of the system |
- Returns
- returns true if the error is outside the bounds, false if it is within the bounds
The documentation for this class was generated from the following files:
- include/WPID/PID.h
- src/WPID/PID.cpp