Added Getter for Error

Revision:
1:6895ff841ee2
Parent:
0:6e12a3e5af19
--- a/PID.cpp	Thu Sep 02 16:48:10 2010 +0000
+++ b/PID.cpp	Tue Apr 12 07:51:25 2022 +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 == 0.0f || tauI < 0.0f || tauD < 0.0f) {
         return;
     }
 
@@ -138,16 +138,16 @@
 
     float tempTauR;
 
-    if (tauI == 0.0) {
-        tempTauR = 0.0;
+    if (tauI == 0.0f) {
+        tempTauR = 0.0f;
     } else {
-        tempTauR = (1.0 / tauI) * tSample_;
+        tempTauR = (1.0f / tauI) * tSample_;
     }
 
     //For "bumpless transfer" we need to rescale the accumulated error.
     if (inAuto) {
-        if (tempTauR == 0.0) {
-            accError_ = 0.0;
+        if (tempTauR == 0.0f) {
+            accError_ = 0.0f;
         } else {
             accError_ *= (Kc_ * tauR_) / (Kc * tempTauR);
         }
@@ -161,7 +161,7 @@
 
 void PID::reset(void) {
 
-    float scaledBias = 0.0;
+    float scaledBias = 0.0f;
 
     if (usingFeedForward) {
         scaledBias = (bias_ - outMin_) / outSpan_;
@@ -225,20 +225,21 @@
     //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 > 1.0f) {
+        scaledPV = 1.0f;
+    } else if (scaledPV < 0.0f) {
+        scaledPV = 0.0f;
     }
 
     float scaledSP = (setPoint_ - inMin_) / inSpan_;
-    if (scaledSP > 1.0) {
+    if (scaledSP > 1.0f) {
         scaledSP = 1;
-    } else if (scaledSP < 0.0) {
+    } else if (scaledSP < 0.0f) {
         scaledSP = 0;
     }
 
     float error = scaledSP - scaledPV;
+    fError =    error;
 
     //Check and see if the output is pegged at a limit and only
     //integrate if it is not. This is to prevent reset-windup.
@@ -249,7 +250,7 @@
     //Compute the current slope of the input signal.
     float dMeas = (scaledPV - prevProcessVariable_) / tSample_;
 
-    float scaledBias = 0.0;
+    float scaledBias = 0.0f;
 
     if (usingFeedForward) {
         scaledBias = (bias_ - outMin_) / outSpan_;
@@ -259,10 +260,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_ < 0.0f) {
+        controllerOutput_ = 0.0f;
+    } else if (controllerOutput_ > 1.0f) {
+        controllerOutput_ = 1.0f;
     }
 
     //Remember this output for the windup check next time.
@@ -322,3 +323,7 @@
     return dParam_;
 
 }
+
+float PID::getError() {
+    return fError;
+}