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:
- 6:99403113343f
- Parent:
- 5:1206105e20bd
diff -r 1206105e20bd -r 99403113343f PidController.h --- a/PidController.h Tue Oct 31 03:46:43 2017 +0000 +++ b/PidController.h Mon May 07 05:15:19 2018 +0000 @@ -28,22 +28,14 @@ * * * - - * @code -#include "mbed.h" -#include "PID.h" - - * @endcode */ - - #ifndef PidController_H #define PidController_H #include "mbed.h" //-- Constants used in system -const int RATE = 20; //--(ms) Time that Calculate mehtod is being called +const int RATE = 100; //--(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 @@ -53,17 +45,15 @@ public: // Public Methods - /** Constructor - * - */ - PidController(char); + // Constructor + PidController(); /** 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. + * @return Returns If Controller is in Automatic then returns PID controlled signal. In manual returns the user SP. */ - float Calculate(float SP, float PV, float ManualMV); + float Calculate(float SP, float PV); /** Update Internal Settings * @param Bias - Added to the PID Calculation @@ -103,37 +93,37 @@ */ void EndDiag(void); - /** Build a string to send back to HMI to Graph PID - */ - void BuildDiagMessage(float SP, float PV, float PWM, float PropAction, float IntAction, float DifAction); - /** Check to see if the controller is collecting diagnostics data * @return true then a diagnostics message is been created. */ bool DiagnosticsEnabled(void){return collectDiagnostics;} - int GetElapsedtime(void){return elapsedTime;} - - // Made Public as im lazy - char diagMsg[65]; + /** Check to see if the controller is collecting diagnostics data + * @param Data - Starting address of target recieve buffer (must be at least 25char long) + */ + void GetDiagnosticsMessage(char *data); private: bool mode; - //-- For Diagnostics to GUI bool collectDiagnostics; - int elapsedTime; + uint16_t elapsedTime; + char diagMsg[28]; + + //-- Settings + float bias; + float minLimit, maxLimit; + float K_p,K_i,K_d; //-- For PID Calculations - char diagChar; - float bias; float error; - float lastInput; float accumError; - float minLimit, maxLimit; - float K_p,K_i,K_d; float prevError; - }; + + //-- Private Helper functions + void float_to_byte(char *data, float *val); + void int_to_byte(char *data, uint16_t val); + }; #endif