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
PT2.h@0:3dd7aeceee65, 2015-01-22 (annotated)
- Committer:
- tbjazic
- Date:
- Thu Jan 22 11:41:02 2015 +0000
- Revision:
- 0:3dd7aeceee65
Initial commit.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tbjazic | 0:3dd7aeceee65 | 1 | #ifndef PT2_H |
tbjazic | 0:3dd7aeceee65 | 2 | #define PT2_H |
tbjazic | 0:3dd7aeceee65 | 3 | |
tbjazic | 0:3dd7aeceee65 | 4 | #include "mbed.h" |
tbjazic | 0:3dd7aeceee65 | 5 | |
tbjazic | 0:3dd7aeceee65 | 6 | /** Transfer function of a PT2 form. |
tbjazic | 0:3dd7aeceee65 | 7 | * G(s) = Y(s) / U(s) = K / ( (1 + T_1 s) * (1 + T_2 s) ) |
tbjazic | 0:3dd7aeceee65 | 8 | * |
tbjazic | 0:3dd7aeceee65 | 9 | * Author(s): TVZ Mechatronics Team |
tbjazic | 0:3dd7aeceee65 | 10 | * |
tbjazic | 0:3dd7aeceee65 | 11 | */ |
tbjazic | 0:3dd7aeceee65 | 12 | class PT2 { |
tbjazic | 0:3dd7aeceee65 | 13 | public: |
tbjazic | 0:3dd7aeceee65 | 14 | /** Default constructor. |
tbjazic | 0:3dd7aeceee65 | 15 | * K = 1, T_1 = 1 s, T_2 = 0.5 s, sampleTime = 0.1 s. |
tbjazic | 0:3dd7aeceee65 | 16 | */ |
tbjazic | 0:3dd7aeceee65 | 17 | PT2(); |
tbjazic | 0:3dd7aeceee65 | 18 | /** PT2 transfer function parameters and sample time in seconds. */ |
tbjazic | 0:3dd7aeceee65 | 19 | PT2(double K, double T_1, double T_2, double sampleTime); |
tbjazic | 0:3dd7aeceee65 | 20 | /** Update PT2 transfer function parameters and sample time. */ |
tbjazic | 0:3dd7aeceee65 | 21 | void setParameters(double K, double T_1, double T_2, double sampleTime); |
tbjazic | 0:3dd7aeceee65 | 22 | /** Calculate the output y. */ |
tbjazic | 0:3dd7aeceee65 | 23 | double out(); |
tbjazic | 0:3dd7aeceee65 | 24 | /** Set the input u. */ |
tbjazic | 0:3dd7aeceee65 | 25 | void in(double u); |
tbjazic | 0:3dd7aeceee65 | 26 | private: |
tbjazic | 0:3dd7aeceee65 | 27 | double K, T_1, T_2, T_d, a, b, c, d, a_1, a_2, b_1, b_2, y, y_p1, y_p2, u, u_p1, u_p2; |
tbjazic | 0:3dd7aeceee65 | 28 | }; |
tbjazic | 0:3dd7aeceee65 | 29 | |
tbjazic | 0:3dd7aeceee65 | 30 | #endif // PT2_H |