Clark Lin / Mbed 2 deprecated BX-car

Dependencies:   mbed

Fork of BX-car by kao yi

Revision:
15:3fa780990a6a
Parent:
12:f7acda4545ba
Child:
16:7ada30380595
diff -r 5cc3e028d8a3 -r 3fa780990a6a controller.cpp
--- a/controller.cpp	Mon Jun 30 02:26:43 2014 +0000
+++ b/controller.cpp	Mon Jun 30 02:54:45 2014 +0000
@@ -18,7 +18,7 @@
  
     tSample_ = interval;// init is 10
  
-    setTunings(Kc, tauI, tauD);
+    setTunings(Kp, Ki, Kd);
  
     setPoint_ = 0.0;
     processVariable_ = 0.0;
@@ -88,25 +88,25 @@
  
  
  
-void PID::setTunings(float Kc, float tauI, float tauD) {
+void PID::setTunings(float Kp, float Ki, float Kd) {
  
     //Verify that the tunings make sense.
-    if (Kc == 0.0 || tauI < 0.0 || tauD < 0.0) {
+    if (Kp == 0.0 || Ki < 0.0 || Kd < 0.0) {
         return;
     }
  
     //Store raw values to hand back to user on request.
-    pParam_ = Kc;
-    iParam_ = tauI;
-    dParam_ = tauD;
+    pParam_ = Kp;
+    iParam_ = Ki;
+    dParam_ = Kd;
  
     float tempTauR;
  
-    if (tauI == 0.0) {
+    if (Ki == 0.0) {
         tempTauR = 0.0;
     }
     else {
-        tempTauR = (1.0 / tauI) * tSample_;
+        tempTauR = (1.0 / Ki) * tSample_;
     }
  
     //For "bumpless transfer" we need to rescale the accumulated error.
@@ -115,13 +115,13 @@
             //accError_ = 0.0;
         //}
         //else {
-            accError_ *= (Kc_ * tauR_) / (Kc * tempTauR);
+            accError_ *= (Kp_ * tauR_) / (Kp * tempTauR);
         //}
     //}
  
-    Kc_ = Kc;
+    Kp_ = Kp;
     tauR_ = tempTauR;
-    tauD_ = tauD / tSample_;
+    Kd_ = Kd / tSample_;
  
 }
  
@@ -162,7 +162,7 @@
         //Convert the time-based tunings to reflect this change.
         tauR_ *= (interval / tSample_);
         accError_ *= (tSample_ / interval);
-        tauD_ *= (interval / tSample_);
+        Kd_ *= (interval / tSample_);
         tSample_ = interval;
     }
  
@@ -194,7 +194,7 @@
     float centerL = L; 
     float centerB = sp;  // center of black
     float error = centerB - centerR;
-    if(error < -8 && error >8){
+    if(error > -8 && error <8){
         return 0.085;
     }
     else if((error < -8 && error > -20)||(error > 8 && error < 40)){