Dependents:   nhk_2018_undercarry_test04 nhk_2018_undercarry_test08 nhk_2018_undercarry_test09 nhk_2018_undercarry_test10 ... more

Files at this revision

API Documentation at this revision

Comitter:
kenken0721
Date:
Sat Mar 24 10:50:11 2018 +0000
Parent:
2:09a00a9407f8
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
--- a/PID.cpp	Wed Mar 21 06:51:29 2018 +0000
+++ b/PID.cpp	Sat Mar 24 10:50:11 2018 +0000
@@ -10,20 +10,20 @@
 }
 
 void PID::init(){
-  timer.reset();
-  timer.start();
-  preTime = 0;
+  //timer.reset();
+  //timer.start();
+  preP = 0;
   P = 0;
   I = 0;
   D = 0;
 }
 
 double PID::compute(double input){
-    dt = (timer.read_us() - preTime) / 10000;
-    preTime = timer.read_us();
+    //dt = timer.read_ms() / 10;
+    //timer.reset();
     P  = Setpoint - input;
-    I += P * dt;
-    D  = (P - preP) / dt;
+    I += P;
+    D  = (P - preP);
     preP = P;
     return (KP * P + KI * I + KD * D);
 }
--- a/PID.h	Wed Mar 21 06:51:29 2018 +0000
+++ b/PID.h	Sat Mar 24 10:50:11 2018 +0000
@@ -5,13 +5,12 @@
 
 class PID {
 private:
-    Timer timer;
+    //Timer timer;
     double Setpoint;
     double KP;
     double KI;
     double KD;
-    unsigned long dt;
-    unsigned long preTime;
+    //unsigned long dt;
     double P;
     double I;
     double D;