test

Dependencies:   ESP8266 HCSR04 PID

Fork of car_test_v1 by 涂 桂旺

Committer:
tgw
Date:
Sat Nov 25 03:36:58 2017 +0000
Revision:
3:9e51de1050a1
test

Who changed what in which revision?

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