Library containing essential automation elements with parameters in continuous Laplace domain, and implemented with fixed sample time. This means that "out" member functions should be called using Ticker object.
Dependents: CurrentMeasurement Zavrsni_rad_NXP_cup HC-SR04 Nucleo_SSD1306_DS1302_ESP8266_AM2320_BME280 ... more
DT1.cpp@1:b9e11da0f2eb, 2015-01-22 (annotated)
- Committer:
- tbjazic
- Date:
- Thu Jan 22 12:44:37 2015 +0000
- Revision:
- 1:b9e11da0f2eb
- Parent:
- 0:3dd7aeceee65
Added header file "AutomationElements.h".
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tbjazic | 0:3dd7aeceee65 | 1 | #include "DT1.h" |
tbjazic | 0:3dd7aeceee65 | 2 | |
tbjazic | 0:3dd7aeceee65 | 3 | DT1::DT1() { |
tbjazic | 0:3dd7aeceee65 | 4 | u = y = u_p1 = y_p1 = 0; |
tbjazic | 0:3dd7aeceee65 | 5 | setParameters(1, 0.5, 0.1); |
tbjazic | 0:3dd7aeceee65 | 6 | } |
tbjazic | 0:3dd7aeceee65 | 7 | |
tbjazic | 0:3dd7aeceee65 | 8 | DT1::DT1(double T_1_, double T_D_, double T_d_) { |
tbjazic | 0:3dd7aeceee65 | 9 | u = y = u_p1 = y_p1 = 0; |
tbjazic | 0:3dd7aeceee65 | 10 | setParameters(T_1_, T_D_, T_d_); |
tbjazic | 0:3dd7aeceee65 | 11 | } |
tbjazic | 0:3dd7aeceee65 | 12 | |
tbjazic | 0:3dd7aeceee65 | 13 | void DT1::setParameters(double T_1_, double T_D_, double T_d_) { |
tbjazic | 0:3dd7aeceee65 | 14 | T_1 = T_1_; |
tbjazic | 0:3dd7aeceee65 | 15 | T_D = T_D_; |
tbjazic | 0:3dd7aeceee65 | 16 | if (T_d_ > 0) // only positive sample time values allowed |
tbjazic | 0:3dd7aeceee65 | 17 | T_d = T_d_; |
tbjazic | 0:3dd7aeceee65 | 18 | else |
tbjazic | 0:3dd7aeceee65 | 19 | T_d = 0.1; |
tbjazic | 0:3dd7aeceee65 | 20 | a_1 = -exp(-T_d/T_1); |
tbjazic | 0:3dd7aeceee65 | 21 | b_0 = T_D / T_1; |
tbjazic | 0:3dd7aeceee65 | 22 | b_1 = -b_0; |
tbjazic | 0:3dd7aeceee65 | 23 | } |
tbjazic | 0:3dd7aeceee65 | 24 | |
tbjazic | 0:3dd7aeceee65 | 25 | void DT1::in(double u_) { |
tbjazic | 0:3dd7aeceee65 | 26 | u = u_; |
tbjazic | 0:3dd7aeceee65 | 27 | } |
tbjazic | 0:3dd7aeceee65 | 28 | |
tbjazic | 0:3dd7aeceee65 | 29 | double DT1::out() { |
tbjazic | 0:3dd7aeceee65 | 30 | y = -a_1*y_p1 + b_0*u + b_1*u_p1; |
tbjazic | 0:3dd7aeceee65 | 31 | y_p1 = y; |
tbjazic | 0:3dd7aeceee65 | 32 | u_p1 = u; |
tbjazic | 0:3dd7aeceee65 | 33 | return y; |
tbjazic | 0:3dd7aeceee65 | 34 | } |