New PID library with digital anti-windup and process control
Fork of PID_modified by
PID.h@4:e3c9cb64be44, 2016-10-26 (annotated)
- Committer:
- benson516
- Date:
- Wed Oct 26 17:56:01 2016 +0000
- Revision:
- 4:e3c9cb64be44
- Parent:
- 3:d8646d8c994f
- Child:
- 5:016c99bb877f
Differential drive succeed (Ver. 1.0)
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 | 2:b9610a2d2ea0 | 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 | 4:e3c9cb64be44 | 11 | |
benson516 | 4:e3c9cb64be44 | 12 | // |
benson516 | 4:e3c9cb64be44 | 13 | void Compute_noWindUP(float reference_in, float feedbackvalue_in); |
benson516 | 4:e3c9cb64be44 | 14 | void Saturation_output(); |
benson516 | 4:e3c9cb64be44 | 15 | void Anti_windup(float delta); // delta_V = Vs - V |
benson516 | 4:e3c9cb64be44 | 16 | // |
benson516 | 2:b9610a2d2ea0 | 17 | |
weisnail | 0:7f9b4ca968ae | 18 | void SetOutputLimits(float setoutputLimits_H, float setoutputLimits_L); |
benson516 | 2:b9610a2d2ea0 | 19 | void SetInputLimits(float setinputLimits_H, float setinputLimits_L); |
benson516 | 3:d8646d8c994f | 20 | void EnableAntiWindUp(float Ka_in); |
weisnail | 0:7f9b4ca968ae | 21 | |
weisnail | 0:7f9b4ca968ae | 22 | float Kp; |
weisnail | 0:7f9b4ca968ae | 23 | float Ki; |
weisnail | 0:7f9b4ca968ae | 24 | float Kd; |
adam_z | 1:4df4895863cd | 25 | float Ka; |
weisnail | 0:7f9b4ca968ae | 26 | |
benson516 | 2:b9610a2d2ea0 | 27 | float error[2]; |
benson516 | 2:b9610a2d2ea0 | 28 | double error_I; |
benson516 | 2:b9610a2d2ea0 | 29 | |
weisnail | 0:7f9b4ca968ae | 30 | float output; |
weisnail | 0:7f9b4ca968ae | 31 | float reference; |
benson516 | 4:e3c9cb64be44 | 32 | float delta_output; // Error by saturating |
benson516 | 4:e3c9cb64be44 | 33 | |
benson516 | 2:b9610a2d2ea0 | 34 | float Ts; |
weisnail | 0:7f9b4ca968ae | 35 | |
weisnail | 0:7f9b4ca968ae | 36 | private: |
weisnail | 0:7f9b4ca968ae | 37 | |
weisnail | 0:7f9b4ca968ae | 38 | bool Outputlimit_bool; |
weisnail | 0:7f9b4ca968ae | 39 | bool Inputlimit_bool; |
adam_z | 1:4df4895863cd | 40 | bool AntiWindUp_bool; |
weisnail | 0:7f9b4ca968ae | 41 | |
weisnail | 0:7f9b4ca968ae | 42 | float outputLimits_H; |
weisnail | 0:7f9b4ca968ae | 43 | float outputLimits_L; |
weisnail | 0:7f9b4ca968ae | 44 | float inputLimits_H; |
weisnail | 0:7f9b4ca968ae | 45 | float inputLimits_L; |
weisnail | 0:7f9b4ca968ae | 46 | |
weisnail | 0:7f9b4ca968ae | 47 | float feedbackvalue; |
weisnail | 0:7f9b4ca968ae | 48 | // Ticker PID_timer; |
weisnail | 0:7f9b4ca968ae | 49 | |
weisnail | 0:7f9b4ca968ae | 50 | }; |
weisnail | 0:7f9b4ca968ae | 51 | |
weisnail | 0:7f9b4ca968ae | 52 | #endif /* PID_H*/ |