Simple PID Controller with Integral Windup Supports creating a diagnostics message to send to a GUI

Files at this revision

API Documentation at this revision

Comitter:
batchee7
Date:
Wed Sep 06 23:45:40 2017 +0000
Parent:
2:dd64c2cf9066
Commit message:
Corrections to output generation

Changed in this revision

PidController.cpp Show annotated file Show diff for this revision Revisions of this file
PidController.h Show annotated file Show diff for this revision Revisions of this file
diff -r dd64c2cf9066 -r c169d08a9d0b PidController.cpp
--- a/PidController.cpp	Tue Sep 05 05:18:52 2017 +0000
+++ b/PidController.cpp	Wed Sep 06 23:45:40 2017 +0000
@@ -48,10 +48,10 @@
         if (CV < minLimit){CV= minLimit;}
         
         
-        if (collectDiagnostics){BuildDiagMessage(SP,PV, CV*scalar, K_p*error, IntegralAction, DerivativeAction);}
+        if (collectDiagnostics){BuildDiagMessage(SP,PV, CV, K_p*error, IntegralAction, DerivativeAction);}
         
         //Convert from mm/s to 0-100%
-        return (int)(CV*scalar)*10;
+        return (int)(CV*scalar);
     }
 
 void PidController::UpdateSettings(float Bias, float PropGain, float IntGain, float DiffGain, float OutputMin, float OutputMax, float OutputScale){
@@ -66,12 +66,18 @@
 
 void PidController::StartDiag(void){
     elapsedTime =0;
+    collectDiagnostics = true;
     }
-    
-void PidController::BuildDiagMessage(float SP, float PV, float PWM, float PropAction, float IntAction, float DifAction){
-    sprintf(diagMsg, "P %d %0.4f, %0.4f %0.1f", // %0.4f %0.4f %0.4f\n", 
-                    elapsedTime, SP, PV, PWM);// PropAction, IntAction, DifAction);
-    elapsedTime += RATE;
-    if (elapsedTime > 32000){EndDiag();}
+
+void PidController::EndDiag(void){
+    collectDiagnostics = false;
+
     }
 
+void PidController::BuildDiagMessage(float SetPoint, float ProcessVar, float PWM, float PropAction, float IntAction, float DifAction){
+    sprintf(diagMsg, "P %d %0.4f %0.4f %0.1f %0.4f %0.4f %0.4f\n", 
+                    elapsedTime, SetPoint, ProcessVar, PWM, PropAction, IntAction, DifAction);
+    elapsedTime += RATE;
+    if (elapsedTime > 32000){sprintf(diagMsg, "R");}
+    }
+
diff -r dd64c2cf9066 -r c169d08a9d0b PidController.h
--- a/PidController.h	Tue Sep 05 05:18:52 2017 +0000
+++ b/PidController.h	Wed Sep 06 23:45:40 2017 +0000
@@ -94,7 +94,7 @@
         
         /** Disable Diagnostics for HMI
         */
-        void EndDiag(void){collectDiagnostics = false;}
+        void EndDiag(void);
         
         /** Build a string to send back to HMI to Graph PID
         */