WPILibC++ 2024.3.2
|
Implements a PID control loop. More...
#include <frc/controller/PIDController.h>
Public Member Functions | |
PIDController (double Kp, double Ki, double Kd, units::second_t period=20_ms) | |
Allocates a PIDController with the given constants for Kp, Ki, and Kd. More... | |
~PIDController () override=default | |
PIDController (const PIDController &)=default | |
PIDController & | operator= (const PIDController &)=default |
PIDController (PIDController &&)=default | |
PIDController & | operator= (PIDController &&)=default |
void | SetPID (double Kp, double Ki, double Kd) |
Sets the PID Controller gain parameters. More... | |
void | SetP (double Kp) |
Sets the proportional coefficient of the PID controller gain. More... | |
void | SetI (double Ki) |
Sets the integral coefficient of the PID controller gain. More... | |
void | SetD (double Kd) |
Sets the differential coefficient of the PID controller gain. More... | |
void | SetIZone (double iZone) |
Sets the IZone range. More... | |
double | GetP () const |
Gets the proportional coefficient. More... | |
double | GetI () const |
Gets the integral coefficient. More... | |
double | GetD () const |
Gets the differential coefficient. More... | |
double | GetIZone () const |
Get the IZone range. More... | |
units::second_t | GetPeriod () const |
Gets the period of this controller. More... | |
double | GetPositionTolerance () const |
Gets the position tolerance of this controller. More... | |
double | GetVelocityTolerance () const |
Gets the velocity tolerance of this controller. More... | |
void | SetSetpoint (double setpoint) |
Sets the setpoint for the PIDController. More... | |
double | GetSetpoint () const |
Returns the current setpoint of the PIDController. More... | |
bool | AtSetpoint () const |
Returns true if the error is within the tolerance of the setpoint. More... | |
void | EnableContinuousInput (double minimumInput, double maximumInput) |
Enables continuous input. More... | |
void | DisableContinuousInput () |
Disables continuous input. More... | |
bool | IsContinuousInputEnabled () const |
Returns true if continuous input is enabled. More... | |
void | SetIntegratorRange (double minimumIntegral, double maximumIntegral) |
Sets the minimum and maximum values for the integrator. More... | |
void | SetTolerance (double positionTolerance, double velocityTolerance=std::numeric_limits< double >::infinity()) |
Sets the error which is considered tolerable for use with AtSetpoint(). More... | |
double | GetPositionError () const |
Returns the difference between the setpoint and the measurement. More... | |
double | GetVelocityError () const |
Returns the velocity error. More... | |
double | Calculate (double measurement) |
Returns the next output of the PID controller. More... | |
double | Calculate (double measurement, double setpoint) |
Returns the next output of the PID controller. More... | |
void | Reset () |
Reset the previous error, the integral term, and disable the controller. More... | |
void | InitSendable (wpi::SendableBuilder &builder) override |
Initializes this Sendable object. More... | |
Public Member Functions inherited from wpi::Sendable | |
virtual | ~Sendable ()=default |
virtual void | InitSendable (SendableBuilder &builder)=0 |
Initializes this Sendable object. More... | |
Public Member Functions inherited from wpi::SendableHelper< PIDController > | |
SendableHelper (const SendableHelper &rhs)=default | |
SendableHelper (SendableHelper &&rhs) | |
SendableHelper & | operator= (const SendableHelper &rhs)=default |
SendableHelper & | operator= (SendableHelper &&rhs) |
Additional Inherited Members | |
Protected Member Functions inherited from wpi::SendableHelper< PIDController > | |
SendableHelper ()=default | |
~SendableHelper () | |
Implements a PID control loop.
frc::PIDController::PIDController | ( | double | Kp, |
double | Ki, | ||
double | Kd, | ||
units::second_t | period = 20_ms |
||
) |
Allocates a PIDController with the given constants for Kp, Ki, and Kd.
Kp | The proportional coefficient. Must be >= 0. |
Ki | The integral coefficient. Must be >= 0. |
Kd | The derivative coefficient. Must be >= 0. |
period | The period between controller updates in seconds. The default is 20 milliseconds. Must be positive. |
|
overridedefault |
|
default |
|
default |
bool frc::PIDController::AtSetpoint | ( | ) | const |
Returns true if the error is within the tolerance of the setpoint.
This will return false until at least one input value has been computed.
double frc::PIDController::Calculate | ( | double | measurement | ) |
Returns the next output of the PID controller.
measurement | The current measurement of the process variable. |
double frc::PIDController::Calculate | ( | double | measurement, |
double | setpoint | ||
) |
Returns the next output of the PID controller.
measurement | The current measurement of the process variable. |
setpoint | The new setpoint of the controller. |
void frc::PIDController::DisableContinuousInput | ( | ) |
Disables continuous input.
void frc::PIDController::EnableContinuousInput | ( | double | minimumInput, |
double | maximumInput | ||
) |
Enables continuous input.
Rather then using the max and min input range as constraints, it considers them to be the same point and automatically calculates the shortest route to the setpoint.
minimumInput | The minimum value expected from the input. |
maximumInput | The maximum value expected from the input. |
double frc::PIDController::GetD | ( | ) | const |
Gets the differential coefficient.
double frc::PIDController::GetI | ( | ) | const |
Gets the integral coefficient.
double frc::PIDController::GetIZone | ( | ) | const |
Get the IZone range.
double frc::PIDController::GetP | ( | ) | const |
Gets the proportional coefficient.
units::second_t frc::PIDController::GetPeriod | ( | ) | const |
Gets the period of this controller.
double frc::PIDController::GetPositionError | ( | ) | const |
Returns the difference between the setpoint and the measurement.
double frc::PIDController::GetPositionTolerance | ( | ) | const |
Gets the position tolerance of this controller.
double frc::PIDController::GetSetpoint | ( | ) | const |
Returns the current setpoint of the PIDController.
double frc::PIDController::GetVelocityError | ( | ) | const |
Returns the velocity error.
double frc::PIDController::GetVelocityTolerance | ( | ) | const |
Gets the velocity tolerance of this controller.
|
overridevirtual |
bool frc::PIDController::IsContinuousInputEnabled | ( | ) | const |
Returns true if continuous input is enabled.
|
default |
|
default |
void frc::PIDController::Reset | ( | ) |
Reset the previous error, the integral term, and disable the controller.
void frc::PIDController::SetD | ( | double | Kd | ) |
Sets the differential coefficient of the PID controller gain.
Kd | The differential coefficient. Must be >= 0. |
void frc::PIDController::SetI | ( | double | Ki | ) |
Sets the integral coefficient of the PID controller gain.
Ki | The integral coefficient. Must be >= 0. |
void frc::PIDController::SetIntegratorRange | ( | double | minimumIntegral, |
double | maximumIntegral | ||
) |
Sets the minimum and maximum values for the integrator.
When the cap is reached, the integrator value is added to the controller output rather than the integrator value times the integral gain.
minimumIntegral | The minimum value of the integrator. |
maximumIntegral | The maximum value of the integrator. |
void frc::PIDController::SetIZone | ( | double | iZone | ) |
Sets the IZone range.
When the absolute value of the position error is greater than IZone, the total accumulated error will reset to zero, disabling integral gain until the absolute value of the position error is less than IZone. This is used to prevent integral windup. Must be non-negative. Passing a value of zero will effectively disable integral gain. Passing a value of infinity disables IZone functionality.
iZone | Maximum magnitude of error to allow integral control. Must be >= 0. |
void frc::PIDController::SetP | ( | double | Kp | ) |
Sets the proportional coefficient of the PID controller gain.
Kp | The proportional coefficient. Must be >= 0. |
void frc::PIDController::SetPID | ( | double | Kp, |
double | Ki, | ||
double | Kd | ||
) |
Sets the PID Controller gain parameters.
Sets the proportional, integral, and differential coefficients.
Kp | The proportional coefficient. Must be >= 0. |
Ki | The integral coefficient. Must be >= 0. |
Kd | The differential coefficient. Must be >= 0. |
void frc::PIDController::SetSetpoint | ( | double | setpoint | ) |
Sets the setpoint for the PIDController.
setpoint | The desired setpoint. |
void frc::PIDController::SetTolerance | ( | double | positionTolerance, |
double | velocityTolerance = std::numeric_limits< double >::infinity() |
||
) |
Sets the error which is considered tolerable for use with AtSetpoint().
positionTolerance | Position error which is tolerable. |
velocityTolerance | Velocity error which is tolerable. |