Proportional, integral, derivative controller library. Ported from the Arduino PID library by Brett Beauregard.

Dependents:   ES_CW2_Starter_MDMA

Fork of PID by Aaron Berk

Files at this revision

API Documentation at this revision

Comitter:
david_s95
Date:
Thu Mar 16 10:44:54 2017 +0000
Parent:
4:c42880625091
Commit message:
Removed unnecessary error checking.

Changed in this revision

PID.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/PID.cpp	Sat Mar 11 15:58:19 2017 +0000
+++ b/PID.cpp	Thu Mar 16 10:44:54 2017 +0000
@@ -58,7 +58,7 @@
     //Make sure to set these to more appropriate limits for
     //your application.
     setInputLimits(0.0, 200.0);
-    setOutputLimits(1.0, 300.0);
+    setOutputLimits(0.1, 200.0);
 
     tSample_ = interval;
 
@@ -78,11 +78,12 @@
 }
 
 void PID::setInputLimits(float inMin, float inMax) {
-
-    //Make sure we haven't been given impossible values.
-    if (inMin >= inMax) {
-        return;
-    }
+    
+//I know we've not given impossible values, so it's unnecessary to check
+//    //Make sure we haven't been given impossible values.
+//    if (inMin >= inMax) {
+//        return;
+//    }
 
     //Rescale the working variables to reflect the changes.
     prevProcessVariable_ *= (inMax - inMin) / inSpan_;
@@ -103,10 +104,11 @@
 
 void PID::setOutputLimits(float outMin, float outMax) {
 
-    //Make sure we haven't been given impossible values.
-    if (outMin >= outMax) {
-        return;
-    }
+//I know we've not given impossible values, so it's unnecessary to check
+//    //Make sure we haven't been given impossible values.
+//    if (outMin >= outMax) {
+//        return;
+//    }
 
     //Rescale the working variables to reflect the changes.
     prevControllerOutput_ *= (outMax - outMin) / outSpan_;
@@ -126,10 +128,11 @@
 
 void PID::setTunings(float Kc, float tauI, float tauD) {
 
-    //Verify that the tunings make sense.
-    if (Kc == 0.0 || tauI < 0.0 || tauD < 0.0) {
-        return;
-    }
+//I know we've not given impossible values, so it's unnecessary to check
+//    //Verify that the tunings make sense.
+//    if (Kc == 0.0 || tauI < 0.0 || tauD < 0.0) {
+//        return;
+//    }
 
     //Store raw values to hand back to user on request.
     pParam_ = Kc;
@@ -247,7 +250,7 @@
     }
 
     //Compute the current slope of the input signal.
-    float dMeas = (scaledPV - prevProcessVariable_) / tSample_;
+//    float dMeas = (scaledPV - prevProcessVariable_) / tSample_;
 
     float scaledBias = 0.0;
 
@@ -256,7 +259,7 @@
     }
 
     //Perform the PID calculation.
-    controllerOutput_ = scaledBias + Kc_ * (error + (tauR_ * accError_) - (tauD_ * dMeas));
+    controllerOutput_ = scaledBias + Kc_ * error + (tauR_ * accError_);// - (tauD_ * dMeas));
 
     //Make sure the computed output is within output constraints.
     if (controllerOutput_ < 0.0) {