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:
- 4:b590bd8fec6f
- Parent:
- 3:c169d08a9d0b
- Child:
- 5:1206105e20bd
diff -r c169d08a9d0b -r b590bd8fec6f PidController.h --- a/PidController.h Wed Sep 06 23:45:40 2017 +0000 +++ b/PidController.h Wed Oct 04 01:13:49 2017 +0000 @@ -36,10 +36,12 @@ * @endcode */ -#include "mbed.h" + #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 @@ -55,16 +57,16 @@ /** Constructor * */ - PidController(); + PidController(bool); /** 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); + int Calculate(float SP, float PV, float ManualMV); - /** Update Internal Seetings + /** Update Internal Settings * @param Bias - Added to the PID Calculation * @param PropGain - Proportional Gain * @param IntGain - Integral Gain @@ -75,6 +77,12 @@ */ void UpdateSettings(float Bias, float PropGain, float IntGain, float DiffGain, float OutputMin, float OutputMax, float OutputScale); + /** Update Internal Settings + * @param OutputMin - Minimum Limit for the Output (units are same as setpoint) + * @param OutputMax - Maximum Limit for the Output (units are same as setpoint) + */ + void UpdateSettings(float OutputMin, float OutputMax); + /** Get the controller mode * @return 1 = AUTOMATIC, 0 = MANUAL(User has direct contol on output). */ @@ -118,9 +126,10 @@ int elapsedTime; //-- For PID Calculations + bool squareRootOuptut; float bias, scalar; float error; - float lastError; + float lastInput; float accumError; float minLimit, maxLimit; float K_p,K_i,K_d;