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

#include <valkyrie/controllers/PIDController.h>

Inheritance diagram for valor::PIDController< INPUT, OUTPUT >:

Public Types

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

Public Member Functions

constexpr PIDController (const PIDF< INPUT, OUTPUT > &pidf, units::second_t period=Robot::kDefaultPeriod)
constexpr void SetPID (const PIDF< INPUT, OUTPUT > &pidf)
constexpr void SetP (PIDF< INPUT, OUTPUT >::ProportionalGain_t Kp)
constexpr void SetI (PIDF< INPUT, OUTPUT >::IntegralGain_t Ki)
constexpr void SetD (PIDF< INPUT, OUTPUT >::DerivativeGain_t Kd)
constexpr void SetIZone (PIDF< INPUT, OUTPUT >::Output_t iZone)
constexpr PIDF< INPUT, OUTPUT >::ProportionalGain_t GetP () const
constexpr PIDF< INPUT, OUTPUT >::IntegralGain_t GetI () const
constexpr PIDF< INPUT, OUTPUT >::DerivativeGain_t GetD () const
constexpr PIDF< INPUT, OUTPUT >::Output_t GetIZone () const
constexpr PIDF< INPUT, OUTPUT >::Input_t GetErrorTolerance () const
constexpr ErrorDerivative GetErrorDerivativeTolerance () const
constexpr PIDF< INPUT, OUTPUT >::Input_t GetAccumulatedError () const
constexpr void SetSetpoint (PIDF< INPUT, OUTPUT >::Input_t setpoint)
constexpr PIDF< INPUT, OUTPUT >::Input_t GetSetpoint () const
constexpr void EnableContinuousInput (PIDF< INPUT, OUTPUT >::Input_t minimumInput, PIDF< INPUT, OUTPUT >::Input_t maximumInput)
constexpr void SetIntegratorRange (PIDF< INPUT, OUTPUT >::Output_t minimumIntegral, PIDF< INPUT, OUTPUT >::Output_t maximumIntegral)
constexpr void SetTolerance (PIDF< INPUT, OUTPUT >::Input_t errorTolerance, ErrorDerivative errorDerivativeTolerance=ErrorDerivative{std::numeric_limits< double >::infinity()})
constexpr PIDF< INPUT, OUTPUT >::Input_t GetError () const
constexpr ErrorDerivative GetErrorDerivative () const
constexpr const valor::PIDF< INPUT, OUTPUT > & GetPID () const
constexpr PIDF< INPUT, OUTPUT >::Output_t Calculate (PIDF< INPUT, OUTPUT >::Input_t measurement)
constexpr PIDF< INPUT, OUTPUT >::Output_t Calculate (PIDF< INPUT, OUTPUT >::Input_t measurement, PIDF< INPUT, OUTPUT >::Input_t setpoint)

Detailed Description

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

Implements a PID control loop.

Constructor & Destructor Documentation

◆ PIDController()

template<typename INPUT, typename OUTPUT>
valor::PIDController< INPUT, OUTPUT >::PIDController ( const PIDF< INPUT, OUTPUT > & pidf,
units::second_t period = Robot::kDefaultPeriod )
inlineconstexpr

Allocates a PIDController with the given constants.

Parameters
pidfThe PIDF structure defining feedforward and gains.
periodThe period between controller updates in seconds. The default is 20 milliseconds. Must be positive.

Member Function Documentation

◆ Calculate() [1/2]

template<typename INPUT, typename OUTPUT>
PIDF< INPUT, OUTPUT >::Output_t valor::PIDController< 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.

◆ Calculate() [2/2]

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

Returns the next output of the PID controller.

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

◆ EnableContinuousInput()

template<typename INPUT, typename OUTPUT>
void valor::PIDController< 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::PIDController< INPUT, OUTPUT >::GetAccumulatedError ( ) const
inlineconstexpr

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

Returns
The accumulated error of this controller.

◆ GetD()

template<typename INPUT, typename OUTPUT>
PIDF< INPUT, OUTPUT >::DerivativeGain_t valor::PIDController< INPUT, OUTPUT >::GetD ( ) const
inlineconstexpr

Gets the differential coefficient.

Returns
differential coefficient

◆ GetError()

template<typename INPUT, typename OUTPUT>
PIDF< INPUT, OUTPUT >::Input_t valor::PIDController< INPUT, OUTPUT >::GetError ( ) const
inlineconstexpr

Returns the difference between the setpoint and the measurement.

◆ GetErrorDerivative()

template<typename INPUT, typename OUTPUT>
ErrorDerivative valor::PIDController< INPUT, OUTPUT >::GetErrorDerivative ( ) const
inlineconstexpr

Returns the error derivative.

◆ GetErrorDerivativeTolerance()

template<typename INPUT, typename OUTPUT>
ErrorDerivative valor::PIDController< INPUT, OUTPUT >::GetErrorDerivativeTolerance ( ) const
inlineconstexpr

Gets the error derivative tolerance of this controller. Defaults to ∞.

Returns
The error derivative tolerance of the controller.

◆ GetErrorTolerance()

template<typename INPUT, typename OUTPUT>
PIDF< INPUT, OUTPUT >::Input_t valor::PIDController< INPUT, OUTPUT >::GetErrorTolerance ( ) const
inlineconstexpr

Gets the error tolerance of this controller. Defaults to 0.05.

Returns
The error tolerance of the controller.

◆ GetI()

template<typename INPUT, typename OUTPUT>
PIDF< INPUT, OUTPUT >::IntegralGain_t valor::PIDController< INPUT, OUTPUT >::GetI ( ) const
inlineconstexpr

Gets the integral coefficient.

Returns
integral coefficient

◆ GetIZone()

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

Get the IZone range.

Returns
Maximum magnitude of error to allow integral control.

◆ GetP()

template<typename INPUT, typename OUTPUT>
PIDF< INPUT, OUTPUT >::ProportionalGain_t valor::PIDController< INPUT, OUTPUT >::GetP ( ) const
inlineconstexpr

Gets the proportional coefficient.

Returns
proportional coefficient

◆ GetPID()

template<typename INPUT, typename OUTPUT>
const valor::PIDF< INPUT, OUTPUT > & valor::PIDController< INPUT, OUTPUT >::GetPID ( ) const
inlineconstexpr

Gets the PID gains

Returns
PID gains

◆ GetSetpoint()

template<typename INPUT, typename OUTPUT>
PIDF< INPUT, OUTPUT >::Input_t valor::PIDController< INPUT, OUTPUT >::GetSetpoint ( ) const
inlineconstexpr

Returns the current setpoint of the PIDController.

Returns
The current setpoint.

◆ SetD()

template<typename INPUT, typename OUTPUT>
void valor::PIDController< INPUT, OUTPUT >::SetD ( PIDF< INPUT, OUTPUT >::DerivativeGain_t Kd)
inlineconstexpr

Sets the differential coefficient of the PID controller gain.

Parameters
KdThe differential coefficient. Must be >= 0.

◆ SetI()

template<typename INPUT, typename OUTPUT>
void valor::PIDController< INPUT, OUTPUT >::SetI ( PIDF< INPUT, OUTPUT >::IntegralGain_t Ki)
inlineconstexpr

Sets the integral coefficient of the PID controller gain.

Parameters
KiThe integral coefficient. Must be >= 0.

◆ SetIntegratorRange()

template<typename INPUT, typename OUTPUT>
void valor::PIDController< 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::PIDController< 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.

◆ SetP()

template<typename INPUT, typename OUTPUT>
void valor::PIDController< INPUT, OUTPUT >::SetP ( PIDF< INPUT, OUTPUT >::ProportionalGain_t Kp)
inlineconstexpr

Sets the proportional coefficient of the PID controller gain.

Parameters
KpThe proportional coefficient. Must be >= 0.

◆ SetPID()

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

Sets the PID Controller gain parameters.

Parameters
pidfThe PIDF structure defining feedforward and gains.

◆ SetSetpoint()

template<typename INPUT, typename OUTPUT>
void valor::PIDController< INPUT, OUTPUT >::SetSetpoint ( PIDF< INPUT, OUTPUT >::Input_t setpoint)
inlineconstexpr

Sets the setpoint for the PIDController.

Parameters
setpointThe desired setpoint.

◆ SetTolerance()

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

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

Parameters
errorToleranceerror which is tolerable.
errorDerivativeToleranceerror derivative which is tolerable.

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