|
AGX Dynamics
2.37.3.2
|
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 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 |
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.
Definition at line 52 of file PidController1D.h.
| typedef agx::ref_ptr< const Derivative > agxModel::PidController1D::DerivativeConstRef |
Definition at line 52 of file PidController1D.h.
| typedef agx::observer_ptr< const DerivativeFivePointStencil > agxModel::PidController1D::DerivativeFivePointStencilConstObserver |
Definition at line 70 of file PidController1D.h.
| typedef agx::ref_ptr< const DerivativeFivePointStencil > agxModel::PidController1D::DerivativeFivePointStencilConstRef |
Definition at line 70 of file PidController1D.h.
| typedef agx::observer_ptr< DerivativeFivePointStencil > agxModel::PidController1D::DerivativeFivePointStencilObserver |
Definition at line 70 of file PidController1D.h.
| typedef agx::ref_ptr< DerivativeFivePointStencil > agxModel::PidController1D::DerivativeFivePointStencilRef |
Definition at line 70 of file PidController1D.h.
Definition at line 52 of file PidController1D.h.
Definition at line 52 of file PidController1D.h.
| typedef agx::observer_ptr< const DerivativeThreePointSkewdStencil > agxModel::PidController1D::DerivativeThreePointSkewdStencilConstObserver |
Definition at line 90 of file PidController1D.h.
| typedef agx::ref_ptr< const DerivativeThreePointSkewdStencil > agxModel::PidController1D::DerivativeThreePointSkewdStencilConstRef |
Definition at line 90 of file PidController1D.h.
| typedef agx::observer_ptr< DerivativeThreePointSkewdStencil > agxModel::PidController1D::DerivativeThreePointSkewdStencilObserver |
Definition at line 90 of file PidController1D.h.
| typedef agx::ref_ptr< DerivativeThreePointSkewdStencil > agxModel::PidController1D::DerivativeThreePointSkewdStencilRef |
Definition at line 90 of file PidController1D.h.
|
strong |
| Enumerator | |
|---|---|
| FIRSTORDER | |
| FIVEPOINTSTENCIL | |
| THREEPOINTSKEWEDSTENCIL | |
Definition at line 45 of file PidController1D.h.
| agxModel::PidController1D::PidController1D | ( | ) |
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.
| deltaTime | This will determine t0 so that t0 = t - deltaTime, where t is the last time update() was called. |
| void agxModel::PidController1D::disablePidController | ( | ) |
Disable the PID controller. The Manipulated Value will be zero.
| void agxModel::PidController1D::enablePidController | ( | ) |
Enable the PID controller.
| agx::Real agxModel::PidController1D::getDerivativeGain | ( | ) | const |
| agx::Real agxModel::PidController1D::getDerivativeTerm | ( | ) | const |
| agx::Real agxModel::PidController1D::getDerivativeTime | ( | ) |
| agx::Real agxModel::PidController1D::getError | ( | ) | const |
| agx::Real agxModel::PidController1D::getFrequency | ( | ) | const |
| agx::Vec3 agxModel::PidController1D::getGains | ( | ) | const |
| agx::Real agxModel::PidController1D::getIntegralGain | ( | ) | const |
| agx::Real agxModel::PidController1D::getIntegralTime | ( | ) |
| const agx::Vec2& agxModel::PidController1D::getIntegralWindupClamping | ( | ) | const |
| agx::Real agxModel::PidController1D::getIntegraTerm | ( | ) | const |
|
overridevirtual |
Reimplemented from agxModel::Controller1D.
| const agx::Vec2& agxModel::PidController1D::getManipulatedVariableAccelerationLimit | ( | ) | const |
| const agx::Vec2& agxModel::PidController1D::getManipulatedVariableLimit | ( | ) | const |
| agx::Real agxModel::PidController1D::getMeasuredProcessVariable | ( | ) | const |
| agx::Real agxModel::PidController1D::getProportionalGain | ( | ) | const |
| agx::Real agxModel::PidController1D::getProportionalTerm | ( | ) | const |
|
overridevirtual |
Reimplemented from agxModel::Controller1D.
| bool agxModel::PidController1D::hasEnabledIntegralWindupProtection | ( | ) | const |
| bool agxModel::PidController1D::isEnabled | ( | ) |
|
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.
| void agxModel::PidController1D::setDerivationMethod | ( | Derivative * | derivationMethod | ) |
Change the derivation method. Default is the first order numerical derivation method.
| void agxModel::PidController1D::setDerivationType | ( | DerivationMethod | derivationMethod | ) |
Change the derivation method. Default is the first order numerical derivation method DerivationMethod::FirstOrder.
| void agxModel::PidController1D::setDerivativeGain | ( | agx::Real | derivativeGain | ) |
Set the derivative gain, K_d.
| 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.
| void agxModel::PidController1D::setFrequency | ( | agx::Real | frequency | ) |
Set PID frequency for gain compensation of the derivative and integral term, default values is 1.
| void agxModel::PidController1D::setGains | ( | agx::Real | proportionalGain, |
| agx::Real | integralGain, | ||
| agx::Real | derivativeGain | ||
| ) |
Set the gains.
| void agxModel::PidController1D::setIntegralGain | ( | agx::Real | integralGain | ) |
Set the integral gain, K_i.
| 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.
| void agxModel::PidController1D::setIntegralWindupClamping | ( | agx::Real | lowerLimitIntegralTerm, |
| agx::Real | upperLimitIntegralTerm | ||
| ) |
Set the lower and upper limit of the integral gain term, getIntegraTerm().
| 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.
| 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.
| 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.
| void agxModel::PidController1D::setProportionalGain | ( | agx::Real | proportionalGain | ) |
Set the proportional gain, K_p.
|
overridevirtual |
Set the current Set Point for the controller.
Reimplemented from agxModel::Controller1D.
|
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
| measuredProcessVariable | The Plant measured Process Variable, PV in a Control System |
Reimplemented from agxModel::Controller1D.