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