HoloLib
High-performance holonomic (X-Drive) control library for VEX V5
Loading...
Searching...
No Matches
PID Class Reference

A standard PID controller with advanced features. More...

#include <PID.h>

Public Member Functions

 PID (double kP, double kI, double kD, double kF=0, double windupRange=0, bool signFlipReset=false, double slew=0)
 Construct a new PID controller.
 
 PID (const PIDGains &gains, double windupRange=0, bool signFlipReset=false)
 Construct a new PID controller from a PIDGains struct.
 
PIDGains getGains ()
 Get the current gains of the PID controller.
 
void setGains (PIDGains gains)
 Set new gains for the PID controller.
 
double update (double error)
 Update the PID controller based on the current error.
 
double update (double error, double measurement)
 Update the PID controller based on error and actual measurement (to prevent derivative kick).
 
void reset ()
 Reset the PID controller's internal state (integral, previous error, etc.).
 
void setSignFlipReset (bool signFlipReset)
 Enable or disable resetting the integral term when the error sign flips.
 
bool getSignFlipReset ()
 Check if sign-flip integral reset is enabled.
 
void setWindupRange (double windupRange)
 Set the windup range within which the integral term is allowed to accumulate.
 
double getWindupRange ()
 Get the current windup range.
 
void setAlpha (double alpha)
 Set the alpha value for the derivative filter.
 
double getAlpha ()
 Get the alpha value for the derivative filter.
 
void setIntegralLimit (double limit)
 Set the maximum absolute value for the integral term.
 
double getIntegralLimit ()
 Get the integral limit.
 
void setStaticThreshold (double threshold)
 Set the static threshold error value.
 
double getStaticThreshold ()
 Get the static threshold error value.
 

Detailed Description

A standard PID controller with advanced features.

Includes support for windup range limits, sign-flip resets, slew rate limits, filtered derivatives, and integral limits.

Definition at line 22 of file PID.h.

Constructor & Destructor Documentation

◆ PID() [1/2]

PID::PID ( double  kP,
double  kI,
double  kD,
double  kF = 0,
double  windupRange = 0,
bool  signFlipReset = false,
double  slew = 0 
)

Construct a new PID controller.

Parameters
kPProportional gain.
kIIntegral gain.
kDDerivative gain.
kFFeed-forward gain.
windupRangeRange within which the integral term accumulates.
signFlipResetIf true, resets the integral when the error sign flips.
slewMaximum change in output per update.

◆ PID() [2/2]

PID::PID ( const PIDGains gains,
double  windupRange = 0,
bool  signFlipReset = false 
)

Construct a new PID controller from a PIDGains struct.

Parameters
gainsA struct containing the Kp, Ki, Kd, Kf, and slew rate.
windupRangeRange within which the integral term accumulates.
signFlipResetIf true, resets the integral when the error sign flips.

Member Function Documentation

◆ getGains()

PIDGains PID::getGains ( )

Get the current gains of the PID controller.

Returns
PIDGains The current gains.

◆ setGains()

void PID::setGains ( PIDGains  gains)

Set new gains for the PID controller.

Parameters
gainsThe new gains to apply.

◆ update() [1/2]

double PID::update ( double  error)

Update the PID controller based on the current error.

Parameters
errorThe current error (target - measurement).
Returns
double The computed output from the PID controller.

◆ update() [2/2]

double PID::update ( double  error,
double  measurement 
)

Update the PID controller based on error and actual measurement (to prevent derivative kick).

Parameters
errorThe current error.
measurementThe current measurement/sensor value.
Returns
double The computed output from the PID controller.

◆ reset()

void PID::reset ( )

Reset the PID controller's internal state (integral, previous error, etc.).

◆ setSignFlipReset()

void PID::setSignFlipReset ( bool  signFlipReset)

Enable or disable resetting the integral term when the error sign flips.

Parameters
signFlipResetTrue to enable, false to disable.

◆ getSignFlipReset()

bool PID::getSignFlipReset ( )

Check if sign-flip integral reset is enabled.

Returns
true if enabled, false otherwise.

◆ setWindupRange()

void PID::setWindupRange ( double  windupRange)

Set the windup range within which the integral term is allowed to accumulate.

Parameters
windupRangeThe windup range.

◆ getWindupRange()

double PID::getWindupRange ( )

Get the current windup range.

Returns
double The windup range.

◆ setAlpha()

void PID::setAlpha ( double  alpha)
inline

Set the alpha value for the derivative filter.

Parameters
alphaThe filter constant (0.0 to 1.0).

Definition at line 138 of file PID.h.

◆ getAlpha()

double PID::getAlpha ( )
inline

Get the alpha value for the derivative filter.

Returns
double The current alpha value.

Definition at line 145 of file PID.h.

◆ setIntegralLimit()

void PID::setIntegralLimit ( double  limit)
inline

Set the maximum absolute value for the integral term.

Parameters
limitThe maximum integral value.

Definition at line 152 of file PID.h.

◆ getIntegralLimit()

double PID::getIntegralLimit ( )
inline

Get the integral limit.

Returns
double The integral limit.

Definition at line 159 of file PID.h.

◆ setStaticThreshold()

void PID::setStaticThreshold ( double  threshold)
inline

Set the static threshold error value.

Parameters
thresholdThe threshold value.

Definition at line 166 of file PID.h.

◆ getStaticThreshold()

double PID::getStaticThreshold ( )
inline

Get the static threshold error value.

Returns
double The static threshold value.

Definition at line 173 of file PID.h.