Universal PID library
Dependents: WRS2019_master FourOmniMecha WRS2020_mecanum_node
PID.h@0:873985df821c, 2019-12-14 (annotated)
- Committer:
- sgrsn
- Date:
- Sat Dec 14 12:23:58 2019 +0000
- Revision:
- 0:873985df821c
First commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sgrsn | 0:873985df821c | 1 | #ifndef PID_H |
sgrsn | 0:873985df821c | 2 | #define PID_H |
sgrsn | 0:873985df821c | 3 | #include "mbed.h" |
sgrsn | 0:873985df821c | 4 | |
sgrsn | 0:873985df821c | 5 | /*sample code |
sgrsn | 0:873985df821c | 6 | |
sgrsn | 0:873985df821c | 7 | */ |
sgrsn | 0:873985df821c | 8 | |
sgrsn | 0:873985df821c | 9 | class PID |
sgrsn | 0:873985df821c | 10 | { |
sgrsn | 0:873985df821c | 11 | public: |
sgrsn | 0:873985df821c | 12 | PID(Timer *T); |
sgrsn | 0:873985df821c | 13 | |
sgrsn | 0:873985df821c | 14 | float controlP(float target, float current, float new_Kp); |
sgrsn | 0:873985df821c | 15 | float controlPI(float target, float current); |
sgrsn | 0:873985df821c | 16 | float controlPID(float target, float current); |
sgrsn | 0:873985df821c | 17 | |
sgrsn | 0:873985df821c | 18 | void setParameter(float new_Kp, float new_Ki, float new_Kd); |
sgrsn | 0:873985df821c | 19 | void setParameter(float new_Ku, float new_Pu); |
sgrsn | 0:873985df821c | 20 | void setParameterPI(float new_Ku, float new_Pu); |
sgrsn | 0:873985df821c | 21 | void reset(); |
sgrsn | 0:873985df821c | 22 | |
sgrsn | 0:873985df821c | 23 | float Ku; |
sgrsn | 0:873985df821c | 24 | float Pu; |
sgrsn | 0:873985df821c | 25 | float Kp; |
sgrsn | 0:873985df821c | 26 | float Ti; |
sgrsn | 0:873985df821c | 27 | float Td; |
sgrsn | 0:873985df821c | 28 | float Ki; |
sgrsn | 0:873985df821c | 29 | float Kd; |
sgrsn | 0:873985df821c | 30 | |
sgrsn | 0:873985df821c | 31 | private: |
sgrsn | 0:873985df821c | 32 | Timer *timer; |
sgrsn | 0:873985df821c | 33 | float integral; |
sgrsn | 0:873985df821c | 34 | float last_error; |
sgrsn | 0:873985df821c | 35 | float current_time; |
sgrsn | 0:873985df821c | 36 | float last_time; |
sgrsn | 0:873985df821c | 37 | }; |
sgrsn | 0:873985df821c | 38 | |
sgrsn | 0:873985df821c | 39 | #endif |