PID

Dependents:   Nucleo_spi 2015_denziben_i2c_S2 Nucleo_Motor Nucleo_Motor

Fork of PID by Aaron Berk

Files at this revision

API Documentation at this revision

Comitter:
kikoaac
Date:
Fri Oct 30 12:47:54 2015 +0000
Parent:
5:3519920d064d
Commit message:
???

Changed in this revision

PID.cpp Show annotated file Show diff for this revision Revisions of this file
PID.h Show annotated file Show diff for this revision Revisions of this file
diff -r 3519920d064d -r 775c9421fe3b PID.cpp
--- a/PID.cpp	Wed Sep 23 06:01:32 2015 +0000
+++ b/PID.cpp	Fri Oct 30 12:47:54 2015 +0000
@@ -52,6 +52,7 @@
 {
     timer = p.timer;
     data = 0;
+    bias=0;
     GAIN_P = p.GAIN_P;
     GAIN_I = p.GAIN_I;
     GAIN_D = p.GAIN_D;
@@ -63,6 +64,7 @@
 {
     timer=T;
     data = 0;
+    bias=0;
     GAIN_P = tauKp;
     GAIN_I = tauKi;
     GAIN_D = tauKd;
@@ -137,7 +139,7 @@
     else if(data<OutMin)s_dErrIntg=OutMin;
     else s_dErrIntg += (dErr+dErr_prev )* T /2.0;
     // 制御入力
-    dRet = GAIN_P * dErr + GAIN_I * s_dErrIntg + GAIN_D*dErrDiff;
+    dRet = bias+GAIN_P * dErr + GAIN_I * s_dErrIntg + GAIN_D*dErrDiff;
     
     dErr_prev = dErr;
     if(dRet>OutMax)data=OutMax;
@@ -150,3 +152,4 @@
 
 
 
+
diff -r 3519920d064d -r 775c9421fe3b PID.h
--- a/PID.h	Wed Sep 23 06:01:32 2015 +0000
+++ b/PID.h	Fri Oct 30 12:47:54 2015 +0000
@@ -1,51 +1,52 @@
-
-#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:
-    float OutMax;
-    float InMax;
-    float OutMin;
-    float InMin;
-    float OutSpan;
-    float InSpan;
-    Timer *timer;
-    float gettime() {
-        static float prev_time;
-        float a = timer->read()-prev_time;
-        prev_time=timer->read();
-        return a;
-    }
-    //Ticker T;
-    float interval;
-
-};
-
+
+#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);
+    void setbias(float bias_){bias=bias_;}
+    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:
+    float bias;
+    float OutMax;
+    float InMax;
+    float OutMin;
+    float InMin;
+    float OutSpan;
+    float InSpan;
+    Timer *timer;
+    float gettime() {
+        static float prev_time;
+        float a = timer->read()-prev_time;
+        prev_time=timer->read();
+        return a;
+    }
+    //Ticker T;
+    float interval;
+
+};
+
 #endif