Simple PID Controller with Integral Windup Supports creating a diagnostics message to send to a GUI Prints to Binary
Fork of PidControllerV2 by
Diff: PidController.cpp
- Revision:
- 3:c169d08a9d0b
- Parent:
- 2:dd64c2cf9066
- Child:
- 4:b590bd8fec6f
--- 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");} + } +