Simple PID controller class with output clamp

Dependents:   NXPCUPcar

Committer:
Clarkk
Date:
Tue Jul 04 19:21:16 2017 +0000
Revision:
0:070ecbe87363
Child:
1:946d71f8afc6
PID Initial version

Who changed what in which revision?

UserRevisionLine numberNew 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 0:070ecbe87363 22 float integral,derivative;
Clarkk 0:070ecbe87363 23 float error,previous_error;
Clarkk 0:070ecbe87363 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