Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of AutomationElements by
PT1.cpp@2:a45cbb512c99, 2017-11-25 (annotated)
- Committer:
- tgw
- Date:
- Sat Nov 25 02:03:00 2017 +0000
- Revision:
- 2:a45cbb512c99
- Parent:
- 0:3dd7aeceee65
test
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| tbjazic | 0:3dd7aeceee65 | 1 | #include "PT1.h" |
| tbjazic | 0:3dd7aeceee65 | 2 | |
| tbjazic | 0:3dd7aeceee65 | 3 | PT1::PT1() { |
| tbjazic | 0:3dd7aeceee65 | 4 | u = y = u_p1 = y_p1 = 0; |
| tbjazic | 0:3dd7aeceee65 | 5 | setParameters(1, 1, 0.1); |
| tbjazic | 0:3dd7aeceee65 | 6 | } |
| tbjazic | 0:3dd7aeceee65 | 7 | |
| tbjazic | 0:3dd7aeceee65 | 8 | PT1::PT1(double K_, double T_1_, double T_d_) { |
| tbjazic | 0:3dd7aeceee65 | 9 | u = y = u_p1 = y_p1 = 0; |
| tbjazic | 0:3dd7aeceee65 | 10 | setParameters(K_, T_1_, T_d_); |
| tbjazic | 0:3dd7aeceee65 | 11 | } |
| tbjazic | 0:3dd7aeceee65 | 12 | |
| tbjazic | 0:3dd7aeceee65 | 13 | void PT1::setParameters(double K_, double T_1_, double T_d_) { |
| tbjazic | 0:3dd7aeceee65 | 14 | if (T_d_ > 0) |
| tbjazic | 0:3dd7aeceee65 | 15 | T_d = T_d_; |
| tbjazic | 0:3dd7aeceee65 | 16 | else |
| tbjazic | 0:3dd7aeceee65 | 17 | T_d = 0.1; |
| tbjazic | 0:3dd7aeceee65 | 18 | K = K_; |
| tbjazic | 0:3dd7aeceee65 | 19 | T_1 = T_1_; |
| tbjazic | 0:3dd7aeceee65 | 20 | a_1 = -exp(-T_d/T_1); |
| tbjazic | 0:3dd7aeceee65 | 21 | b_1 = K * (1 + a_1); |
| tbjazic | 0:3dd7aeceee65 | 22 | } |
| tbjazic | 0:3dd7aeceee65 | 23 | |
| tbjazic | 0:3dd7aeceee65 | 24 | double PT1::out() { |
| tbjazic | 0:3dd7aeceee65 | 25 | y = -a_1 * y_p1 + b_1 * u_p1; |
| tbjazic | 0:3dd7aeceee65 | 26 | y_p1 = y; |
| tbjazic | 0:3dd7aeceee65 | 27 | u_p1 = u; |
| tbjazic | 0:3dd7aeceee65 | 28 | return y; |
| tbjazic | 0:3dd7aeceee65 | 29 | } |
| tbjazic | 0:3dd7aeceee65 | 30 | |
| tbjazic | 0:3dd7aeceee65 | 31 | void PT1::in(double u_) { |
| tbjazic | 0:3dd7aeceee65 | 32 | u = u_; |
| tbjazic | 0:3dd7aeceee65 | 33 | } |
