Documentation
Tools for embedded systems
Loading...
Searching...
No Matches
qlibs::pidController Class Reference

A PID controller object. More...

#include <pid.hpp>

Inheritance diagram for qlibs::pidController:
qlibs::pidGains qlibs::nState

Public Member Functions

virtual ~pidController ()
 
 pidController ()=default
 
bool setup (const real_t kc, const real_t ki, const real_t kd, const real_t dT) noexcept
 Setup and initialize the PID controller instance.
 
bool setup (const pidGains &g, const real_t dT) noexcept
 Setup and initialize the PID controller instance.
 
bool setDirection (const pidDirection d) noexcept
 Set the PID control action direction.
 
bool setParams (const real_t kc, const real_t ti, const real_t td) noexcept
 Set/Change the PID controller gains by using the [Kc, Ti Td ] triplet.
 
bool setGains (const real_t kc, const real_t ki, const real_t kd) noexcept
 Set/Change the PID controller gains.
 
bool setGains (const pidGains &g) noexcept
 Set/Change the PID controller gains.
 
bool setExtraGains (const real_t Kw, const real_t Kt) noexcept
 Set/Change extra PID controller gains.
 
bool setSaturation (const real_t Min, const real_t Max) noexcept
 Setup the output saturation for the PID controller.
 
bool setSeries (void) noexcept
 Convert the controller gains to conform the series or interacting form.
 
bool setEpsilon (const real_t eps) noexcept
 Set the minimum value considered as error.
 
bool setDerivativeFilter (const real_t Beta) noexcept
 Set the tuning parameter for the derivative filter.
 
bool setDerivativeFilterTimeConstant (const real_t Tf) noexcept
 Set the time constant for the derivative filter.
 
bool setMode (const pidMode Mode) noexcept
 Change the controller operational mode. In pidMode::PID_AUTOMATIC, the computed output of the PID controller will be used as the control signal for the process. In pidMode::PID_MANUAL mode, the manual input will be used as the control signal for the process and the PID controller loop will continue operating to guarantee the bumpless-transfer when a switch to the pidMode::PID_AUTOMATIC its performed;.
 
bool setReferenceWeighting (const real_t gb, const real_t gc) noexcept
 Set the PID Reference(Set-Point) Weighting. This value is used in order to avoid the increase of the rise time due to the smoothing of the reference signal applied to the closed-loop system.
 
bool setManualInput (const real_t manualInput) noexcept
 Set the PID manual input mode. This value will be used as the manual input when the controller it set into the pidMode::PID_MANUAL mode. Bumpless-transfer is guaranteed.
 
bool setModelReferenceControl (const real_t &modelRef, const real_t Gamma=0.5_re, const real_t Alpha=0.01_re) noexcept
 Enable the additive MRAC(Model Reference Adaptive Control) feature.
 
bool removeModelReferenceControl (void) noexcept
 Removes the Enable the additive MRAC(Model Reference Adaptive Control) feature from the control loop.
 
real_t control (const real_t w, const real_t y) noexcept
 Computes the control action for given PID controller instance.
 
bool bindAutoTuning (pidAutoTuning &at) noexcept
 Binds the specified instance to enable the PID controller auto tuning algorithm.
 
bool unbindAutoTuning (void) noexcept
 Unbind and disable the PID controller auto-tuning algorithm.
 
bool enableAutoTuning (const uint32_t tEnable) noexcept
 Set the number of time steps where the auto tuner algorithm will modify the controller gains.
 
bool isAutoTuningComplete (void) const noexcept
 Verifies that the auto tuning process has finished with new gains set on the controller.
 
bool setAutoTuningParameters (const real_t Mu, const real_t Alpha, const real_t lambda) noexcept
 Change parameters of the auto-tuning algorithm.
 
bool setAutoTuningControllerType (const pidType t) noexcept
 Select the PID type to tune.
 
bool reset (void) noexcept
 Reset the internal PID controller calculations.
 
pidGains getGains (void) const noexcept
 Retrieve the current PID gains.
 
- Public Member Functions inherited from qlibs::nState
virtual ~nState ()
 
 nState (const real_t x0=0.0_re, const real_t sn_1=0.0_re, const real_t sn_2=0.0_re) noexcept
 Constructor for the state object.
 
void init (const real_t x0=0.0_re, const real_t sn_1=0.0_re, const real_t sn_2=0.0_re) noexcept
 Initialize the state object.
 
real_t integrate (const real_t s, const real_t dt, const bool bUpdate=true) noexcept
 Perform a numerical integration step.
 
real_t derive (const real_t s, const real_t dt, const bool bUpdate=true) noexcept
 Perform a numerical derivation step by using the delta rule.
 
void setIntegrationMethod (integrationMethod m) noexcept
 Set integration method .
 
void setDerivationMethod (derivationMethod m) noexcept
 Set derivation method.
 
real_t operator() (void) const noexcept
 Get the value of the state.
 

Additional Inherited Members

- Public Attributes inherited from qlibs::pidGains
real_t Kc
 
real_t Ki
 
real_t Kd
 

Detailed Description

A PID controller object.

The instance should be initialized using the pid::setup() method.

Constructor & Destructor Documentation

◆ ~pidController()

virtual qlibs::pidController::~pidController ( )
inlinevirtual

◆ pidController()

qlibs::pidController::pidController ( )
default

Member Function Documentation

◆ bindAutoTuning()

bool pidController::bindAutoTuning ( pidAutoTuning & at)
noexcept

Binds the specified instance to enable the PID controller auto tuning algorithm.

Parameters
[in]atThe PID auto-tuning instance.
Returns
true on success, otherwise return false.

◆ control()

real_t pidController::control ( const real_t w,
const real_t y )
noexcept

Computes the control action for given PID controller instance.

Precondition
Instance must be previously initialized by pidController::setup()
Note
The user must ensure that this function is executed in the time specified in dt either by using a HW or SW timer, a real time task, or a timing service.
Parameters
[in]wThe reference value aka SetPoint.
[in]yThe controlled variable aka Process-variable.
Returns
The control action.

◆ enableAutoTuning()

bool pidController::enableAutoTuning ( const uint32_t tEnable)
noexcept

Set the number of time steps where the auto tuner algorithm will modify the controller gains.

Precondition
Controller must have an pidAutoTuning object already binded wih pidController::bindAutoTuning()
Note
To disable auto-tuning pass a 0uL value to the tEnable argument.
Parameters
[in]tEnableThe number of time steps. To keep the auto tuner enabled indefinitely pass pidAutoTuning::UNDEFINED as argument.
Returns
true on success, otherwise return false.

◆ getGains()

pidGains qlibs::pidController::getGains ( void ) const
inlinenoexcept

Retrieve the current PID gains.

Returns
A struct with the pid gains Kc Ki and Kd

◆ isAutoTuningComplete()

bool pidController::isAutoTuningComplete ( void ) const
noexcept

Verifies that the auto tuning process has finished with new gains set on the controller.

Returns
true if auto-tuning its complete, otherwise return false.

◆ removeModelReferenceControl()

bool pidController::removeModelReferenceControl ( void )
noexcept

Removes the Enable the additive MRAC(Model Reference Adaptive Control) feature from the control loop.

Returns
true on success, otherwise return false.

◆ reset()

bool pidController::reset ( void )
noexcept

Reset the internal PID controller calculations.

Returns
true on success, otherwise return false.

◆ setAutoTuningControllerType()

bool pidController::setAutoTuningControllerType ( const pidType t)
noexcept

Select the PID type to tune.

Parameters
[in]tThe type of controller to tune.
Returns
true on success, false on failure.

◆ setAutoTuningParameters()

bool pidController::setAutoTuningParameters ( const real_t Mu,
const real_t Alpha,
const real_t lambda )
noexcept

Change parameters of the auto-tuning algorithm.

Parameters
[in]MuAlgorithm momentum. [ 0 <= Mu <= 1 ].
[in]AlphaFinal controller speed adjustment. [ 0 < Alpha <= 1 ].
[in]lambdaAlgorithm forgetting factor [ 0.8 <= lambda <= 1 ].
Returns
true on success, false on failure.

◆ setDerivativeFilter()

bool pidController::setDerivativeFilter ( const real_t Beta)
noexcept

Set the tuning parameter for the derivative filter.

Parameters
[in]BetaThe tuning parameter. [ 0 <= Beta < 1 ]
Returns
true on success, otherwise return false.

◆ setDerivativeFilterTimeConstant()

bool pidController::setDerivativeFilterTimeConstant ( const real_t Tf)
noexcept

Set the time constant for the derivative filter.

Note
Parameters
[in]TfDerivative filter time constant [ Tf >= 0 ]
Returns
true on success, otherwise return false.

◆ setDirection()

bool pidController::setDirection ( const pidDirection d)
noexcept

Set the PID control action direction.

Parameters
[in]dDesired output direction.
Returns
true on success, otherwise return false.

◆ setEpsilon()

bool pidController::setEpsilon ( const real_t eps)
noexcept

Set the minimum value considered as error.

Parameters
[in]epsThe minimal error value ( eps > 0 ).
Returns
true on success, otherwise return false.

◆ setExtraGains()

bool pidController::setExtraGains ( const real_t Kw,
const real_t Kt )
noexcept

Set/Change extra PID controller gains.

Parameters
[in]KwSaturation feedback gain. Used for antiWindup and bumpless transfer. A zero value disables these features.
[in]KtManual input gain.
Returns
true on success, otherwise return false.

◆ setGains() [1/2]

bool pidController::setGains ( const pidGains & g)
noexcept

Set/Change the PID controller gains.

Parameters
[in]gThe structure with the controller gains
Returns
true on success, otherwise return false.

◆ setGains() [2/2]

bool pidController::setGains ( const real_t kc,
const real_t ki,
const real_t kd )
noexcept

Set/Change the PID controller gains.

Parameters
[in]kcProportional Gain.
[in]kiIntegral Gain.
[in]kdDerivative Gain.
Returns
true on success, otherwise return false.

◆ setManualInput()

bool pidController::setManualInput ( const real_t manualInput)
noexcept

Set the PID manual input mode. This value will be used as the manual input when the controller it set into the pidMode::PID_MANUAL mode. Bumpless-transfer is guaranteed.

Parameters
[in]manualInputThe value of the manual input.
Returns
true on success, otherwise return false.

◆ setMode()

bool pidController::setMode ( const pidMode Mode)
noexcept

Change the controller operational mode. In pidMode::PID_AUTOMATIC, the computed output of the PID controller will be used as the control signal for the process. In pidMode::PID_MANUAL mode, the manual input will be used as the control signal for the process and the PID controller loop will continue operating to guarantee the bumpless-transfer when a switch to the pidMode::PID_AUTOMATIC its performed;.

Parameters
[in]ModeThe desired operational mode.
Returns
true on success, otherwise return false.

◆ setModelReferenceControl()

bool pidController::setModelReferenceControl ( const real_t & modelRef,
const real_t Gamma = 0.5_re,
const real_t Alpha = 0.01_re )
noexcept

Enable the additive MRAC(Model Reference Adaptive Control) feature.

Parameters
[in]modelRefA pointer to the output of the model reference.
[in]GammaAdjustable parameter to indicate the adaptation speed.
[in]AlphaAdjustable parameter the adaptation momentum.
Returns
true on success, otherwise return false.

◆ setParams()

bool pidController::setParams ( const real_t kc,
const real_t ti,
const real_t td )
noexcept

Set/Change the PID controller gains by using the [Kc, Ti Td ] triplet.

Parameters
[in]kcProportional Gain.
[in]tiIntegral time.
[in]tdDerivative time.
Returns
true on success, otherwise return false.

◆ setReferenceWeighting()

bool pidController::setReferenceWeighting ( const real_t gb,
const real_t gc )
noexcept

Set the PID Reference(Set-Point) Weighting. This value is used in order to avoid the increase of the rise time due to the smoothing of the reference signal applied to the closed-loop system.

Note
A value close to zero en gc can be used to eliminate the reduce the effect of the phenomena called "derivative-kick"
Parameters
[in]gbThe reference weight value for the proportional element.
[in]gcThe reference weight value for the derivative element.
Returns
true on success, otherwise return false.

◆ setSaturation()

bool pidController::setSaturation ( const real_t Min,
const real_t Max )
noexcept

Setup the output saturation for the PID controller.

Parameters
[in]MinThe minimal value allowed for the output.
[in]MaxThe maximal value allowed for the output.
Returns
true on success, otherwise return false.

◆ setSeries()

bool pidController::setSeries ( void )
noexcept

Convert the controller gains to conform the series or interacting form.

Returns
true on success, otherwise return false.

◆ setup() [1/2]

bool qlibs::pidController::setup ( const pidGains & g,
const real_t dT )
inlinenoexcept

Setup and initialize the PID controller instance.

Parameters
[in]gThe structure with the controller gains
[in]dTTime step in seconds.
Returns
true on success, otherwise return false.

◆ setup() [2/2]

bool pidController::setup ( const real_t kc,
const real_t ki,
const real_t kd,
const real_t dT )
noexcept

Setup and initialize the PID controller instance.

Parameters
[in]kcProportional Gain.
[in]kiIntegral Gain.
[in]kdDerivative Gain.
[in]dTTime step in seconds.
Returns
true on success, otherwise return false.

◆ unbindAutoTuning()

bool qlibs::pidController::unbindAutoTuning ( void )
inlinenoexcept

Unbind and disable the PID controller auto-tuning algorithm.

Returns
true on success, otherwise return false.