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.h
- Revision:
- 5:1206105e20bd
- Parent:
- 4:b590bd8fec6f
- Child:
- 6:99403113343f
diff -r b590bd8fec6f -r 1206105e20bd PidController.h --- a/PidController.h Wed Oct 04 01:13:49 2017 +0000 +++ b/PidController.h Tue Oct 31 03:46:43 2017 +0000 @@ -41,10 +41,9 @@ #ifndef PidController_H #define PidController_H #include "mbed.h" -#include "math.h" //-- Constants used in system -const int RATE = 100; //--(ms) Time that Calculate mehtod is being called +const int RATE = 20; //--(ms) Time that Calculate mehtod is being called const int AUTOMATIC = 0; //-- In automatic then PID Controls Output const int MANUAL = 1; //-- In Manual then User Controls Output directly @@ -57,14 +56,14 @@ /** Constructor * */ - PidController(bool); + PidController(char); /** Performs the PID Calculation * @param SP - Setpoint (target value) units depends on what PID is controlling * @param PV - Process Variable (feedback/ measure value) units depends on what PID is controlling * @return Returns If Controller is in Automatic then returns PID controlled signal. In manual returns the user SP multipled by scalar. */ - int Calculate(float SP, float PV, float ManualMV); + float Calculate(float SP, float PV, float ManualMV); /** Update Internal Settings * @param Bias - Added to the PID Calculation @@ -75,7 +74,7 @@ * @param OutputMax - Maximum Limit for the Output (units are same as setpoint) * @param OutputScale - Multiplier at End of PID loop to convert from engineering units to signal (eg PWM duty cycle) */ - void UpdateSettings(float Bias, float PropGain, float IntGain, float DiffGain, float OutputMin, float OutputMax, float OutputScale); + void UpdateSettings(float Bias, float PropGain, float IntGain, float DiffGain, float OutputMin, float OutputMax); /** Update Internal Settings * @param OutputMin - Minimum Limit for the Output (units are same as setpoint) @@ -126,13 +125,14 @@ int elapsedTime; //-- For PID Calculations - bool squareRootOuptut; - float bias, scalar; + char diagChar; + float bias; float error; float lastInput; float accumError; float minLimit, maxLimit; float K_p,K_i,K_d; + float prevError; }; #endif