CTRE Phoenix 6 C++ 25.2.1
Loading...
Searching...
No Matches
ctre::phoenix6::swerve::PhoenixPIDController Class Reference

Phoenix-centric PID controller taken from WPI's frc#PIDController class. More...

#include <ctre/phoenix6/swerve/utility/PhoenixPIDController.hpp>

Public Member Functions

 PhoenixPIDController (double Kp, double Ki, double Kd)
 Allocates a PhoenixPIDController with the given constants for Kp, Ki, and Kd.
 
void SetPID (double Kp, double Ki, double Kd)
 Sets the PID Controller gain parameters.
 
void SetP (double Kp)
 Sets the proportional coefficient of the PID controller gain.
 
void SetI (double Ki)
 Sets the integral coefficient of the PID controller gain.
 
void SetD (double Kd)
 Sets the differential coefficient of the PID controller gain.
 
void SetIZone (double iZone)
 Sets the IZone range.
 
double GetP () const
 Gets the proportional coefficient.
 
double GetI () const
 Gets the integral coefficient.
 
double GetD () const
 Gets the differential coefficient.
 
double GetIZone () const
 Get the IZone range.
 
double GetPositionTolerance () const
 Gets the position tolerance of this controller.
 
double GetVelocityTolerance () const
 Gets the velocity tolerance of this controller.
 
double GetSetpoint () const
 Returns the current setpoint of the PIDController.
 
bool AtSetpoint () const
 Returns true if the error is within the tolerance of the setpoint.
 
void EnableContinuousInput (double minimumInput, double maximumInput)
 Enables continuous input.
 
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.
 
void SetTolerance (double positionTolerance, double velocityTolerance=std::numeric_limits< double >::infinity())
 Sets the error which is considered tolerable for use with AtSetpoint().
 
double GetPositionError () const
 Returns the difference between the setpoint and the measurement.
 
double GetVelocityError () const
 Returns the velocity error.
 
double Calculate (double measurement, double setpoint, units::second_t currentTimestamp)
 Returns the next output of the PID controller.
 
double GetLastAppliedOutput () const
 Returns the last applied output from this PID controller.
 
void Reset ()
 Reset the previous error, the integral term, and disable the controller.
 

Detailed Description

Phoenix-centric PID controller taken from WPI's frc#PIDController class.

This class differs from the WPI implementation by using explicit timestamps for integral/derivative calculations. Ideally, these timestamps come from the StatusSignal.

Constructor & Destructor Documentation

◆ PhoenixPIDController()

ctre::phoenix6::swerve::PhoenixPIDController::PhoenixPIDController ( double Kp,
double Ki,
double Kd )

Allocates a PhoenixPIDController with the given constants for Kp, Ki, and Kd.

Parameters
KpThe proportional coefficient. Must be >= 0.
KiThe integral coefficient. Must be >= 0.
KdThe derivative coefficient. Must be >= 0.

Member Function Documentation

◆ AtSetpoint()

bool ctre::phoenix6::swerve::PhoenixPIDController::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()

double ctre::phoenix6::swerve::PhoenixPIDController::Calculate ( double measurement,
double setpoint,
units::second_t currentTimestamp )

Returns the next output of the PID controller.

Parameters
measurementThe current measurement of the process variable.
setpointThe new setpoint of the controller.
currentTimestampThe current timestamp to use for calculating integral/derivative error

◆ DisableContinuousInput()

void ctre::phoenix6::swerve::PhoenixPIDController::DisableContinuousInput ( )

Disables continuous input.

◆ EnableContinuousInput()

void ctre::phoenix6::swerve::PhoenixPIDController::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 ctre::phoenix6::swerve::PhoenixPIDController::GetD ( ) const

Gets the differential coefficient.

Returns
differential coefficient

◆ GetI()

double ctre::phoenix6::swerve::PhoenixPIDController::GetI ( ) const

Gets the integral coefficient.

Returns
integral coefficient

◆ GetIZone()

double ctre::phoenix6::swerve::PhoenixPIDController::GetIZone ( ) const

Get the IZone range.

Returns
Maximum magnitude of error to allow integral control.

◆ GetLastAppliedOutput()

double ctre::phoenix6::swerve::PhoenixPIDController::GetLastAppliedOutput ( ) const

Returns the last applied output from this PID controller.

◆ GetP()

double ctre::phoenix6::swerve::PhoenixPIDController::GetP ( ) const

Gets the proportional coefficient.

Returns
proportional coefficient

◆ GetPositionError()

double ctre::phoenix6::swerve::PhoenixPIDController::GetPositionError ( ) const

Returns the difference between the setpoint and the measurement.

◆ GetPositionTolerance()

double ctre::phoenix6::swerve::PhoenixPIDController::GetPositionTolerance ( ) const

Gets the position tolerance of this controller.

Returns
The position tolerance of the controller.

◆ GetSetpoint()

double ctre::phoenix6::swerve::PhoenixPIDController::GetSetpoint ( ) const

Returns the current setpoint of the PIDController.

Returns
The current setpoint.

◆ GetVelocityError()

double ctre::phoenix6::swerve::PhoenixPIDController::GetVelocityError ( ) const

Returns the velocity error.

◆ GetVelocityTolerance()

double ctre::phoenix6::swerve::PhoenixPIDController::GetVelocityTolerance ( ) const

Gets the velocity tolerance of this controller.

Returns
The velocity tolerance of the controller.

◆ IsContinuousInputEnabled()

bool ctre::phoenix6::swerve::PhoenixPIDController::IsContinuousInputEnabled ( ) const

Returns true if continuous input is enabled.

◆ Reset()

void ctre::phoenix6::swerve::PhoenixPIDController::Reset ( )

Reset the previous error, the integral term, and disable the controller.

◆ SetD()

void ctre::phoenix6::swerve::PhoenixPIDController::SetD ( double Kd)

Sets the differential coefficient of the PID controller gain.

Parameters
KdThe differential coefficient. Must be >= 0.

◆ SetI()

void ctre::phoenix6::swerve::PhoenixPIDController::SetI ( double Ki)

Sets the integral coefficient of the PID controller gain.

Parameters
KiThe integral coefficient. Must be >= 0.

◆ SetIntegratorRange()

void ctre::phoenix6::swerve::PhoenixPIDController::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.

◆ SetIZone()

void ctre::phoenix6::swerve::PhoenixPIDController::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.

Parameters
iZoneMaximum magnitude of error to allow integral control. Must be >= 0.

◆ SetP()

void ctre::phoenix6::swerve::PhoenixPIDController::SetP ( double Kp)

Sets the proportional coefficient of the PID controller gain.

Parameters
KpThe proportional coefficient. Must be >= 0.

◆ SetPID()

void ctre::phoenix6::swerve::PhoenixPIDController::SetPID ( double Kp,
double Ki,
double Kd )

Sets the PID Controller gain parameters.

Sets the proportional, integral, and differential coefficients.

Parameters
KpThe proportional coefficient. Must be >= 0.
KiThe integral coefficient. Must be >= 0.
KdThe differential coefficient. Must be >= 0.

◆ SetTolerance()

void ctre::phoenix6::swerve::PhoenixPIDController::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.
velocityToleranceVelocity error which is tolerable.

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