Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BX-car_2 by
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 pv, 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 Kc_; 00092 float tauI_; 00093 float tauD_; 00094 00095 00096 00097 float pParam_; 00098 float iParam_; 00099 float dParam_; 00100 00101 float accError_; 00102 00103 //Raw tuning parameters. 00104 00105 //The point we want to reach. 00106 float setPoint_; 00107 //The thing we measure. 00108 float processVariable_; 00109 float prevProcessVariable_; 00110 //The output that affects the process variable. 00111 float controllerOutput_; 00112 float prevControllerOutput_; 00113 00114 //We work in % for calculations so these will scale from 00115 //real world values to 0-100% and back again. 00116 float inMin_; 00117 float inMax_; 00118 float inSpan_; 00119 00120 float outMin_; 00121 float outMid_; 00122 float outMax_; 00123 float outSpan_; 00124 00125 float ctrl_Lbound; 00126 float ctrl_Ubound; 00127 00128 00129 00130 00131 //The accumulated error, i.e. integral. 00132 //float accError_; 00133 //The controller output bias. 00134 // float bias_; 00135 00136 //The interval between samples. 00137 float tSample_; 00138 00139 //Controller output as a real world value. 00140 // volatile float realOutput_; 00141 00142 };
Generated on Tue Jul 12 2022 21:33:29 by
1.7.2
