WPILibC++ 2025.2.1
|
Implements a PID control loop whose setpoint is constrained by a trapezoid profile. More...
#include <frc/controller/ProfiledPIDController.h>
Public Types | |
using | Distance_t = units::unit_t<Distance> |
using | Velocity |
using | Velocity_t = units::unit_t<Velocity> |
using | Acceleration |
using | Acceleration_t = units::unit_t<Acceleration> |
using | State = typename TrapezoidProfile<Distance>::State |
using | Constraints = typename TrapezoidProfile<Distance>::Constraints |
Public Member Functions | |
constexpr | ProfiledPIDController (double Kp, double Ki, double Kd, Constraints constraints, units::second_t period=20_ms) |
Allocates a ProfiledPIDController with the given constants for Kp, Ki, and Kd. | |
constexpr | ~ProfiledPIDController () override=default |
constexpr | ProfiledPIDController (const ProfiledPIDController &)=default |
constexpr ProfiledPIDController & | operator= (const ProfiledPIDController &)=default |
constexpr | ProfiledPIDController (ProfiledPIDController &&)=default |
constexpr ProfiledPIDController & | operator= (ProfiledPIDController &&)=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 | 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 | SetGoal (State goal) |
Sets the goal for the ProfiledPIDController. | |
constexpr void | SetGoal (Distance_t goal) |
Sets the goal for the ProfiledPIDController. | |
constexpr State | GetGoal () const |
Gets the goal for the ProfiledPIDController. | |
constexpr bool | AtGoal () const |
Returns true if the error is within the tolerance of the error. | |
constexpr void | SetConstraints (Constraints constraints) |
Set velocity and acceleration constraints for goal. | |
constexpr Constraints | GetConstraints () |
Get the velocity and acceleration constraints for this controller. | |
constexpr State | GetSetpoint () const |
Returns the current setpoint of the ProfiledPIDController. | |
constexpr bool | AtSetpoint () const |
Returns true if the error is within the tolerance of the error. | |
constexpr void | EnableContinuousInput (Distance_t minimumInput, Distance_t maximumInput) |
Enables continuous input. | |
constexpr void | DisableContinuousInput () |
Disables continuous input. | |
constexpr void | SetIntegratorRange (double minimumIntegral, double maximumIntegral) |
Sets the minimum and maximum contributions of the integral term. | |
constexpr void | SetTolerance (Distance_t positionTolerance, Velocity_t velocityTolerance=Velocity_t{ std::numeric_limits< double >::infinity()}) |
Sets the error which is considered tolerable for use with AtSetpoint(). | |
constexpr Distance_t | GetPositionError () const |
Returns the difference between the setpoint and the measurement. | |
constexpr Velocity_t | GetVelocityError () const |
Returns the change in error per second. | |
constexpr double | Calculate (Distance_t measurement) |
Returns the next output of the PID controller. | |
constexpr double | Calculate (Distance_t measurement, State goal) |
Returns the next output of the PID controller. | |
constexpr double | Calculate (Distance_t measurement, Distance_t goal) |
Returns the next output of the PID controller. | |
constexpr double | Calculate (Distance_t measurement, Distance_t goal, typename frc::TrapezoidProfile< Distance >::Constraints constraints) |
Returns the next output of the PID controller. | |
constexpr void | Reset (const State &measurement) |
Reset the previous error and the integral term. | |
constexpr void | Reset (Distance_t measuredPosition, Velocity_t measuredVelocity) |
Reset the previous error and the integral term. | |
constexpr void | Reset (Distance_t measuredPosition) |
Reset the previous error and the integral term. | |
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< ProfiledPIDController< Distance > > | |
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< ProfiledPIDController< Distance > > | |
constexpr | SendableHelper ()=default |
constexpr | ~SendableHelper () |
Implements a PID control loop whose setpoint is constrained by a trapezoid profile.
using frc::ProfiledPIDController< Distance >::Acceleration |
using frc::ProfiledPIDController< Distance >::Acceleration_t = units::unit_t<Acceleration> |
using frc::ProfiledPIDController< Distance >::Constraints = typename TrapezoidProfile<Distance>::Constraints |
using frc::ProfiledPIDController< Distance >::Distance_t = units::unit_t<Distance> |
using frc::ProfiledPIDController< Distance >::State = typename TrapezoidProfile<Distance>::State |
using frc::ProfiledPIDController< Distance >::Velocity |
using frc::ProfiledPIDController< Distance >::Velocity_t = units::unit_t<Velocity> |
|
inlineconstexpr |
Allocates a ProfiledPIDController with the given constants for Kp, Ki, and Kd.
Users should call reset() when they first start running the controller to avoid unwanted behavior.
Kp | The proportional coefficient. Must be >= 0. |
Ki | The integral coefficient. Must be >= 0. |
Kd | The derivative coefficient. Must be >= 0. |
constraints | Velocity and acceleration constraints for goal. |
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 error.
This will return false until at least one input value has been computed.
|
inlineconstexpr |
Returns true if the error is within the tolerance of the error.
Currently this just reports on target as the actual value passes through the setpoint. Ideally it should be based on being within the tolerance for some period of time.
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. |
goal | The new goal of the controller. |
|
inlineconstexpr |
Returns the next output of the PID controller.
measurement | The current measurement of the process variable. |
goal | The new goal of the controller. |
constraints | Velocity and acceleration constraints for goal. |
|
inlineconstexpr |
Returns the next output of the PID controller.
measurement | The current measurement of the process variable. |
goal | The new goal 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 |
Get the velocity and acceleration constraints for this controller.
|
inlineconstexpr |
Gets the differential coefficient.
|
inlineconstexpr |
Gets the goal for the ProfiledPIDController.
|
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 ProfiledPIDController.
|
inlineconstexpr |
Returns the change in error per second.
|
inlineconstexpr |
Gets the velocity tolerance of this controller.
|
inlineoverridevirtual |
|
constexprdefault |
|
constexprdefault |
|
inlineconstexpr |
Reset the previous error and the integral term.
measurement | The current measured State of the system. |
|
inlineconstexpr |
Reset the previous error and the integral term.
measuredPosition | The current measured position of the system. The velocity is assumed to be zero. |
|
inlineconstexpr |
Reset the previous error and the integral term.
measuredPosition | The current measured position of the system. |
measuredVelocity | The current measured velocity of the system. |
|
inlineconstexpr |
Set velocity and acceleration constraints for goal.
constraints | Velocity and acceleration constraints for goal. |
|
inlineconstexpr |
Sets the differential coefficient of the PID controller gain.
Kd | The differential coefficient. Must be >= 0. |
|
inlineconstexpr |
Sets the goal for the ProfiledPIDController.
goal | The desired unprofiled setpoint. |
|
inlineconstexpr |
Sets the goal for the ProfiledPIDController.
goal | The desired unprofiled setpoint. |
|
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 error which is considered tolerable for use with AtSetpoint().
positionTolerance | Position error which is tolerable. |
velocityTolerance | Velocity error which is tolerable. |