WPILibC++  2020.3.2-60-g3011ebe
frc2::PIDController Class Reference

Implements a PID control loop. More...

#include <PIDController.h>

Inheritance diagram for frc2::PIDController:
frc::Sendable frc::SendableHelper< PIDController >

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 (const PIDController &)=default
 
PIDControlleroperator= (const PIDController &)=default
 
 PIDController (PIDController &&)=default
 
PIDControlleroperator= (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...
 
double GetP () const
 Gets the proportional coefficient. More...
 
double GetI () const
 Gets the integral coefficient. More...
 
double GetD () const
 Gets the differential coefficient. More...
 
units::second_t GetPeriod () const
 Gets the period 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.
 
bool IsContinuousInputEnabled () const
 Returns true if continuous input is enabled.
 
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.
 
double GetVelocityError () const
 Returns the velocity error.
 
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.
 
void InitSendable (frc::SendableBuilder &builder) override
 Initializes this Sendable object. More...
 
- Public Member Functions inherited from frc::SendableHelper< PIDController >
 SendableHelper (const SendableHelper &rhs)=default
 
 SendableHelper (SendableHelper &&rhs)
 
SendableHelperoperator= (const SendableHelper &rhs)=default
 
SendableHelperoperator= (SendableHelper &&rhs)
 
std::string GetName () const
 Gets the name of this Sendable object. More...
 
void SetName (const wpi::Twine &name)
 Sets the name of this Sendable object. More...
 
void SetName (const wpi::Twine &subsystem, const wpi::Twine &name)
 Sets both the subsystem name and device name of this Sendable object. More...
 
std::string GetSubsystem () const
 Gets the subsystem name of this Sendable object. More...
 
void SetSubsystem (const wpi::Twine &subsystem)
 Sets the subsystem name of this Sendable object. More...
 

Additional Inherited Members

- Protected Member Functions inherited from frc::SendableHelper< PIDController >
void SetName (const wpi::Twine &moduleType, int channel)
 Sets the name of the sensor with a channel number. More...
 
void SetName (const wpi::Twine &moduleType, int moduleNumber, int channel)
 Sets the name of the sensor with a module and channel number. More...
 
void AddChild (std::shared_ptr< Sendable > child)
 Add a child component. More...
 
void AddChild (void *child)
 Add a child component. More...
 

Detailed Description

Implements a PID control loop.

Constructor & Destructor Documentation

◆ PIDController()

frc2::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.

Parameters
KpThe proportional coefficient.
KiThe integral coefficient.
KdThe derivative coefficient.
periodThe period between controller updates in seconds. The default is 20 milliseconds.

Member Function Documentation

◆ AtSetpoint()

bool frc2::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.

◆ Calculate() [1/2]

double frc2::PIDController::Calculate ( double  measurement)

Returns the next output of the PID controller.

Parameters
measurementThe current measurement of the process variable.

◆ Calculate() [2/2]

double frc2::PIDController::Calculate ( double  measurement,
double  setpoint 
)

Returns the next output of the PID controller.

Parameters
measurementThe current measurement of the process variable.
setpointThe new setpoint of the controller.

◆ EnableContinuousInput()

void frc2::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.

Parameters
minimumInputThe minimum value expected from the input.
maximumInputThe maximum value expected from the input.

◆ GetD()

double frc2::PIDController::GetD ( ) const

Gets the differential coefficient.

Returns
differential coefficient

◆ GetI()

double frc2::PIDController::GetI ( ) const

Gets the integral coefficient.

Returns
integral coefficient

◆ GetP()

double frc2::PIDController::GetP ( ) const

Gets the proportional coefficient.

Returns
proportional coefficient

◆ GetPeriod()

units::second_t frc2::PIDController::GetPeriod ( ) const

Gets the period of this controller.

Returns
The period of the controller.

◆ GetSetpoint()

double frc2::PIDController::GetSetpoint ( ) const

Returns the current setpoint of the PIDController.

Returns
The current setpoint.

◆ InitSendable()

void frc2::PIDController::InitSendable ( frc::SendableBuilder builder)
overridevirtual

Initializes this Sendable object.

Parameters
buildersendable builder

Implements frc::Sendable.

◆ SetD()

void frc2::PIDController::SetD ( double  Kd)

Sets the differential coefficient of the PID controller gain.

Parameters
Kddifferential coefficient

◆ SetI()

void frc2::PIDController::SetI ( double  Ki)

Sets the integral coefficient of the PID controller gain.

Parameters
Kiintegral coefficient

◆ SetIntegratorRange()

void frc2::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.

Parameters
minimumIntegralThe minimum value of the integrator.
maximumIntegralThe maximum value of the integrator.

◆ SetP()

void frc2::PIDController::SetP ( double  Kp)

Sets the proportional coefficient of the PID controller gain.

Parameters
Kpproportional coefficient

◆ SetPID()

void frc2::PIDController::SetPID ( double  Kp,
double  Ki,
double  Kd 
)

Sets the PID Controller gain parameters.

Sets the proportional, integral, and differential coefficients.

Parameters
KpProportional coefficient
KiIntegral coefficient
KdDifferential coefficient

◆ SetSetpoint()

void frc2::PIDController::SetSetpoint ( double  setpoint)

Sets the setpoint for the PIDController.

Parameters
setpointThe desired setpoint.

◆ SetTolerance()

void frc2::PIDController::SetTolerance ( double  positionTolerance,
double  velocityTolerance = std::numeric_limits< double >::infinity() 
)

Sets the error which is considered tolerable for use with AtSetpoint().

Parameters
positionTolerancePosition error which is tolerable.
velociytToleranceVelocity error which is tolerable.

The documentation for this class was generated from the following file: