test
Dependencies: ESP8266 HCSR04 PID
Fork of car_test_v1 by
Diff: AutomationElement/PI1.h
- Revision:
- 3:9e51de1050a1
diff -r 35738c77d454 -r 9e51de1050a1 AutomationElement/PI1.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AutomationElement/PI1.h Sat Nov 25 03:36:58 2017 +0000 @@ -0,0 +1,42 @@ +#ifndef PI1_H +#define PI1_H + +#include "mbed.h" + +/** Data type for choosing the operation mode of the controller ("automatic" or "manual"). */ +enum Mode {automatic, manual}; + +/** Transfer function of a PI controller with output limitation, anti-windup and bumpless automatic and manual mode. + * G_C(s) = U_C(s) / E(s) = K_C ( 1 + 1 / (T_I s) ) = K_C (1 + T_I s) / (T_I s) + * + * K_C is the controller gain, and T_I is the controller integral time constant in seconds. + * + * Author(s): TVZ Mechatronics Team + * + */ +class PI1 { + public: + /** Default constructor. + * K_C = 1, T_I = 1 s, sampleTime = 0.1 s. + */ + PI1(); + /** PI controller gain, integral time constant in seconds and sample time in seconds. */ + PI1(double K_C, double T_I, double sampleTime); + /** Update PI controller gain, integral time constant and sample time. */ + void setParameters(double K_C, double T_I, double sampleTime); + /** Set the controller lower and upper output limit. */ + void setOutputLimits(double lowerOutputLimit, double upperOutputLimit); + /** Set the operation mode to "automatic" or "manual". */ + void setOperationMode (Mode operationMode); + /** Set the controller output manually. */ + void setOutputManually(double u_C); + /** Calculate the controller output u_C. */ + double out(); + /** Set the PI controller input e = SP - PV (setpoint - process value). */ + void in(double e); + private: + double K_R, T_I, T_d, y, y_p1, u, u_p1, y_max, y_min, y_manual; + Mode operationMode; +}; + +#endif // PI1_H \ No newline at end of file