my version

Dependents:   aps_so_c2

Fork of PID by Aaron Berk

Files at this revision

API Documentation at this revision

Comitter:
feupos
Date:
Sat Nov 18 18:28:32 2017 +0000
Parent:
0:6e12a3e5af19
Commit message:
set to float;

Changed in this revision

PID.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 6e12a3e5af19 -r b09436d17ecc PID.cpp
--- a/PID.cpp	Thu Sep 02 16:48:10 2010 +0000
+++ b/PID.cpp	Sat Nov 18 18:28:32 2017 +0000
@@ -127,7 +127,7 @@
 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) {
+    if (Kc == (float)0.0 || tauI < (float)0.0 || tauD < (float)0.0) {
         return;
     }
 
@@ -138,16 +138,16 @@
 
     float tempTauR;
 
-    if (tauI == 0.0) {
-        tempTauR = 0.0;
+    if (tauI == (float)0.0) {
+        tempTauR = (float)0.0;
     } else {
-        tempTauR = (1.0 / tauI) * tSample_;
+        tempTauR = ((float)1.0 / tauI) * tSample_;
     }
 
     //For "bumpless transfer" we need to rescale the accumulated error.
     if (inAuto) {
-        if (tempTauR == 0.0) {
-            accError_ = 0.0;
+        if (tempTauR == (float)0.0) {
+            accError_ = (float)0.0;
         } else {
             accError_ *= (Kc_ * tauR_) / (Kc * tempTauR);
         }
@@ -161,7 +161,7 @@
 
 void PID::reset(void) {
 
-    float scaledBias = 0.0;
+    float scaledBias = (float)0.0;
 
     if (usingFeedForward) {
         scaledBias = (bias_ - outMin_) / outSpan_;
@@ -173,7 +173,7 @@
     prevProcessVariable_  = (processVariable_ - inMin_) / inSpan_;
 
     //Clear any error in the integral.
-    accError_ = 0;
+    accError_ = (float)0;
 
 }
 
@@ -225,17 +225,17 @@
     //Pull in the input and setpoint, and scale them into percent span.
     float scaledPV = (processVariable_ - inMin_) / inSpan_;
 
-    if (scaledPV > 1.0) {
-        scaledPV = 1.0;
-    } else if (scaledPV < 0.0) {
-        scaledPV = 0.0;
+    if (scaledPV > (float)1.0) {
+        scaledPV = (float)1.0;
+    } else if (scaledPV < (float)0.0) {
+        scaledPV = (float)0.0;
     }
 
     float scaledSP = (setPoint_ - inMin_) / inSpan_;
-    if (scaledSP > 1.0) {
-        scaledSP = 1;
-    } else if (scaledSP < 0.0) {
-        scaledSP = 0;
+    if (scaledSP > (float)1.0) {
+        scaledSP = (float)1;
+    } else if (scaledSP < (float)0.0) {
+        scaledSP = (float)0;
     }
 
     float error = scaledSP - scaledPV;
@@ -249,7 +249,7 @@
     //Compute the current slope of the input signal.
     float dMeas = (scaledPV - prevProcessVariable_) / tSample_;
 
-    float scaledBias = 0.0;
+    float scaledBias = (float)0.0;
 
     if (usingFeedForward) {
         scaledBias = (bias_ - outMin_) / outSpan_;
@@ -259,10 +259,10 @@
     controllerOutput_ = scaledBias + Kc_ * (error + (tauR_ * accError_) - (tauD_ * dMeas));
 
     //Make sure the computed output is within output constraints.
-    if (controllerOutput_ < 0.0) {
-        controllerOutput_ = 0.0;
-    } else if (controllerOutput_ > 1.0) {
-        controllerOutput_ = 1.0;
+    if (controllerOutput_ < (float)0.0) {
+        controllerOutput_ = (float)0.0;
+    } else if (controllerOutput_ > (float)1.0) {
+        controllerOutput_ = (float)1.0;
     }
 
     //Remember this output for the windup check next time.