|
RIT VEXU Core API
|
#include <pid.h>
Public Types | |
| enum | ERROR_TYPE |
Public Member Functions | |
| PID (double kp, double ki, double kd, double deadband, double on_target_time, ERROR_TYPE error_method=PID::LINEAR) | |
| Create the PID object. | |
| void | init (double start_pt, double set_pt) override |
| double | update (double sensor_val) override |
| double | update (double sensor_val, double v_setpt) |
| double | get_sensor_val () const |
| gets the sensor value that we were last updated with | |
| double | get () override |
| Gets the current PID out value, from when update() was last run. | |
| void | set_limits (double lower, double upper) override |
| bool | is_on_target () override |
| void | reset () |
| Reset the PID loop by resetting time since 0 and accumulated error. | |
| double | get_error () |
| Get the delta between the current sensor data and the target. | |
| double | get_output () |
| Get the delta between the current sensor data and the target. | |
| double | get_target () const |
| void | set_target (double target) |
| Set the target for the PID loop, where the robot is trying to end up. | |
Public Attributes | |
| double | kp |
| Proportional coeffecient; p * error(). | |
| double | ki |
| Integral coefficient; i * integral(error). | |
| double | kd |
| Derivative coefficient; d * derivative(error). | |
| double | deadband |
| A deadband that determines the threshold for what counts as finished. | |
| double | on_target_time |
| The time, in seconds, that we have to be in the threshold in order to be considered on target. | |
| ERROR_TYPE | error_method |
| Determines whether error is performed as a simple subtraction (LINEAR) or wrapping (ANGULAR). | |
PID Class
Defines a standard feedback loop using the constants kP, kI, kD, deadband, and on_target_time. The formula is:
out = kP*error + kI*integral(d Error) + kD*(dError/dt)
The PID object will determine it is "on target" when the error is within the deadband, for a duration of on_target_time
| enum PID::ERROR_TYPE |
An enum to distinguish between a linear and angular caluclation of PID error.
| PID::PID | ( | double | kp, |
| double | ki, | ||
| double | kd, | ||
| double | deadband, | ||
| double | on_target_time, | ||
| PID::ERROR_TYPE | error_method = PID::LINEAR ) |
Create the PID object.
Create the PID object
| kp | Coefficient double p. Direct error to voltage. |
| ki | Coefficient double i. Integral of error to voltage. Helps get the motor "unstuck" if P is not enough to drive the motor. |
| kd | Coefficient double d. Derivative of error to voltage. Helps prevent overshooting. |
| deadband | Double. Acceptable margin of error. |
| on_target_time | Double. How long the reading must be within the deadband to consider robot "aligned." |
| error_method | ERROR_TYPE struct. Can be either LINEAR or ANGULAR. Determines how we want the PID to enact, on position or rotation for example. |
|
overridevirtual |
| double PID::get_error | ( | ) |
Get the delta between the current sensor data and the target.
Get the delta between the current sensor data and the target
| double PID::get_output | ( | ) |
Get the delta between the current sensor data and the target.
Get the output calculated from the P, I, D and Error values
| double PID::get_sensor_val | ( | ) | const |
gets the sensor value that we were last updated with
| double PID::get_target | ( | ) | const |
|
overridevirtual |
Inherited from Feedback for interoperability. Update the setpoint and reset integral accumulation
start_pt can be safely ignored in this feedback controller
| start_pt | commpletely ignored for PID. necessary to satisfy Feedback base |
| set_pt | sets the target of the PID controller |
| start_vel | completely ignored for PID. necessary to satisfy Feedback base |
| end_vel | sets the target end velocity of the PID controller |
Implements Feedback.
|
overridevirtual |
|
overridevirtual |
Set the limits on the PID out. The PID out will "clip" itself to be between the limits.
| lower | the lower limit. the PID controller will never command the output go below lower |
| upper | the upper limit. the PID controller will never command the output go higher than upper |
Set the limits on the PID out. The PID out will "clip" itself to be between the limits.
Implements Feedback.
| void PID::set_target | ( | double | target | ) |
|
overridevirtual |
Update the PID loop by taking the time difference from last update, and running the PID formula with the new sensor data
| sensor_val | the distance, angle, encoder position or whatever it is we are measuring |
Implements Feedback.
| double PID::update | ( | double | sensor_val, |
| double | v_setpt ) |
Update the PID loop by taking the time difference from last update, and running the PID formula with the new sensor data
| sensor_val | the distance, angle, encoder position or whatever it is we are measuring |
| v_setpt | Expected velocity setpoint, to subtract from the D term (for velocity control) |