test
Fork of AutomationElements by
PI.h@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 | #ifndef PI_H |
tbjazic | 0:3dd7aeceee65 | 2 | #define PI_H |
tbjazic | 0:3dd7aeceee65 | 3 | |
tbjazic | 0:3dd7aeceee65 | 4 | #include "mbed.h" |
tbjazic | 0:3dd7aeceee65 | 5 | |
tbjazic | 0:3dd7aeceee65 | 6 | /** Data type for choosing the operation mode of the controller ("automatic" or "manual"). */ |
tbjazic | 0:3dd7aeceee65 | 7 | enum Mode {automatic, manual}; |
tbjazic | 0:3dd7aeceee65 | 8 | |
tbjazic | 0:3dd7aeceee65 | 9 | /** Transfer function of a PI controller with output limitation, anti-windup and bumpless automatic and manual mode. |
tbjazic | 0:3dd7aeceee65 | 10 | * G_C(s) = U_C(s) / E(s) = K_C ( 1 + 1 / (T_I s) ) = K_C (1 + T_I s) / (T_I s) |
tbjazic | 0:3dd7aeceee65 | 11 | * |
tbjazic | 0:3dd7aeceee65 | 12 | * K_C is the controller gain, and T_I is the controller integral time constant in seconds. |
tbjazic | 0:3dd7aeceee65 | 13 | * |
tbjazic | 0:3dd7aeceee65 | 14 | * Author(s): TVZ Mechatronics Team |
tbjazic | 0:3dd7aeceee65 | 15 | * |
tbjazic | 0:3dd7aeceee65 | 16 | */ |
tbjazic | 0:3dd7aeceee65 | 17 | class PI { |
tbjazic | 0:3dd7aeceee65 | 18 | public: |
tbjazic | 0:3dd7aeceee65 | 19 | /** Default constructor. |
tbjazic | 0:3dd7aeceee65 | 20 | * K_C = 1, T_I = 1 s, sampleTime = 0.1 s. |
tbjazic | 0:3dd7aeceee65 | 21 | */ |
tbjazic | 0:3dd7aeceee65 | 22 | PI(); |
tbjazic | 0:3dd7aeceee65 | 23 | /** PI controller gain, integral time constant in seconds and sample time in seconds. */ |
tbjazic | 0:3dd7aeceee65 | 24 | PI(double K_C, double T_I, double sampleTime); |
tbjazic | 0:3dd7aeceee65 | 25 | /** Update PI controller gain, integral time constant and sample time. */ |
tbjazic | 0:3dd7aeceee65 | 26 | void setParameters(double K_C, double T_I, double sampleTime); |
tbjazic | 0:3dd7aeceee65 | 27 | /** Set the controller lower and upper output limit. */ |
tbjazic | 0:3dd7aeceee65 | 28 | void setOutputLimits(double lowerOutputLimit, double upperOutputLimit); |
tbjazic | 0:3dd7aeceee65 | 29 | /** Set the operation mode to "automatic" or "manual". */ |
tbjazic | 0:3dd7aeceee65 | 30 | void setOperationMode (Mode operationMode); |
tbjazic | 0:3dd7aeceee65 | 31 | /** Set the controller output manually. */ |
tbjazic | 0:3dd7aeceee65 | 32 | void setOutputManually(double u_C); |
tbjazic | 0:3dd7aeceee65 | 33 | /** Calculate the controller output u_C. */ |
tbjazic | 0:3dd7aeceee65 | 34 | double out(); |
tbjazic | 0:3dd7aeceee65 | 35 | /** Set the PI controller input e = SP - PV (setpoint - process value). */ |
tbjazic | 0:3dd7aeceee65 | 36 | void in(double e); |
tbjazic | 0:3dd7aeceee65 | 37 | private: |
tbjazic | 0:3dd7aeceee65 | 38 | double K_R, T_I, T_d, y, y_p1, u, u_p1, y_max, y_min, y_manual; |
tbjazic | 0:3dd7aeceee65 | 39 | Mode operationMode; |
tbjazic | 0:3dd7aeceee65 | 40 | }; |
tbjazic | 0:3dd7aeceee65 | 41 | |
tbjazic | 0:3dd7aeceee65 | 42 | #endif // PI_H |