AGX Dynamics  2.35.0.1
agxModel::PidController1D Class Reference

A PID controller with the classic gain coefficients for proportional, integral, and derivative gain. More...

#include <PidController1D.h>

+ Inheritance diagram for agxModel::PidController1D:

Classes

class  Derivative
 Differentiate a PID controller signal with a two point estimation. More...
 
class  DerivativeFivePointStencil
 Differentiate a PID controller signal with the "five-point stencil" method. More...
 
class  DerivativeThreePointSkewedStencil
 Differentiate a PID controller signal with the "three-point stencil" method. More...
 

Public Types

enum class  DerivationMethod : agx::UInt32 { FIRSTORDER = 1 << 0 , FIVEPOINTSTENCIL = 1 << 1 , THREEPOINTSKEWEDSTENCIL = 1 << 2 }
 
typedef agx::observer_ptr< const Derivative > DerivativeConstObserver
 
typedef agx::ref_ptr< const Derivative > DerivativeConstRef
 
typedef agx::observer_ptr< const DerivativeFivePointStencil > DerivativeFivePointStencilConstObserver
 
typedef agx::ref_ptr< const DerivativeFivePointStencil > DerivativeFivePointStencilConstRef
 
typedef agx::observer_ptr< DerivativeFivePointStencil > DerivativeFivePointStencilObserver
 
typedef agx::ref_ptr< DerivativeFivePointStencil > DerivativeFivePointStencilRef
 
typedef agx::observer_ptr< Derivative > DerivativeObserver
 
typedef agx::ref_ptr< Derivative > DerivativeRef
 
typedef agx::observer_ptr< const DerivativeThreePointSkewdStencil > DerivativeThreePointSkewdStencilConstObserver
 
typedef agx::ref_ptr< const DerivativeThreePointSkewdStencil > DerivativeThreePointSkewdStencilConstRef
 
typedef agx::observer_ptr< DerivativeThreePointSkewdStencil > DerivativeThreePointSkewdStencilObserver
 
typedef agx::ref_ptr< DerivativeThreePointSkewdStencil > DerivativeThreePointSkewdStencilRef
 

Public Member Functions

 PidController1D ()
 
agx::Real calculateCostFunctionValue (agx::Real deltaTime) const
 This will calculate the cost function value between the last time update() was called and last time minus deltaTime so that (t - t0) = deltaTime, where t is the last time update() was called. More...
 
void disablePidController ()
 Disable the PID controller. The Manipulated Value will be zero. More...
 
void enablePidController ()
 Enable the PID controller. More...
 
agx::Real getDerivativeGain () const
 
agx::Real getDerivativeTerm () const
 
agx::Real getDerivativeTime ()
 
agx::Real getError () const
 
agx::Real getFrequency () const
 
agx::Vec3 getGains () const
 
agx::Real getIntegralGain () const
 
agx::Real getIntegralTime ()
 
const agx::Vec2 & getIntegralWindupClamping () const
 
agx::Real getIntegraTerm () const
 
virtual agx::Real getManipulatedVariable () const override
 
const agx::Vec2 & getManipulatedVariableAccelerationLimit () const
 
const agx::Vec2 & getManipulatedVariableLimit () const
 
agx::Real getMeasuredProcessVariable () const
 
agx::Real getProportionalGain () const
 
agx::Real getProportionalTerm () const
 
virtual agx::Real getSetPoint () const override
 
bool hasEnabledIntegralWindupProtection () const
 
bool isEnabled ()
 
virtual void reset () override
 Reset calculated gain, error, and cost to 0. More...
 
void setDerivationMethod (Derivative *derivationMethod)
 Change the derivation method. Default is the first order numerical derivation method. More...
 
void setDerivationType (DerivationMethod derivationMethod)
 Change the derivation method. Default is the first order numerical derivation method DerivationMethod::FirstOrder. More...
 
void setDerivativeGain (agx::Real derivativeGain)
 Set the derivative gain, K_d. More...
 
void setDerivativeTime (agx::Real derivativeTime)
 Set the derivative time defined as T_d = K_d / K_p. More...
 
void setFrequency (agx::Real frequency)
 Set PID frequency for gain compensation of the derivative and integral term, default values is 1. More...
 
void setGains (agx::Real proportionalGain, agx::Real integralGain, agx::Real derivativeGain)
 Set the gains. More...
 
void setIntegralGain (agx::Real integralGain)
 Set the integral gain, K_i. More...
 
void setIntegralTime (agx::Real integralTime)
 Set the integral time defined as T_i = K_p / K_i. More...
 
void setIntegralWindupClamping (agx::Real lowerLimitIntegralTerm, agx::Real upperLimitIntegralTerm)
 Set the lower and upper limit of the integral gain term, getIntegraTerm(). More...
 
void setIntegralWindupProtection (bool doIntegralWindupProtection)
 Enable or disable the integral windup backward calculation. More...
 
void setManipulatedVariableAccelerationLimit (agx::Real lowerLimit, agx::Real upperLimit)
 Limit the Manipulated Variable acceleration dMV/dt between this lower and upper limit. Default limits are +/- agx::Real max value. More...
 
void setManipulatedVariableLimit (agx::Real lowerLimit, agx::Real upperLimit)
 Limit the Manipulated Variable between this lower and upper limit. Default limits are +/- agx::Real max value. More...
 
void setProportionalGain (agx::Real proportionalGain)
 Set the proportional gain, K_p. More...
 
virtual void setSetPoint (agx::Real setPoint) override
 Set the current Set Point for the controller. More...
 
virtual void update (const agx::TimeStamp &time, agx::Real measuredProcessVariable) override
 Update the measured Process Variable and calculate a new value for the Manipulated Variable. More...
 
- Public Member Functions inherited from agx::Referenced
 Referenced ()
 Default constructor. More...
 
 Referenced (const Referenced &)
 
template<typename T >
T * as ()
 Subclass casting. More...
 
template<typename T >
const T * as () const
 
template<typename T >
T * asSafe ()
 Safe subclass casting, return nullptr if template type does not match. More...
 
template<typename T >
const T * asSafe () const
 
int getReferenceCount () const
 
template<typename T >
bool is () const
 Subclass test. More...
 
Referenced & operator= (const Referenced &)
 Assignment operator. Will increment the number of references to the referenced object. More...
 
void reference (void *ptr=nullptr) const
 Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void unreference (void *ptr=nullptr) const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unreference_nodelete () const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from agx::Referenced
template<typename T >
static bool ValidateCast (const Referenced *object)
 
- Protected Member Functions inherited from agx::Referenced
virtual ~Referenced ()
 Destructor. More...
 
void allocateObserverVector () const
 
void deleteUsingDeleteHandler () const
 
- Static Protected Member Functions inherited from agx::Referenced
static DeleteHandler * getDeleteHandler ()
 
static void setDeleteHandler (DeleteHandler *handler)
 Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to. More...
 
- Protected Attributes inherited from agx::Referenced
Mutex m_mutex
 
ObserverContainer m_observers
 
AtomicValue m_refCount
 

Detailed Description

A PID controller with the classic gain coefficients for proportional, integral, and derivative gain.

The PID controller has an integral windup algorithm with both "clamping" and/or an integral back-calculation algorithm. The backward calculation is done by recomputing the integral term to its previous state before the windup started and by that disabling the integration.

The PID controller may also add constraints on the Manipulated Variable (MV) and/or the acceleration of the Manipulated Variable (dMV/dt). For example, the Manipulated Variable limits might be set to a winch max/min speed and max/min force.

To reduce noise in the time derivative of the error, dE/dt, the PID controller could use a longer time interval to differentiate the error, e.g. the five-point stencil method.

Definition at line 42 of file PidController1D.h.

Member Typedef Documentation

◆ DerivativeConstObserver

◆ DerivativeConstRef

◆ DerivativeFivePointStencilConstObserver

◆ DerivativeFivePointStencilConstRef

◆ DerivativeFivePointStencilObserver

◆ DerivativeFivePointStencilRef

◆ DerivativeObserver

◆ DerivativeRef

◆ DerivativeThreePointSkewdStencilConstObserver

Definition at line 90 of file PidController1D.h.

◆ DerivativeThreePointSkewdStencilConstRef

typedef agx::ref_ptr< const DerivativeThreePointSkewdStencil > agxModel::PidController1D::DerivativeThreePointSkewdStencilConstRef

Definition at line 90 of file PidController1D.h.

◆ DerivativeThreePointSkewdStencilObserver

Definition at line 90 of file PidController1D.h.

◆ DerivativeThreePointSkewdStencilRef

Definition at line 90 of file PidController1D.h.

Member Enumeration Documentation

◆ DerivationMethod

Enumerator
FIRSTORDER 
FIVEPOINTSTENCIL 
THREEPOINTSKEWEDSTENCIL 

Definition at line 45 of file PidController1D.h.

Constructor & Destructor Documentation

◆ PidController1D()

agxModel::PidController1D::PidController1D ( )

Member Function Documentation

◆ calculateCostFunctionValue()

agx::Real agxModel::PidController1D::calculateCostFunctionValue ( agx::Real  deltaTime) const

This will calculate the cost function value between the last time update() was called and last time minus deltaTime so that (t - t0) = deltaTime, where t is the last time update() was called.

Note that the cost function history is not infinite and is truncated at 1000 time steps.

Returns
The cost function value, 1 / (t - t0) * Int( e(tau )^2 dtau, t0..t)
Parameters
deltaTimeThis will determine t0 so that t0 = t - deltaTime, where t is the last time update() was called.

◆ disablePidController()

void agxModel::PidController1D::disablePidController ( )

Disable the PID controller. The Manipulated Value will be zero.

◆ enablePidController()

void agxModel::PidController1D::enablePidController ( )

Enable the PID controller.

◆ getDerivativeGain()

agx::Real agxModel::PidController1D::getDerivativeGain ( ) const
Returns
The derivative gain, K_d

◆ getDerivativeTerm()

agx::Real agxModel::PidController1D::getDerivativeTerm ( ) const
Returns
The current derivative term, K_d * de(t)/dt * f, where f is the defined PID frequency

◆ getDerivativeTime()

agx::Real agxModel::PidController1D::getDerivativeTime ( )
Returns
the derivative time defined as T_d = K_d / K_p. If the proportional gain is zero the agx::RealMax is returned.

◆ getError()

agx::Real agxModel::PidController1D::getError ( ) const
Returns
The error between the Process Variable and the Set Point, e = SP - PV

◆ getFrequency()

agx::Real agxModel::PidController1D::getFrequency ( ) const
Returns
PID frequency for gain compensation of the derivative and integral term

◆ getGains()

agx::Vec3 agxModel::PidController1D::getGains ( ) const
Returns
The gains stored in a vector, where x is proportional gain K_p, y is integral gain K_i and z is derivative gain K_d

◆ getIntegralGain()

agx::Real agxModel::PidController1D::getIntegralGain ( ) const
Returns
The integral gain, K_i

◆ getIntegralTime()

agx::Real agxModel::PidController1D::getIntegralTime ( )
Returns
the integral time defined as T_i = K_p / K_i. If K_i is zero then agx::RealMax is returned.

◆ getIntegralWindupClamping()

const agx::Vec2& agxModel::PidController1D::getIntegralWindupClamping ( ) const
Returns
the value of the upper and lower limit of the integral gain term. First value in the vector is the lower limit and the second value in the vector is the upper limit.

◆ getIntegraTerm()

agx::Real agxModel::PidController1D::getIntegraTerm ( ) const
Returns
The current integral term, K_i * Int( e(tau ) dtau, 0..t) * f, where f is the defined PID frequency

◆ getManipulatedVariable()

virtual agx::Real agxModel::PidController1D::getManipulatedVariable ( ) const
overridevirtual
Returns
The Manipulated Variable (MV), or the output signal, from the PID controller. The Manipulated Variable is calculated in the last call to update(). If no call to update is done then 0 is returned.

Reimplemented from agxModel::Controller1D.

◆ getManipulatedVariableAccelerationLimit()

const agx::Vec2& agxModel::PidController1D::getManipulatedVariableAccelerationLimit ( ) const
Returns
The upper and lower limit of the Manipulated Variable acceleration limitation. First value in the returned vector is the lower limit and the second value in the vector is the upper limit.

◆ getManipulatedVariableLimit()

const agx::Vec2& agxModel::PidController1D::getManipulatedVariableLimit ( ) const
Returns
The upper and lower limit of the Manipulated Variable. First value in the returned vector is the lower limit and the second value in the vector is the upper limit.

◆ getMeasuredProcessVariable()

agx::Real agxModel::PidController1D::getMeasuredProcessVariable ( ) const
Returns
The current value of the measured Process Variable as given in the call to update.

◆ getProportionalGain()

agx::Real agxModel::PidController1D::getProportionalGain ( ) const
Returns
The proportional gain, K_p

◆ getProportionalTerm()

agx::Real agxModel::PidController1D::getProportionalTerm ( ) const
Returns
The current proportional term, K_p * e(t)

◆ getSetPoint()

virtual agx::Real agxModel::PidController1D::getSetPoint ( ) const
overridevirtual
Returns
The current Set Point for the controller

Reimplemented from agxModel::Controller1D.

◆ hasEnabledIntegralWindupProtection()

bool agxModel::PidController1D::hasEnabledIntegralWindupProtection ( ) const

◆ isEnabled()

bool agxModel::PidController1D::isEnabled ( )
Returns
return true if the PID controller is enabled. Default is true.

◆ reset()

virtual void agxModel::PidController1D::reset ( )
overridevirtual

Reset calculated gain, error, and cost to 0.

Note that this will keep the Set Point and Manipulated Variable as it is. The PID controller keeps track of the simulation time and this simulation time will not be reset to 0 when this method is called.

Reimplemented from agxModel::Controller1D.

◆ setDerivationMethod()

void agxModel::PidController1D::setDerivationMethod ( Derivative *  derivationMethod)

Change the derivation method. Default is the first order numerical derivation method.

◆ setDerivationType()

void agxModel::PidController1D::setDerivationType ( DerivationMethod  derivationMethod)

Change the derivation method. Default is the first order numerical derivation method DerivationMethod::FirstOrder.

◆ setDerivativeGain()

void agxModel::PidController1D::setDerivativeGain ( agx::Real  derivativeGain)

Set the derivative gain, K_d.

◆ setDerivativeTime()

void agxModel::PidController1D::setDerivativeTime ( agx::Real  derivativeTime)

Set the derivative time defined as T_d = K_d / K_p.

This will update the derivative gain, K_d. If the proportional gain is zero then K_d will be set to zero as well regardless of the value of the derivativeTime. If the derivative time is zero the derivative gain is set to zero.

◆ setFrequency()

void agxModel::PidController1D::setFrequency ( agx::Real  frequency)

Set PID frequency for gain compensation of the derivative and integral term, default values is 1.

◆ setGains()

void agxModel::PidController1D::setGains ( agx::Real  proportionalGain,
agx::Real  integralGain,
agx::Real  derivativeGain 
)

Set the gains.

◆ setIntegralGain()

void agxModel::PidController1D::setIntegralGain ( agx::Real  integralGain)

Set the integral gain, K_i.

◆ setIntegralTime()

void agxModel::PidController1D::setIntegralTime ( agx::Real  integralTime)

Set the integral time defined as T_i = K_p / K_i.

This call will update the integral gain coefficient, K_i. If T_i is set to agx::Real::maxval then K_i is set to 0. If T_i is set to 0 then K_i is set to agx::RealMax If the proportional gain coefficient is zero then K_i will be set to zero as well regardless of the value of the integralTime.

◆ setIntegralWindupClamping()

void agxModel::PidController1D::setIntegralWindupClamping ( agx::Real  lowerLimitIntegralTerm,
agx::Real  upperLimitIntegralTerm 
)

Set the lower and upper limit of the integral gain term, getIntegraTerm().

◆ setIntegralWindupProtection()

void agxModel::PidController1D::setIntegralWindupProtection ( bool  doIntegralWindupProtection)

Enable or disable the integral windup backward calculation.

Note that the anti windup algorithm is on by default. If this is disabled then the integral gain will not be limited when the Manipulated Variable is outside its limits defined by getManipulatedVariableLimit(), and by that cause an integral windup. The backward calculation is done by recomputing the integral term to its previous state before the windup started and by that disabling the integration.

◆ setManipulatedVariableAccelerationLimit()

void agxModel::PidController1D::setManipulatedVariableAccelerationLimit ( agx::Real  lowerLimit,
agx::Real  upperLimit 
)

Limit the Manipulated Variable acceleration dMV/dt between this lower and upper limit. Default limits are +/- agx::Real max value.

◆ setManipulatedVariableLimit()

void agxModel::PidController1D::setManipulatedVariableLimit ( agx::Real  lowerLimit,
agx::Real  upperLimit 
)

Limit the Manipulated Variable between this lower and upper limit. Default limits are +/- agx::Real max value.

◆ setProportionalGain()

void agxModel::PidController1D::setProportionalGain ( agx::Real  proportionalGain)

Set the proportional gain, K_p.

◆ setSetPoint()

virtual void agxModel::PidController1D::setSetPoint ( agx::Real  setPoint)
overridevirtual

Set the current Set Point for the controller.

Reimplemented from agxModel::Controller1D.

◆ update()

virtual void agxModel::PidController1D::update ( const agx::TimeStamp &  time,
agx::Real  measuredProcessVariable 
)
overridevirtual

Update the measured Process Variable and calculate a new value for the Manipulated Variable.

Calculate the function u(t) = K_p * e(t) + K_i * Int( e(tau ) dtau, 0..t) + K_d * de(t)/dt, where e is the error between the measured Process Variable and the Set Point

Parameters
measuredProcessVariableThe Plant measured Process Variable, PV in a Control System

Reimplemented from agxModel::Controller1D.


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