PID modified by C.-F. Huang
Fork of PID by
PID.h@7:52f66036f628, 2016-12-24 (annotated)
- Committer:
- benson516
- Date:
- Sat Dec 24 09:51:00 2016 +0000
- Revision:
- 7:52f66036f628
- Parent:
- 4:e3c9cb64be44
Add the reset function
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
weisnail | 0:7f9b4ca968ae | 1 | #ifndef PID_H |
weisnail | 0:7f9b4ca968ae | 2 | #define PID_H |
weisnail | 0:7f9b4ca968ae | 3 | |
weisnail | 0:7f9b4ca968ae | 4 | #include "mbed.h" |
weisnail | 0:7f9b4ca968ae | 5 | |
weisnail | 0:7f9b4ca968ae | 6 | class PID{ |
weisnail | 0:7f9b4ca968ae | 7 | public: |
weisnail | 0:7f9b4ca968ae | 8 | |
benson516 | 7:52f66036f628 | 9 | PID(float Kp_in, float Ki_in, float Kd_in, float Sampletime_in); |
benson516 | 2:b9610a2d2ea0 | 10 | void Compute(float reference_in, float feedbackvalue_in); |
benson516 | 7:52f66036f628 | 11 | void Reset(void); |
benson516 | 7:52f66036f628 | 12 | // |
benson516 | 4:e3c9cb64be44 | 13 | void Compute_noWindUP(float reference_in, float feedbackvalue_in); |
benson516 | 7:52f66036f628 | 14 | // Method 1: Separated operation for anti-windup |
benson516 | 4:e3c9cb64be44 | 15 | void Saturation_output(); |
benson516 | 4:e3c9cb64be44 | 16 | void Anti_windup(float delta); // delta_V = Vs - V |
benson516 | 7:52f66036f628 | 17 | // Method 2: Single anti-windup operation |
benson516 | 7:52f66036f628 | 18 | void Anti_windup(); |
benson516 | 4:e3c9cb64be44 | 19 | // |
benson516 | 7:52f66036f628 | 20 | |
weisnail | 0:7f9b4ca968ae | 21 | void SetOutputLimits(float setoutputLimits_H, float setoutputLimits_L); |
benson516 | 7:52f66036f628 | 22 | void SetInputLimits(float setinputLimits_H, float setinputLimits_L); |
benson516 | 7:52f66036f628 | 23 | void EnableAntiWindUp(float Ka_in); |
benson516 | 7:52f66036f628 | 24 | |
weisnail | 0:7f9b4ca968ae | 25 | float Kp; |
weisnail | 0:7f9b4ca968ae | 26 | float Ki; |
weisnail | 0:7f9b4ca968ae | 27 | float Kd; |
adam_z | 1:4df4895863cd | 28 | float Ka; |
benson516 | 7:52f66036f628 | 29 | |
benson516 | 2:b9610a2d2ea0 | 30 | float error[2]; |
benson516 | 2:b9610a2d2ea0 | 31 | double error_I; |
benson516 | 7:52f66036f628 | 32 | |
weisnail | 0:7f9b4ca968ae | 33 | float output; |
weisnail | 0:7f9b4ca968ae | 34 | float reference; |
benson516 | 4:e3c9cb64be44 | 35 | float delta_output; // Error by saturating |
benson516 | 7:52f66036f628 | 36 | |
benson516 | 2:b9610a2d2ea0 | 37 | float Ts; |
weisnail | 0:7f9b4ca968ae | 38 | |
weisnail | 0:7f9b4ca968ae | 39 | private: |
benson516 | 7:52f66036f628 | 40 | |
weisnail | 0:7f9b4ca968ae | 41 | bool Outputlimit_bool; |
weisnail | 0:7f9b4ca968ae | 42 | bool Inputlimit_bool; |
adam_z | 1:4df4895863cd | 43 | bool AntiWindUp_bool; |
benson516 | 7:52f66036f628 | 44 | |
weisnail | 0:7f9b4ca968ae | 45 | float outputLimits_H; |
weisnail | 0:7f9b4ca968ae | 46 | float outputLimits_L; |
weisnail | 0:7f9b4ca968ae | 47 | float inputLimits_H; |
weisnail | 0:7f9b4ca968ae | 48 | float inputLimits_L; |
benson516 | 7:52f66036f628 | 49 | |
weisnail | 0:7f9b4ca968ae | 50 | float feedbackvalue; |
weisnail | 0:7f9b4ca968ae | 51 | // Ticker PID_timer; |
weisnail | 0:7f9b4ca968ae | 52 | |
weisnail | 0:7f9b4ca968ae | 53 | }; |
weisnail | 0:7f9b4ca968ae | 54 | |
benson516 | 7:52f66036f628 | 55 | #endif /* PID_H*/ |