68 constexpr void kp(
const T&
kp){this->kp_ =
kp;}
73 [[nodiscard]]
constexpr const T&
kp()
const {
return this->kp_;}
80 constexpr T
input(
const T& u) {
return u * this->kp_;}
88 constexpr T
input(
const T& u, [[maybe_unused]]
const T& Ts) {
return this->
input(u);}
103 constexpr T
operator() (
const T& u, [[maybe_unused]]
const T& Ts) {
return this->
input(u);}
156 T u_k1_ =
static_cast<T
>(0);
157 T y_k1_ =
static_cast<T
>(0);
172 constexpr void set_param(
const T& ki) {
return this->ki_ = ki;}
180 this->u_k1_ =
static_cast<T
>(0);
181 this->y_k1_ =
static_cast<T
>(0);
189 constexpr T
input(
const T& u,
const T& Ts){
190 const T y = this->ki_ * Ts / 2 * (u + this->u_k1_) + this->y_k1_;
271 T u_k1_ =
static_cast<T
>(0);
272 T y_k1_ =
static_cast<T
>(0);
284 constexpr IAntiWindup(
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())
297 constexpr void set_param(
const T& ki) {
return this->ki_ = ki;}
304 [[nodiscard]]
constexpr const T&
prate_limit()
const {
return this->vp_;}
311 [[nodiscard]]
constexpr const T&
nrate_limit()
const {
return this->vn_;}
315 constexpr void max_limit(
const T& max) {
return this->max_ = max;}
318 [[nodiscard]]
constexpr const T&
max_limit()
const {
return this->max_;}
322 constexpr void min_limit(
const T& min) {
return this->min_ = min;}
325 [[nodiscard]]
constexpr const T&
min_limit()
const {
return this->min_;}
336 this->u_k1_ =
static_cast<T
>(0);
337 this->y_k1_ =
static_cast<T
>(0);
345 constexpr T
input(
const T& u,
const T& Ts){
346 const T v = std::clamp(this->ki_ / 2 * (u + this->u_k1_), this->vn_, this->vp_);
348 const T y = std::clamp(dy + this->y_k1_, this->min_, this->max_);
413 T x_ =
static_cast<T
>(0);
429 constexpr T
input(
const T& u,
const T& Ts){
430 const T V = 2 * kd_ * omega_;
435 const T omega_Ts = omega_ * Ts;
436 const T a0 = omega_Ts + 2;
437 const T a1 = omega_Ts - 2;
439 const T b0_ = b0 / a0;
440 const T b1_ = b1 / a0;
442 const T a1_ = a1 / a0;
445 const T C = b1_ - a1_ * b0_;
448 const T new_x = A * x_ + u;
449 const T y = C * x_ + D * u;
462 this->x_ =
static_cast<T
>(0);
503 T _K =
static_cast<T
>(1);
504 T _omega =
static_cast<T
>(1);
505 T _x =
static_cast<T
>(0);
522 [[nodiscard]]
constexpr const T&
gain()
const {
return this->_K;}
525 [[nodiscard]]
constexpr const T&
omega()
const {
return this->_omega;}
527 constexpr T
input(
const T& u,
const T& Ts){
529 const T p = (Ts * this->_omega + 2);
530 const T n = (Ts * this->_omega - 2);
535 const T b = this->_K * Ts * this->_omega / p;
538 const T new_x = (-a) * this->_x + u;
539 const T new_y = b * ((1 - a) * this->_x + u);
553 this->_x =
static_cast<T
>(0);
604 Eigen::Vector<T, 2> x_ = Eigen::Vector<T, 2>::Zero();
620 constexpr T
input(
const T& u,
const T& Ts){
622 const T b0 =
static_cast<T
>(1);
623 const T b1 =
static_cast<T
>(2);
624 const T b2 =
static_cast<T
>(1);
626 const T omega_Ts_sqr = this->omega_ * this->omega_ * Ts * Ts;
627 const T _4_DomegaTs = 4 * this->D_ * this->omega_ * Ts;
629 const T V = this->K_ * omega_Ts_sqr;
630 const T a0 = omega_Ts_sqr + _4_DomegaTs + 4;
631 const T a1 = 2 * omega_Ts_sqr - 8;
632 const T a2 = omega_Ts_sqr - _4_DomegaTs + 4;
634 const T b0_ = b0 / a0;
635 const T b1_ = b1 / a0;
636 const T b2_ = b2 / a0;
638 const T a1_ = a1 / a0;
639 const T a2_ = a2 / a0;
642 Eigen::Matrix<T, 2, 2> A({
644 {
static_cast<T
>(1),
static_cast<T
>(0)}
647 const Eigen::Matrix<T, 2, 1> B({
652 const Eigen::Matrix<T, 1, 2> C({
653 (b1_ - a1_ * b0_), (b2_ - a2_ * b0_)
659 const Eigen::Vector<T, 2> new_x = A * this->x_ + B * u;
660 const T y = C * this->x_ + D * u;
734 constexpr T
input(
const T& u,
const T& Ts){
735 const T y = P_(u, Ts) + I_(u, Ts);
805 T y_k1_ =
static_cast<T
>(0);
816 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())
818 , I_(
ki, min, max, vn, vp)
832 [[nodiscard]]
constexpr const T&
kp()
const {
return this->P_.
kp();}
838 constexpr void ki(
const T&
ki){this->I_.ki(
ki);}
843 [[nodiscard]]
constexpr const T&
ki()
const {
return this->I_.ki_();}
879 constexpr T
input(
const T& u,
const T& Ts){
882 T rate_raw = (y_raw - y_k1_)/Ts;
884 T y_rate_clamped = rate * Ts + y_k1_;
911 this->y_k1_ =
static_cast<T
>(0);
996 constexpr T
input(
const T& u,
const T& Ts){
998 const T result = PT1_(u, Ts) + I_(u, Ts);
1062 PIDControl(
const T& kp,
const T& ki,
const T& kd,
const T& omega)
1085 const T kp = 1 / (mag_G * alpha);
1086 const T ki = omega_c / (mag_G * alpha * alpha * alpha);
1087 const T kd = 1 / (omega_c * mag_G);
1088 const T omega = omega_c * alpha;
1099 constexpr T
input(
const T& u,
const T& Ts){
1100 const T result = P_(u, Ts) + I_(u, Ts) + D_(u, Ts);
1158 T x_ =
static_cast<T
>(0);
1166 constexpr T
input(
const T& u,
const T& Ts){
1167 const T V = this->omega2_ / this->omega1_;
1169 const T b0 = Ts * this->omega1_ +
static_cast<T
>(2);
1170 const T b1 = Ts * this->omega1_ -
static_cast<T
>(2);
1172 const T a0 = Ts * this->omega2_ +
static_cast<T
>(2);
1173 const T a1 = Ts * this->omega2_ -
static_cast<T
>(2);
1175 const T b0_ = b0 / a0;
1176 const T b1_ = b1 / a0;
1178 const T a1_ = a1 / a0;
1181 const T C = b1_ - a1_ * b0_;
1184 const T new_x = A * x_ + u;
1185 const T y = C * x_ + D * u;
1197 constexpr void reset(){this->x_ =
static_cast<T
>(0);}
1222 Eigen::Vector<T, 2> x_ = Eigen::Vector<T, 2>::Zero();
1239 constexpr T
input(
const T& u,
const T& Ts){
1240 const T Ts_omega_sqr = Ts * Ts * this->omega_ * this->omega_;
1241 const T Ts_omega_sqr_plus_4 = Ts_omega_sqr + 4;
1242 const T _4_Ts_w_omega = 4 * Ts * this->w_ * this->omega_;
1243 const T _4_Ts_w_omega_g = _4_Ts_w_omega * this->g_min_;
1245 const T b0 = Ts_omega_sqr_plus_4 + _4_Ts_w_omega_g;
1246 const T b1 = 2 * (Ts_omega_sqr - 4);
1247 const T b2 = Ts_omega_sqr_plus_4 - _4_Ts_w_omega_g;
1249 const T a0 = Ts_omega_sqr_plus_4 + _4_Ts_w_omega;
1251 const T a2 = Ts_omega_sqr_plus_4 - _4_Ts_w_omega;
1253 const T b0_ = b0 / a0;
1254 const T b1_ = b1 / a0;
1255 const T b2_ = b2 / a0;
1257 const T a1_ = a1 / a0;
1258 const T a2_ = a2 / a0;
1261 Eigen::Matrix<T, 2, 2> A({
1263 {
static_cast<T
>(1),
static_cast<T
>(0)}
1266 const Eigen::Matrix<T, 2, 1> B({
1271 const Eigen::Matrix<T, 1, 2> C({
1272 (b1_ - a1_ * b0_), (b2_ - a2_ * b0_)
1278 const Eigen::Vector<T, 2> new_x = A * this->x_ + B * u;
1279 const T y = C * this->x_ + D * u;
A D (differntial) controller, with varying smaple-time.
Definition TimeVariantControl.hpp:409
constexpr void reset()
Definition TimeVariantControl.hpp:461
constexpr T input(const T &u, const T &Ts)
Definition TimeVariantControl.hpp:429
constexpr DControl(const DControl &)=default
default copy constructor
constexpr DControl(const T &kd, const T &omega)
Construct a D control element.
Definition TimeVariantControl.hpp:422
friend constexpr ValueSampletimePair< T > operator>>(const ValueSampletimePair< T > &p, DControl &c)
Definition TimeVariantControl.hpp:457
constexpr T operator()(const T &u, const T &Ts)
Definition TimeVariantControl.hpp:455
An I (integrating) controller with anti windup protection (rate and value limits),...
Definition TimeVariantControl.hpp:261
friend constexpr ValueSampletimePair< T > operator>>(const ValueSampletimePair< T > &p, IAntiWindup &c)
Definition TimeVariantControl.hpp:363
constexpr IAntiWindup(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 an I (Integrator) controller with anti-windup controller.
Definition TimeVariantControl.hpp:284
constexpr const T & min_limit() const
returns the minimal value limit
Definition TimeVariantControl.hpp:325
constexpr const T & prate_limit() const
returns the positive rate limit
Definition TimeVariantControl.hpp:304
constexpr T input(const T &u, const T &Ts)
Adds a new value input and sample time to calculate the next output.
Definition TimeVariantControl.hpp:345
constexpr const T & max_limit() const
returns the maximal value limit
Definition TimeVariantControl.hpp:318
constexpr IAntiWindup(const IAntiWindup &)=default
Default copy constructor.
constexpr void prate_limit(const T &pv)
Sets the positive rate limit of the I controller.
Definition TimeVariantControl.hpp:301
constexpr void nrate_limit(const T &nv)
Sets the negative rate limit of the I controller.
Definition TimeVariantControl.hpp:308
constexpr T operator()(const T &u, const T &Ts)
Adds a new value input and sample time to calculate the next output.
Definition TimeVariantControl.hpp:361
T value_type
Definition TimeVariantControl.hpp:263
constexpr void max_limit(const T &max)
Sets the maximal value limit.
Definition TimeVariantControl.hpp:315
constexpr void set_param(const T &ki)
Sets the integrator gain.
Definition TimeVariantControl.hpp:297
constexpr void min_limit(const T &min)
Sets the minimal value limit.
Definition TimeVariantControl.hpp:322
constexpr void reset()
resets (clears) the internal states
Definition TimeVariantControl.hpp:335
constexpr const T & nrate_limit() const
returns the negative rate limit
Definition TimeVariantControl.hpp:311
An I (Integrator) controller, with varying smaple-time.
Definition TimeVariantControl.hpp:151
constexpr void set_param(const T &ki)
Sets the integrator gain.
Definition TimeVariantControl.hpp:172
constexpr T input(const T &u, const T &Ts)
Adds a new value input and sample time to calculate the next output.
Definition TimeVariantControl.hpp:189
constexpr IControl(const IControl &)=default
Default copy constructor.
T value_type
Definition TimeVariantControl.hpp:153
constexpr IControl(const T &ki)
Constructs an I (Integrator) controller.
Definition TimeVariantControl.hpp:165
constexpr void reset()
resets (clears) the internal states
Definition TimeVariantControl.hpp:179
friend constexpr ValueSampletimePair< T > operator>>(const ValueSampletimePair< T > &p, IControl &c)
Definition TimeVariantControl.hpp:204
constexpr T operator()(const T &u, const T &Ts)
Adds a new value input and sample time to calculate the next output.
Definition TimeVariantControl.hpp:202
A Lead-Lag control element with varying sample-times.
Definition TimeVariantControl.hpp:1154
constexpr void reset()
Definition TimeVariantControl.hpp:1197
constexpr T operator()(const T &u, const T &Ts)
Definition TimeVariantControl.hpp:1191
constexpr LeadLagControl(const T &omega1, const T &omega2)
Definition TimeVariantControl.hpp:1162
friend constexpr ValueSampletimePair< T > operator>>(const ValueSampletimePair< T > &p, LeadLagControl &c)
Definition TimeVariantControl.hpp:1193
constexpr T input(const T &u, const T &Ts)
Definition TimeVariantControl.hpp:1166
A notch element with variable sample-time.
Definition TimeVariantControl.hpp:1217
constexpr T input(const T &u, const T &Ts)
Definition TimeVariantControl.hpp:1239
constexpr NotchControl(const T &w, const T &g_min, const T &omega)
Creates a notch filter.
Definition TimeVariantControl.hpp:1234
friend constexpr ValueSampletimePair< T > operator>>(const ValueSampletimePair< T > &p, NotchControl &c)
Definition TimeVariantControl.hpp:1288
constexpr T operator()(const T &u, const T &Ts)
Definition TimeVariantControl.hpp:1286
constexpr void reset()
Definition TimeVariantControl.hpp:1292
A P (Proportional) controller.
Definition TimeVariantControl.hpp:46
constexpr void reset()
resets the internal states of the filter
Definition TimeVariantControl.hpp:114
constexpr T input(const T &u, const T &Ts)
Adds a new sample.
Definition TimeVariantControl.hpp:88
constexpr T input(const T &u)
Adds a new sample.
Definition TimeVariantControl.hpp:80
friend constexpr ValueSampletimePair< T > operator>>(const ValueSampletimePair< T > &p, PControl &c)
Definition TimeVariantControl.hpp:105
constexpr PControl(const T &kp)
Construct a P (Proportional) controller with a constant gain.
Definition TimeVariantControl.hpp:62
constexpr void kp(const T &kp)
sets the proportional gain
Definition TimeVariantControl.hpp:68
constexpr PControl(const PControl &)=default
Default copy constructor.
constexpr T operator()(const T &u)
Adds a new sample.
Definition TimeVariantControl.hpp:95
T value_type
Definition TimeVariantControl.hpp:48
constexpr const T & kp() const
returns the current gain
Definition TimeVariantControl.hpp:73
A PI (Proportional Integral) controller with varying sample-times.
Definition TimeVariantControl.hpp:800
constexpr T operator()(const T &u, const T &Ts)
Input a new sample to the controller.
Definition TimeVariantControl.hpp:899
constexpr void ki(const T &ki)
sets the integral gain
Definition TimeVariantControl.hpp:838
friend constexpr ValueSampletimePair< T > operator>>(const ValueSampletimePair< T > &p, PIAntiWindup &c)
Definition TimeVariantControl.hpp:901
constexpr const T & min_limit() const
returns the minimal value limit
Definition TimeVariantControl.hpp:871
constexpr void min_limit(const T &min)
Sets the minimal value limit.
Definition TimeVariantControl.hpp:868
constexpr void prate_limit(const T &pv)
Sets the positive rate limit of the I controller.
Definition TimeVariantControl.hpp:847
constexpr const T & kp() const
returns the current gain
Definition TimeVariantControl.hpp:832
constexpr const T & prate_limit() const
returns the positive rate limit
Definition TimeVariantControl.hpp:850
constexpr T input(const T &u, const T &Ts)
Input a new sample to the controller.
Definition TimeVariantControl.hpp:879
constexpr const T & nrate_limit() const
returns the negative rate limit
Definition TimeVariantControl.hpp:857
constexpr void reset()
resets (clears) the internal states resets the internal states ( , ) to zero
Definition TimeVariantControl.hpp:909
PIAntiWindup(const PIAntiWindup &)=default
constexpr const T & ki() const
returns the current gain
Definition TimeVariantControl.hpp:843
constexpr void max_limit(const T &max)
Sets the maximal value limit.
Definition TimeVariantControl.hpp:861
constexpr const T & max_limit() const
returns the maximal value limit
Definition TimeVariantControl.hpp:864
constexpr void kp(const T &kp)
sets the proportional gain
Definition TimeVariantControl.hpp:827
constexpr void nrate_limit(const T &nv)
Sets the negative rate limit of the I controller.
Definition TimeVariantControl.hpp:854
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.
Definition TimeVariantControl.hpp:816
A PI (Proportional Integral) controller with varying sample-times.
Definition TimeVariantControl.hpp:717
friend constexpr ValueSampletimePair< T > operator>>(const ValueSampletimePair< T > &p, PIControl &c)
Definition TimeVariantControl.hpp:741
PIControl(const PIControl &)=default
constexpr T input(const T &u, const T &Ts)
Definition TimeVariantControl.hpp:734
PIControl(const T &kp, const T &ki)
Definition TimeVariantControl.hpp:728
constexpr void reset()
Definition TimeVariantControl.hpp:745
constexpr T operator()(const T &u, const T &Ts)
Definition TimeVariantControl.hpp:739
Definition TimeVariantControl.hpp:1125
A PID (proportional + integral + differential) controller with variable sample-times.
Definition TimeVariantControl.hpp:1047
constexpr T operator()(const T &u, const T &Ts)
resets (clears) the internal states resets the internal states ( , , and ) to zero
Definition TimeVariantControl.hpp:1108
constexpr T input(const T &u, const T &Ts)
Input a new sample to the controller.
Definition TimeVariantControl.hpp:1099
constexpr void reset()
resets (clears) the internal states resets the internal states ( , , and ) to zero
Definition TimeVariantControl.hpp:1118
PIDControl(const T &kp, const T &ki, const T &kd, const T &omega)
constructs a PID controller form gain parameters
Definition TimeVariantControl.hpp:1062
static PIDControl from_alpha_tune(const T &alpha, const T &omega_c, const T &mag_G)
Constructa a PID controller using the alpha tuning method.
Definition TimeVariantControl.hpp:1084
friend constexpr ValueSampletimePair< T > operator>>(const ValueSampletimePair< T > &p, PIDControl &c)
Definition TimeVariantControl.hpp:1110
A PT1 (proportional time first order) filter (=low-pass element of order 1), with varying smaple-time...
Definition TimeVariantControl.hpp:501
friend constexpr ValueSampletimePair< T > operator>>(const ValueSampletimePair< T > &p, PT1Control &c)
Definition TimeVariantControl.hpp:548
constexpr PT1Control(const T &K, const T &omega)
Constructs a low-pass filter.
Definition TimeVariantControl.hpp:514
constexpr void reset()
Definition TimeVariantControl.hpp:552
constexpr void set_omega(const T &w)
Definition TimeVariantControl.hpp:524
constexpr void set_gain(const T &g)
Definition TimeVariantControl.hpp:521
constexpr const T & gain() const
Definition TimeVariantControl.hpp:522
constexpr T operator()(const T &u, const T &Ts)
Definition TimeVariantControl.hpp:546
constexpr const T & omega() const
Definition TimeVariantControl.hpp:525
constexpr PT1Control(const PT1Control &)=default
Default copy constructor.
constexpr T input(const T &u, const T &Ts)
Definition TimeVariantControl.hpp:527
A Thamed PI controller (PI controller with a low pass filter) with variable sample-times.
Definition TimeVariantControl.hpp:969
constexpr PT1IControl(const T &kp, const T &ki, const T &omega)
Constructs a PT1I (proportional time delayed + integral) controller.
Definition TimeVariantControl.hpp:985
constexpr void reset()
resets (clears) the internal states resets the internal states ( , , and ) to zero
Definition TimeVariantControl.hpp:1018
constexpr T input(const T &u, const T &Ts)
Input a new sample to the controller.
Definition TimeVariantControl.hpp:996
constexpr PT1IControl(const PT1IControl &)=default
constexpr T operator()(const T &u, const T &Ts)
Input a new sample to the controller.
Definition TimeVariantControl.hpp:1008
friend constexpr ValueSampletimePair< T > operator>>(const ValueSampletimePair< T > &p, PT1IControl &c)
Definition TimeVariantControl.hpp:1010
A PT2 (proportional time second order) filter (=low-pass element of order 1), with varying smaple-tim...
Definition TimeVariantControl.hpp:599
constexpr T operator()(const T &u, const T &Ts)
Definition TimeVariantControl.hpp:667
PT2Control(const PT2Control &)=default
constexpr void reset()
Definition TimeVariantControl.hpp:673
friend constexpr ValueSampletimePair< T > operator>>(const ValueSampletimePair< T > &p, PT2Control &c)
Definition TimeVariantControl.hpp:669
constexpr T input(const T &u, const T &Ts)
Definition TimeVariantControl.hpp:620
PT2Control(const T &K, const T &D, const T &omega)
constructs a PT2 element
Definition TimeVariantControl.hpp:615
The main namespace for the Control++ library.
Definition Bode.cpp:3
Definition TimeVariantControl.hpp:23
T value
Definition TimeVariantControl.hpp:24
T sample_time
Definition TimeVariantControl.hpp:25