Simple PID controller class with output clamp

Dependents:   NXPCUPcar

PIDcontroller.h

Committer:
Clarkk
Date:
2017-07-05
Revision:
1:946d71f8afc6
Parent:
0:070ecbe87363
Child:
2:994ed695c8a5

File content as of revision 1:946d71f8afc6:

#include "mbed.h"

#ifndef _PIDCONTROLLER_H
#define _PIDCONTROLLER_H

class PID
{
    public:

    PID();
    void reset(void);
    void setReference(float ref);
    void setCoefficients(float Kp, float Ki, float Kd);
    void setOutputLimits(float min, float max);
    float processNewValue(float input);
    float getControllerOutput(void);
    
    private:

    float target;    
    float kp, ki, kd;
    float integral, derivative;
    float error, previous_error;
    float outputMin, outputMax;
    
    Timer t;
};

#endif