Controlpp
Loading...
Searching...
No Matches
controlpp::timevar::PIAntiWindup< T > Class Template Reference

A PI (Proportional Integral) controller with varying sample-times. More...

#include <controlpp/TimeVariantControl.hpp>

Public Member Functions

 PIAntiWindup (const T &kp, const T &ki, const T &min, const T &max, const T &vn=std::numeric_limits< T >::lowest(), const T &vp=std::numeric_limits< T >::max())
 Constructs a PI (proportional + integral) controller with anti-windup.
 
 PIAntiWindup (const PIAntiWindup &)=default
 
constexpr void kp (const T &kp)
 sets the proportional gain
 
constexpr const T & kp () const
 returns the current gain
 
constexpr void ki (const T &ki)
 sets the integral gain
 
constexpr const T & ki () const
 returns the current gain
 
constexpr void prate_limit (const T &pv)
 Sets the positive rate limit of the I controller.
 
constexpr const T & prate_limit () const
 returns the positive rate limit
 
constexpr void nrate_limit (const T &nv)
 Sets the negative rate limit of the I controller.
 
constexpr const T & nrate_limit () const
 returns the negative rate limit
 
constexpr void max_limit (const T &max)
 Sets the maximal value limit.
 
constexpr const T & max_limit () const
 returns the maximal value limit
 
constexpr void min_limit (const T &min)
 Sets the minimal value limit.
 
constexpr const T & min_limit () const
 returns the minimal value limit
 
constexpr T input (const T &u, const T &Ts)
 Input a new sample to the controller.
 
constexpr T operator() (const T &u, const T &Ts)
 Input a new sample to the controller.
 
constexpr void reset ()
 resets (clears) the internal states resets the internal states ( \(u_{k-1}\), \(y_{k-1}\)) to zero
 

Friends

constexpr ValueSampletimePair< T > operator>> (const ValueSampletimePair< T > &p, PIAntiWindup &c)
 

Detailed Description

template<class T>
class controlpp::timevar::PIAntiWindup< T >

A PI (Proportional Integral) controller with varying sample-times.

Anti-windup prevents the controller’s integrator from accumulating excessive error when the actuator cannot keep up with the commanded output. Without anti-windup protection, the integrator continues to grow—even though the actuator is saturated and unable to reflect these changes—resulting in increasingly unrealistic control signals. Once the system reaches its target, the controller must then "unwind" or de-integrate the surplus error, which leads to a delayed response and potential overshoot. Anti-windup mitigates this by limiting or adjusting the integrator during saturation, improving stability and responsiveness.

Has the transfer function:

\[ \text{PI} = k_p + \frac{k_i}{s} \]

and the discretisation using the tustin transformation:

\[ s = \frac{2}{T_s} \frac{1 - z^{-1}}{1 + z^{-1}} \]

resulting in the controlers time series:

\[ y_k = \begin{cases} \if y_k > max \text{ then } max \\ \if y_k < min \text{ then } max \\ \if \frac{y_k - y_{k-1}}{Ts} > v_p \text{ then } v_p * Ts \\ \if \frac{y_k - y_{k-1}}{Ts} < v_n \text{ then } v_n * Ts \\ \text{else } \left( \frac{k_i T}{2} + k_p \right) u_k + \left( \frac{k_i T}{2} - k_p \right) u_{k-1} + y_{k-1} \end{cases} \]

with:

  • \(T_s\) the sample-time in seconds
  • \(u_{k}\) and \(u_{k-1}\) are current and previous control inputs
  • \(y_{k}\) and \(y_{k-1}\) are current and previous control outputs
See also
controlpp::vartime::PI
Template Parameters
TValue type of the filter like float or double

Constructor & Destructor Documentation

◆ PIAntiWindup() [1/2]

template<class T >
controlpp::timevar::PIAntiWindup< T >::PIAntiWindup ( const T &  kp,
const T &  ki,
const T &  min,
const T &  max,
const T &  vn = std::numeric_limits<T>::lowest(),
const T &  vp = std::numeric_limits<T>::max() 
)
inline

Constructs a PI (proportional + integral) controller with anti-windup.

Parameters
kpThe proportional gain
kiThe integral gain.
vnThe minimal negative velocity of the control output. Assumes: \(v_n < 0 < v_p\)
vpThe maximal positive velocity of the control output. Assumes: \(v_n < 0 < v_p\)
minThe minimal value of the control output. Assumes: \(min < max\)
maxThe maximal value of the control output. Assumes: \(min < max\)

◆ PIAntiWindup() [2/2]

template<class T >
controlpp::timevar::PIAntiWindup< T >::PIAntiWindup ( const PIAntiWindup< T > &  )
default

Member Function Documentation

◆ input()

template<class T >
constexpr T controlpp::timevar::PIAntiWindup< T >::input ( const T &  u,
const T &  Ts 
)
inlineconstexpr

Input a new sample to the controller.

Parameters
uThe control input
TsThe sample-time
See also
operator()(const T& u, const T& Ts)

◆ ki() [1/2]

template<class T >
constexpr const T & controlpp::timevar::PIAntiWindup< T >::ki ( ) const
inlineconstexpr

returns the current gain

◆ ki() [2/2]

template<class T >
constexpr void controlpp::timevar::PIAntiWindup< T >::ki ( const T &  ki)
inlineconstexpr

sets the integral gain

Parameters
kithe new proportional gain for the next sample value

◆ kp() [1/2]

template<class T >
constexpr const T & controlpp::timevar::PIAntiWindup< T >::kp ( ) const
inlineconstexpr

returns the current gain

◆ kp() [2/2]

template<class T >
constexpr void controlpp::timevar::PIAntiWindup< T >::kp ( const T &  kp)
inlineconstexpr

sets the proportional gain

Parameters
kpthe new proportional gain for the next sample value

◆ max_limit() [1/2]

template<class T >
constexpr const T & controlpp::timevar::PIAntiWindup< T >::max_limit ( ) const
inlineconstexpr

returns the maximal value limit

◆ max_limit() [2/2]

template<class T >
constexpr void controlpp::timevar::PIAntiWindup< T >::max_limit ( const T &  max)
inlineconstexpr

Sets the maximal value limit.

Parameters
maxThe new maximal value limit

◆ min_limit() [1/2]

template<class T >
constexpr const T & controlpp::timevar::PIAntiWindup< T >::min_limit ( ) const
inlineconstexpr

returns the minimal value limit

◆ min_limit() [2/2]

template<class T >
constexpr void controlpp::timevar::PIAntiWindup< T >::min_limit ( const T &  min)
inlineconstexpr

Sets the minimal value limit.

Parameters
minThe new minimal value limit

◆ nrate_limit() [1/2]

template<class T >
constexpr const T & controlpp::timevar::PIAntiWindup< T >::nrate_limit ( ) const
inlineconstexpr

returns the negative rate limit

◆ nrate_limit() [2/2]

template<class T >
constexpr void controlpp::timevar::PIAntiWindup< T >::nrate_limit ( const T &  nv)
inlineconstexpr

Sets the negative rate limit of the I controller.

Parameters
nvThe new negative rate limit

◆ operator()()

template<class T >
constexpr T controlpp::timevar::PIAntiWindup< T >::operator() ( const T &  u,
const T &  Ts 
)
inlineconstexpr

Input a new sample to the controller.

Parameters
uThe control input
TsThe sample-time
See also
input(const T& u, const T& Ts)

◆ prate_limit() [1/2]

template<class T >
constexpr const T & controlpp::timevar::PIAntiWindup< T >::prate_limit ( ) const
inlineconstexpr

returns the positive rate limit

◆ prate_limit() [2/2]

template<class T >
constexpr void controlpp::timevar::PIAntiWindup< T >::prate_limit ( const T &  pv)
inlineconstexpr

Sets the positive rate limit of the I controller.

Parameters
pvThe new positive rate limit

◆ reset()

template<class T >
constexpr void controlpp::timevar::PIAntiWindup< T >::reset ( )
inlineconstexpr

resets (clears) the internal states resets the internal states ( \(u_{k-1}\), \(y_{k-1}\)) to zero

Friends And Related Symbol Documentation

◆ operator>>

template<class T >
constexpr ValueSampletimePair< T > operator>> ( const ValueSampletimePair< T > &  p,
PIAntiWindup< T > &  c 
)
friend

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