Valkyrie 2026
Loading...
Searching...
No Matches
valor::ProfiledPIDController< INPUT, OUTPUT > Class Template Reference

#include <valkyrie/controllers/ProfiledPIDController.h>

Public Types

using ErrorDerivative = units::unit_t<units::compound_unit<INPUT, units::inverse<units::second>>>

Public Member Functions

constexpr ProfiledPIDController (const PIDF< INPUT, OUTPUT > &pidf, units::second_t period=20_ms)
constexpr void SetPID (const PIDF< INPUT, OUTPUT > &pidf)
constexpr void SetIZone (PIDF< INPUT, OUTPUT >::Output_t iZone)
PIDF< INPUT, OUTPUT > GetPID () const
constexpr PIDF< INPUT, OUTPUT >::Output_t GetIZone () const
constexpr units::second_t GetPeriod () const
constexpr PIDF< INPUT, OUTPUT >::Input_t GetPositionTolerance () const
constexpr ErrorDerivative GetVelocityTolerance () const
constexpr PIDF< INPUT, OUTPUT >::Input_t GetAccumulatedError () const
constexpr void SetGoal (frc::TrapezoidProfile< INPUT >::State goal)
constexpr frc::TrapezoidProfile< INPUT >::State GetGoal () const
constexpr bool AtGoal () const
constexpr frc::TrapezoidProfile< INPUT >::State GetSetpoint () const
constexpr bool AtSetpoint () const
constexpr void EnableContinuousInput (PIDF< INPUT, OUTPUT >::Input_t minimumInput, PIDF< INPUT, OUTPUT >::Input_t maximumInput)
constexpr void DisableContinuousInput ()
constexpr void SetIntegratorRange (PIDF< INPUT, OUTPUT >::Output_t minimumIntegral, PIDF< INPUT, OUTPUT >::Output_t maximumIntegral)
constexpr void SetTolerance (PIDF< INPUT, OUTPUT >::Input_t positionTolerance, ErrorDerivative velocityTolerance=ErrorDerivative{std::numeric_limits< double >::infinity()})
constexpr PIDF< INPUT, OUTPUT >::Input_t GetPositionError () const
constexpr ErrorDerivative GetVelocityError () const
constexpr PIDF< INPUT, OUTPUT >::Output_t Calculate (PIDF< INPUT, OUTPUT >::Input_t measurement)
constexpr void Reset (const frc::TrapezoidProfile< INPUT >::State &measurement)

Detailed Description

template<typename INPUT, typename OUTPUT>
class valor::ProfiledPIDController< INPUT, OUTPUT >

Implements a PID control loop whose setpoint is constrained by a trapezoid profile.

Constructor & Destructor Documentation

◆ ProfiledPIDController()

template<typename INPUT, typename OUTPUT>
valor::ProfiledPIDController< INPUT, OUTPUT >::ProfiledPIDController ( const PIDF< INPUT, OUTPUT > & pidf,
units::second_t period = 20_ms )
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.

Parameters
pidfThe PIDF gains
constraintsVelocity and acceleration constraints for goal.
periodThe period between controller updates in seconds. The default is 20 milliseconds. Must be positive.

Member Function Documentation

◆ AtGoal()

template<typename INPUT, typename OUTPUT>
bool valor::ProfiledPIDController< INPUT, OUTPUT >::AtGoal ( ) const
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.

◆ AtSetpoint()

template<typename INPUT, typename OUTPUT>
bool valor::ProfiledPIDController< INPUT, OUTPUT >::AtSetpoint ( ) const
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.

◆ Calculate()

template<typename INPUT, typename OUTPUT>
PIDF< INPUT, OUTPUT >::Output_t valor::ProfiledPIDController< INPUT, OUTPUT >::Calculate ( PIDF< INPUT, OUTPUT >::Input_t measurement)
inlineconstexpr

Returns the next output of the PID controller.

Parameters
measurementThe current measurement of the process variable.

◆ DisableContinuousInput()

template<typename INPUT, typename OUTPUT>
void valor::ProfiledPIDController< INPUT, OUTPUT >::DisableContinuousInput ( )
inlineconstexpr

Disables continuous input.

◆ EnableContinuousInput()

template<typename INPUT, typename OUTPUT>
void valor::ProfiledPIDController< INPUT, OUTPUT >::EnableContinuousInput ( PIDF< INPUT, OUTPUT >::Input_t minimumInput,
PIDF< INPUT, OUTPUT >::Input_t maximumInput )
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.

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

◆ GetAccumulatedError()

template<typename INPUT, typename OUTPUT>
PIDF< INPUT, OUTPUT >::Input_t valor::ProfiledPIDController< INPUT, OUTPUT >::GetAccumulatedError ( ) const
inlineconstexpr

Gets the accumulated error used in the integral calculation of this controller.

Returns
The accumulated error of this controller.

◆ GetGoal()

template<typename INPUT, typename OUTPUT>
frc::TrapezoidProfile< INPUT >::State valor::ProfiledPIDController< INPUT, OUTPUT >::GetGoal ( ) const
inlineconstexpr

Gets the goal for the ProfiledPIDController.

◆ GetIZone()

template<typename INPUT, typename OUTPUT>
PIDF< INPUT, OUTPUT >::Output_t valor::ProfiledPIDController< INPUT, OUTPUT >::GetIZone ( ) const
inlineconstexpr

Get the IZone range.

Returns
Maximum magnitude of error to allow integral control.

◆ GetPeriod()

template<typename INPUT, typename OUTPUT>
units::second_t valor::ProfiledPIDController< INPUT, OUTPUT >::GetPeriod ( ) const
inlineconstexpr

Gets the period of this controller.

Returns
The period of the controller.

◆ GetPID()

template<typename INPUT, typename OUTPUT>
PIDF< INPUT, OUTPUT > valor::ProfiledPIDController< INPUT, OUTPUT >::GetPID ( ) const
inline

Gets the proportional coefficient.

Returns
PIDF gains

◆ GetPositionError()

template<typename INPUT, typename OUTPUT>
PIDF< INPUT, OUTPUT >::Input_t valor::ProfiledPIDController< INPUT, OUTPUT >::GetPositionError ( ) const
inlineconstexpr

Returns the difference between the setpoint and the measurement.

Returns
The error.

◆ GetPositionTolerance()

template<typename INPUT, typename OUTPUT>
PIDF< INPUT, OUTPUT >::Input_t valor::ProfiledPIDController< INPUT, OUTPUT >::GetPositionTolerance ( ) const
inlineconstexpr

Gets the position tolerance of this controller.

Returns
The position tolerance of the controller.

◆ GetSetpoint()

template<typename INPUT, typename OUTPUT>
frc::TrapezoidProfile< INPUT >::State valor::ProfiledPIDController< INPUT, OUTPUT >::GetSetpoint ( ) const
inlineconstexpr

Returns the current setpoint of the ProfiledPIDController.

Returns
The current setpoint.

◆ GetVelocityError()

template<typename INPUT, typename OUTPUT>
ErrorDerivative valor::ProfiledPIDController< INPUT, OUTPUT >::GetVelocityError ( ) const
inlineconstexpr

Returns the change in error per second.

◆ GetVelocityTolerance()

template<typename INPUT, typename OUTPUT>
ErrorDerivative valor::ProfiledPIDController< INPUT, OUTPUT >::GetVelocityTolerance ( ) const
inlineconstexpr

Gets the velocity tolerance of this controller.

Returns
The velocity tolerance of the controller.

◆ Reset()

template<typename INPUT, typename OUTPUT>
void valor::ProfiledPIDController< INPUT, OUTPUT >::Reset ( const frc::TrapezoidProfile< INPUT >::State & measurement)
inlineconstexpr

Reset the previous error and the integral term.

Parameters
measurementThe current measured State of the system.

◆ SetGoal()

template<typename INPUT, typename OUTPUT>
void valor::ProfiledPIDController< INPUT, OUTPUT >::SetGoal ( frc::TrapezoidProfile< INPUT >::State goal)
inlineconstexpr

Sets the goal for the ProfiledPIDController.

Parameters
goalThe desired unprofiled setpoint.

◆ SetIntegratorRange()

template<typename INPUT, typename OUTPUT>
void valor::ProfiledPIDController< INPUT, OUTPUT >::SetIntegratorRange ( PIDF< INPUT, OUTPUT >::Output_t minimumIntegral,
PIDF< INPUT, OUTPUT >::Output_t maximumIntegral )
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.

Parameters
minimumIntegralThe minimum contribution of the integral term.
maximumIntegralThe maximum contribution of the integral term.

◆ SetIZone()

template<typename INPUT, typename OUTPUT>
void valor::ProfiledPIDController< INPUT, OUTPUT >::SetIZone ( PIDF< INPUT, OUTPUT >::Output_t iZone)
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.

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

◆ SetPID()

template<typename INPUT, typename OUTPUT>
void valor::ProfiledPIDController< INPUT, OUTPUT >::SetPID ( const PIDF< INPUT, OUTPUT > & pidf)
inlineconstexpr

Sets the PID Controller gain parameters.

Sets the proportional, integral, and differential coefficients.

Parameters
pidfThe PIDF gains

◆ SetTolerance()

template<typename INPUT, typename OUTPUT>
void valor::ProfiledPIDController< INPUT, OUTPUT >::SetTolerance ( PIDF< INPUT, OUTPUT >::Input_t positionTolerance,
ErrorDerivative velocityTolerance = ErrorDerivative{std::numeric_limits<double>::infinity()} )
inlineconstexpr

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: