Simple PID controller class with output clamp
PIDcontroller.h@1:946d71f8afc6, 2017-07-05 (annotated)
- Committer:
- Clarkk
- Date:
- Wed Jul 05 20:30:07 2017 +0000
- Revision:
- 1:946d71f8afc6
- Parent:
- 0:070ecbe87363
- Child:
- 2:994ed695c8a5
Minor changes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Clarkk | 0:070ecbe87363 | 1 | #include "mbed.h" |
Clarkk | 0:070ecbe87363 | 2 | |
Clarkk | 0:070ecbe87363 | 3 | #ifndef _PIDCONTROLLER_H |
Clarkk | 0:070ecbe87363 | 4 | #define _PIDCONTROLLER_H |
Clarkk | 0:070ecbe87363 | 5 | |
Clarkk | 0:070ecbe87363 | 6 | class PID |
Clarkk | 0:070ecbe87363 | 7 | { |
Clarkk | 0:070ecbe87363 | 8 | public: |
Clarkk | 0:070ecbe87363 | 9 | |
Clarkk | 0:070ecbe87363 | 10 | PID(); |
Clarkk | 0:070ecbe87363 | 11 | void reset(void); |
Clarkk | 0:070ecbe87363 | 12 | void setReference(float ref); |
Clarkk | 0:070ecbe87363 | 13 | void setCoefficients(float Kp, float Ki, float Kd); |
Clarkk | 0:070ecbe87363 | 14 | void setOutputLimits(float min, float max); |
Clarkk | 0:070ecbe87363 | 15 | float processNewValue(float input); |
Clarkk | 0:070ecbe87363 | 16 | float getControllerOutput(void); |
Clarkk | 0:070ecbe87363 | 17 | |
Clarkk | 0:070ecbe87363 | 18 | private: |
Clarkk | 0:070ecbe87363 | 19 | |
Clarkk | 0:070ecbe87363 | 20 | float target; |
Clarkk | 0:070ecbe87363 | 21 | float kp, ki, kd; |
Clarkk | 1:946d71f8afc6 | 22 | float integral, derivative; |
Clarkk | 1:946d71f8afc6 | 23 | float error, previous_error; |
Clarkk | 1:946d71f8afc6 | 24 | float outputMin, outputMax; |
Clarkk | 0:070ecbe87363 | 25 | |
Clarkk | 0:070ecbe87363 | 26 | Timer t; |
Clarkk | 0:070ecbe87363 | 27 | }; |
Clarkk | 0:070ecbe87363 | 28 | |
Clarkk | 0:070ecbe87363 | 29 | #endif |