pid
Fork of PID by
PID.h@4:a3c85727f0f6, 2015-09-14 (annotated)
- Committer:
- kikoaac
- Date:
- Mon Sep 14 07:43:57 2015 +0000
- Revision:
- 4:a3c85727f0f6
- Parent:
- 3:34f4f22b18e7
ADVANCE PID;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kikoaac | 4:a3c85727f0f6 | 1 | |
kikoaac | 4:a3c85727f0f6 | 2 | #ifndef PID_H |
kikoaac | 4:a3c85727f0f6 | 3 | #define PID_H |
kikoaac | 4:a3c85727f0f6 | 4 | |
kikoaac | 4:a3c85727f0f6 | 5 | #include "mbed.h" |
kikoaac | 4:a3c85727f0f6 | 6 | class PID |
kikoaac | 4:a3c85727f0f6 | 7 | { |
kikoaac | 4:a3c85727f0f6 | 8 | protected: |
kikoaac | 4:a3c85727f0f6 | 9 | PID(const PID& p); |
kikoaac | 4:a3c85727f0f6 | 10 | PID& operator=(const PID &p) { |
kikoaac | 4:a3c85727f0f6 | 11 | return *this; |
kikoaac | 4:a3c85727f0f6 | 12 | } |
kikoaac | 4:a3c85727f0f6 | 13 | void PIDctrl(); |
kikoaac | 4:a3c85727f0f6 | 14 | public: |
kikoaac | 4:a3c85727f0f6 | 15 | void InputLimits(float max,float min); |
kikoaac | 4:a3c85727f0f6 | 16 | void OutputLimits(float max,float min); |
kikoaac | 4:a3c85727f0f6 | 17 | PID(float tauKc, float tauKi, float tauKd ,Timer *T); |
kikoaac | 4:a3c85727f0f6 | 18 | |
kikoaac | 4:a3c85727f0f6 | 19 | double s_dErrIntg ,dErr_prev; |
kikoaac | 4:a3c85727f0f6 | 20 | void Start(); |
kikoaac | 4:a3c85727f0f6 | 21 | void pid_reset(); |
kikoaac | 4:a3c85727f0f6 | 22 | void setInterval(double inter); |
kikoaac | 4:a3c85727f0f6 | 23 | //Getters. |
kikoaac | 4:a3c85727f0f6 | 24 | void stop(); |
kikoaac | 4:a3c85727f0f6 | 25 | double dTarget; |
kikoaac | 4:a3c85727f0f6 | 26 | double dPoint; |
kikoaac | 4:a3c85727f0f6 | 27 | // PI制御ゲイン |
kikoaac | 4:a3c85727f0f6 | 28 | double GAIN_P ;//1.5 // 比例ゲイン |
kikoaac | 4:a3c85727f0f6 | 29 | double GAIN_I ;//2.8 // 積分ゲイン |
kikoaac | 4:a3c85727f0f6 | 30 | double GAIN_D ;//0.2 |
kikoaac | 4:a3c85727f0f6 | 31 | double data; |
kikoaac | 4:a3c85727f0f6 | 32 | private: |
kikoaac | 4:a3c85727f0f6 | 33 | double dErr; |
kikoaac | 4:a3c85727f0f6 | 34 | |
kikoaac | 4:a3c85727f0f6 | 35 | double dErrDiff; |
kikoaac | 4:a3c85727f0f6 | 36 | float OutMax; |
kikoaac | 4:a3c85727f0f6 | 37 | float InMax; |
kikoaac | 4:a3c85727f0f6 | 38 | float OutMin; |
kikoaac | 4:a3c85727f0f6 | 39 | float InMin; |
kikoaac | 4:a3c85727f0f6 | 40 | float OutSpan; |
kikoaac | 4:a3c85727f0f6 | 41 | float InSpan; |
kikoaac | 4:a3c85727f0f6 | 42 | Timer *timer; |
kikoaac | 4:a3c85727f0f6 | 43 | float prev_time; |
kikoaac | 4:a3c85727f0f6 | 44 | float gettime() { |
kikoaac | 4:a3c85727f0f6 | 45 | float a = timer->read()-prev_time; |
kikoaac | 4:a3c85727f0f6 | 46 | //printf("%f ",prev_time); |
kikoaac | 4:a3c85727f0f6 | 47 | prev_time=timer->read(); |
kikoaac | 4:a3c85727f0f6 | 48 | return a; |
kikoaac | 4:a3c85727f0f6 | 49 | } |
kikoaac | 4:a3c85727f0f6 | 50 | float T; |
kikoaac | 4:a3c85727f0f6 | 51 | double dRet; |
kikoaac | 4:a3c85727f0f6 | 52 | //Ticker T; |
kikoaac | 4:a3c85727f0f6 | 53 | float interval; |
kikoaac | 4:a3c85727f0f6 | 54 | |
kikoaac | 4:a3c85727f0f6 | 55 | }; |
kikoaac | 4:a3c85727f0f6 | 56 | |
kikoaac | 4:a3c85727f0f6 | 57 | #endif |