pid

Dependents:   OneCircleRobot

Fork of PID by Kiko Ishimoto

Revision:
4:a3c85727f0f6
Parent:
3:34f4f22b18e7
--- a/PID.h	Tue Aug 18 04:45:10 2015 +0000
+++ b/PID.h	Mon Sep 14 07:43:57 2015 +0000
@@ -1,32 +1,57 @@
-
-#ifndef PID_H
-#define PID_H
-
-#include "mbed.h"
-class PID 
-{    
-    public:
-        
-        PID(float tauKc, float tauKi, float tauKd);
-    
-        double s_dErrIntg ,dErr_prev;
-        void Start();
-        void Reset();
-        void setInterval(double inter);
-        //Getters.
-        void stop();    
-        double dTarget; double dPoint;
-        // PI制御ゲイン
-        double GAIN_P ;//1.5 // 比例ゲイン
-        double GAIN_I ;//2.8 // 積分ゲイン
-        double GAIN_D ;//0.2 
-        double data;
-    private:
-        Timer timer;
-        Ticker T;
-        float interval;
-        void PIDctrl();
-        
-};
-
-#endif 
\ No newline at end of file
+
+#ifndef PID_H
+#define PID_H
+
+#include "mbed.h"
+class PID
+{
+protected:
+    PID(const PID& p);
+    PID& operator=(const PID &p) {
+        return *this;
+    }
+    void PIDctrl();
+public:
+    void InputLimits(float max,float min);
+    void OutputLimits(float max,float min);
+    PID(float tauKc, float tauKi, float tauKd ,Timer *T);
+
+    double s_dErrIntg ,dErr_prev;
+    void Start();
+    void pid_reset();
+    void setInterval(double inter);
+    //Getters.
+    void stop();
+    double dTarget;
+    double dPoint;
+    // PI制御ゲイン
+    double GAIN_P ;//1.5 // 比例ゲイン
+    double GAIN_I ;//2.8 // 積分ゲイン
+    double GAIN_D ;//0.2
+    double data;
+private:
+    double dErr;
+    
+    double dErrDiff;
+    float OutMax;
+    float InMax;
+    float OutMin;
+    float InMin;
+    float OutSpan;
+    float InSpan;
+    Timer *timer;
+    float prev_time;
+    float gettime() {
+        float a = timer->read()-prev_time;
+        //printf("%f ",prev_time);
+        prev_time=timer->read();
+        return a;
+    }
+    float T;
+    double dRet;
+    //Ticker T;
+    float interval;
+
+};
+
+#endif