123
Fork of Boboobooo by
Embed:
(wiki syntax)
Show/hide line numbers
controller.h
00001 #include "mbed.h" 00002 00003 00004 00005 class PID 00006 { 00007 public: 00008 00009 00010 float de_kp; 00011 float de_ip; 00012 float de_dp; 00013 00014 00015 00016 float de_output; 00017 00018 00019 /* 00020 * Constructeur 00021 * Sets default limits, calculates tuning parameters, and sets manual mode with no bias. 00022 * @param Kc - Tuning parameter 00023 * @param tauI - Tuning parameter 00024 * @param tauD - Tuning parameter 00025 * @param interval PID calculation performed every interval seconds. 00026 */ 00027 PID(float in_min,float in_max,float out_min,float out_max,float Kc, float tauI, float tauD, float interval); 00028 00029 /* 00030 * Scale from inputs to 0-100%. 00031 * @param InMin The real world value corresponding to 0%. 00032 * @param InMax The real world value corresponding to 100%. 00033 */ 00034 void setInputLimits(float inMin, float inMax); 00035 00036 /* 00037 * Scale from outputs to 0-100%. 00038 * @param outMin The real world value corresponding to 0%. 00039 * @param outMax The real world value corresponding to 100%. 00040 */ 00041 void setOutputLimits(float outMin, float outMax); 00042 00043 /* 00044 * Calculate PID constants. 00045 * Allows parameters to be changed on the fly without ruining calculations. 00046 * @param Kc - Tuning parameter 00047 * @param tauI - Tuning parameter 00048 * @param tauD - Tuning parameter 00049 */ 00050 void setTunings(float Kc, float tauI, float tauD); 00051 00052 /* 00053 * Reinitializes controller internals. Automatically 00054 * called on a manual to auto transition. 00055 */ 00056 // void reset(void); 00057 00058 /* 00059 * Set how fast the PID loop is run. 00060 * @param interval PID calculation peformed every interval seconds. 00061 */ 00062 // void setInterval(float interval); 00063 00064 /* 00065 * Set the bias. 00066 * @param bias The bias for the controller output. 00067 */ 00068 // void setBias(float bias); 00069 00070 /* 00071 * PID calculation. 00072 * @return The controller output as a float between outMin and outMax. 00073 */ 00074 float compute(float center, float sp); 00075 00076 //Getters. 00077 float getInMin(); 00078 float getInMax(); 00079 float getOutMin(); 00080 float getOutMax(); 00081 float getInterval(); 00082 float getPParam(); 00083 float getIParam(); 00084 float getDParam(); 00085 00086 private: 00087 00088 // bool usingFeedForward; 00089 00090 //Actual tuning parameters used in PID calculation. 00091 float Kp; 00092 float Ki; 00093 float Kd; 00094 float Kc_; 00095 float tauI_; 00096 float tauD_; 00097 00098 00099 00100 float pParam_; 00101 float iParam_; 00102 float dParam_; 00103 00104 float accError_; 00105 00106 //Raw tuning parameters. 00107 00108 //The point we want to reach. 00109 float setPoint_; 00110 //The thing we measure. 00111 float processVariable_; 00112 float prevProcessVariable_; 00113 //The output that affects the process variable. 00114 float controllerOutput_; 00115 float prevControllerOutput_; 00116 00117 //We work in % for calculations so these will scale from 00118 //real world values to 0-100% and back again. 00119 float inMin_; 00120 float inMax_; 00121 float inSpan_; 00122 00123 float outMin_; 00124 float outMid_; 00125 float outMax_; 00126 float outSpan_; 00127 00128 float ctrl_Lbound; 00129 float ctrl_Ubound; 00130 00131 00132 00133 00134 //The accumulated error, i.e. integral. 00135 //float accError_; 00136 //The controller output bias. 00137 // float bias_; 00138 00139 //The interval between samples. 00140 float tSample_; 00141 00142 //Controller output as a real world value. 00143 // volatile float realOutput_; 00144 00145 };
Generated on Wed Jul 20 2022 19:27:32 by
1.7.2
