WPILibC++ 2025.2.1
|
Implements a PID control loop. More...
#include <frc/controller/PIDController.h>
Public Member Functions | |
constexpr | 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. | |
constexpr | ~PIDController () override=default |
constexpr | PIDController (const PIDController &)=default |
constexpr PIDController & | operator= (const PIDController &)=default |
constexpr | PIDController (PIDController &&)=default |
constexpr PIDController & | operator= (PIDController &&)=default |
constexpr void | SetPID (double Kp, double Ki, double Kd) |
Sets the PID Controller gain parameters. | |
constexpr void | SetP (double Kp) |
Sets the proportional coefficient of the PID controller gain. | |
constexpr void | SetI (double Ki) |
Sets the integral coefficient of the PID controller gain. | |
constexpr void | SetD (double Kd) |
Sets the differential coefficient of the PID controller gain. | |
constexpr void | SetIZone (double iZone) |
Sets the IZone range. | |
constexpr double | GetP () const |
Gets the proportional coefficient. | |
constexpr double | GetI () const |
Gets the integral coefficient. | |
constexpr double | GetD () const |
Gets the differential coefficient. | |
constexpr double | GetIZone () const |
Get the IZone range. | |
constexpr units::second_t | GetPeriod () const |
Gets the period of this controller. | |
constexpr double | GetErrorTolerance () const |
Gets the error tolerance of this controller. | |
constexpr double | GetErrorDerivativeTolerance () const |
Gets the error derivative tolerance of this controller. | |
constexpr double | GetPositionTolerance () const |
Gets the position tolerance of this controller. | |
constexpr double | GetVelocityTolerance () const |
Gets the velocity tolerance of this controller. | |
constexpr double | GetAccumulatedError () const |
Gets the accumulated error used in the integral calculation of this controller. | |
constexpr void | SetSetpoint (double setpoint) |
Sets the setpoint for the PIDController. | |
constexpr double | GetSetpoint () const |
Returns the current setpoint of the PIDController. | |
constexpr bool | AtSetpoint () const |
Returns true if the error is within the tolerance of the setpoint. | |
constexpr void | EnableContinuousInput (double minimumInput, double maximumInput) |
Enables continuous input. | |
constexpr void | DisableContinuousInput () |
Disables continuous input. | |
constexpr bool | IsContinuousInputEnabled () const |
Returns true if continuous input is enabled. | |
constexpr void | SetIntegratorRange (double minimumIntegral, double maximumIntegral) |
Sets the minimum and maximum contributions of the integral term. | |
constexpr void | SetTolerance (double errorTolerance, double errorDerivativeTolerance=std::numeric_limits< double >::infinity()) |
Sets the error which is considered tolerable for use with AtSetpoint(). | |
constexpr double | GetError () const |
Returns the difference between the setpoint and the measurement. | |
constexpr double | GetErrorDerivative () const |
Returns the error derivative. | |
constexpr double | GetPositionError () const |
Returns the difference between the setpoint and the measurement. | |
constexpr double | GetVelocityError () const |
Returns the velocity error. | |
constexpr double | Calculate (double measurement) |
Returns the next output of the PID controller. | |
constexpr double | Calculate (double measurement, double setpoint) |
Returns the next output of the PID controller. | |
constexpr void | Reset () |
Reset the previous error, the integral term, and disable the controller. | |
void | InitSendable (wpi::SendableBuilder &builder) override |
Initializes this Sendable object. | |
Public Member Functions inherited from wpi::Sendable | |
virtual constexpr | ~Sendable ()=default |
Public Member Functions inherited from wpi::SendableHelper< PIDController > | |
constexpr | SendableHelper (const SendableHelper &rhs)=default |
constexpr | SendableHelper (SendableHelper &&rhs) |
constexpr SendableHelper & | operator= (const SendableHelper &rhs)=default |
constexpr SendableHelper & | operator= (SendableHelper &&rhs) |
Additional Inherited Members | |
Protected Member Functions inherited from wpi::SendableHelper< PIDController > | |
constexpr | SendableHelper ()=default |
constexpr | ~SendableHelper () |
Implements a PID control loop.
|
inlineconstexpr |
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. |
|
constexproverridedefault |
|
constexprdefault |
|
constexprdefault |
|
inlineconstexpr |
Returns true if the error is within the tolerance of the setpoint.
The error tolerance defauls to 0.05, and the error derivative tolerance defaults to ∞.
This will return false until at least one input value has been computed.
|
inlineconstexpr |
Returns the next output of the PID controller.
measurement | The current measurement of the process variable. |
|
inlineconstexpr |
Returns the next output of the PID controller.
measurement | The current measurement of the process variable. |
setpoint | The new setpoint of the controller. |
|
inlineconstexpr |
Disables continuous input.
|
inlineconstexpr |
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. |
|
inlineconstexpr |
Gets the accumulated error used in the integral calculation of this controller.
|
inlineconstexpr |
Gets the differential coefficient.
|
inlineconstexpr |
Returns the difference between the setpoint and the measurement.
|
inlineconstexpr |
Returns the error derivative.
|
inlineconstexpr |
Gets the error derivative tolerance of this controller.
Defaults to ∞.
|
inlineconstexpr |
Gets the error tolerance of this controller.
Defaults to 0.05.
|
inlineconstexpr |
Gets the integral coefficient.
|
inlineconstexpr |
Get the IZone range.
|
inlineconstexpr |
Gets the proportional coefficient.
|
inlineconstexpr |
Gets the period of this controller.
|
inlineconstexpr |
Returns the difference between the setpoint and the measurement.
|
inlineconstexpr |
Gets the position tolerance of this controller.
|
inlineconstexpr |
Returns the current setpoint of the PIDController.
|
inlineconstexpr |
Returns the velocity error.
|
inlineconstexpr |
Gets the velocity tolerance of this controller.
|
overridevirtual |
|
inlineconstexpr |
Returns true if continuous input is enabled.
|
constexprdefault |
|
constexprdefault |
|
inlineconstexpr |
Reset the previous error, the integral term, and disable the controller.
|
inlineconstexpr |
Sets the differential coefficient of the PID controller gain.
Kd | The differential coefficient. Must be >= 0. |
|
inlineconstexpr |
Sets the integral coefficient of the PID controller gain.
Ki | The integral coefficient. Must be >= 0. |
|
inlineconstexpr |
Sets the minimum and maximum contributions of the integral term.
The internal integrator is clamped so that the integral term's contribution to the output stays between minimumIntegral and maximumIntegral. This prevents integral windup.
minimumIntegral | The minimum contribution of the integral term. |
maximumIntegral | The maximum contribution of the integral term. |
|
inlineconstexpr |
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. |
|
inlineconstexpr |
Sets the proportional coefficient of the PID controller gain.
Kp | The proportional coefficient. Must be >= 0. |
|
inlineconstexpr |
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. |
|
inlineconstexpr |
Sets the setpoint for the PIDController.
setpoint | The desired setpoint. |
|
inlineconstexpr |
Sets the error which is considered tolerable for use with AtSetpoint().
errorTolerance | error which is tolerable. |
errorDerivativeTolerance | error derivative which is tolerable. |