好文档 - 专业文书写作范文服务资料分享网站

PID控制算法的C语言实现(完整版)

天下 分享 时间: 加入收藏 我要投稿 点赞

int main(){

PID_init(); int count=0;

while(count<1000) {

float speed=PID_realize(200.0); printf(\ count++; }

return 0; }

运行后的1000个数据为:

83.000000 87.143440 122.618294 11.555000 88.552994 123.585594 59.559677 89.946945 124.540794 28.175406 91.322067 125.484062 52.907425 92.680977 126.415535 38.944149 94.022224 127.335365 51.891701 95.347176 128.243698 46.141655 96.655235 129.140671 53.339050 97.947174 130.026443 51.510002 99.222801 130.901138 55.908447 100.482597 131.764893 55.944637 101.726562 132.617859 58.970676 102.955040 133.460159 59.882942 104.168114 134.291931 62.224998 105.366058 135.113297 63.537247 106.549004 135.924408 65.527702 107.717178 136.725372 67.011047 108.870743 137.516327 68.810638 110.009888 138.297394 70.355309 111.134796 139.068695 72.042023 112.245636 139.830353 73.595642 113.342598 140.582489 75.207603 114.425842 141.325226 76.745430 115.495552 142.058685 78.301514 116.551880 142.782974 79.812126 117.595009 143.498199 81.321915 118.625099 144.204498 82.800293 119.642311 144.901962 84.268898 120.646812 145.590714 85.713097

121.638756

146.270844

146.942474 147.605713 148.260651 148.907410 149.546082 150.176773 150.799576 151.414597 152.021927 152.621674 153.213913 153.798752 154.376282 154.946594 155.509781 156.065918 156.615112 157.157440 157.692993 158.221848 158.744095 159.259811 159.769073 160.271973 160.768585 161.258987 161.743271 162.221481 162.693726 163.160065

163.620575 164.075333 164.524399 164.967865 165.405777 165.838226 166.265259 166.686951 167.103378 167.514587 167.920670 168.321671 168.717667 169.108704 169.494858 169.876175 170.252731 170.624588 170.991791 171.354401 171.712479 172.066086 172.415268 172.760086 173.100601 173.436844 173.768890 174.096786 174.420578 174.740326

175.056076 175.367889 175.675797 175.979858 176.280121 176.576630 176.869431 177.158569 177.444092 177.726044 178.004471 178.279419 178.550934 178.819046 179.083817 179.345276 179.603470 179.858429 180.110214 180.358841 180.604370 180.846817 181.086243 181.322662 181.556137 181.786682 182.014359 182.239182 182.461197 182.680435

182.896942 183.110733 183.321854 183.530334 183.736206 183.939514 184.140274 184.338531 184.534302 184.727631 184.918533 185.107056 185.293228 185.477066 185.658615 185.837891 186.014923 186.189743 186.362381 186.532852 186.701202 186.867432 187.031601 187.193710 187.353790 187.511871 187.667984 187.822128 187.974365 188.124680

188.273132 188.419724 188.564484 188.707428 188.848587 188.987976 189.125626 189.261566 189.395798 193.257675 193.341965 193.425186 193.507385 193.588531 193.668686 193.747818 193.825974 193.903152 196.123566 196.172028 196.219879 196.267136 196.313797 196.359879 196.405380 196.450317 196.494690 197.771255 197.799118 197.826630 197.853806 197.880630 197.907120 197.933289 197.959122 197.984634 198.718597 198.734619 198.750443 198.766068 198.781494 198.796722 198.811768 198.826614 198.841278 199.263290 199.272507 199.281601 199.290588 199.299454 199.308212 199.316864 199.325409 199.333847 199.576462 199.581757 199.586990 199.592148 199.597244 199.602280 199.607254 199.612167 199.617020 189.528351 189.659256 189.788513 189.916168 190.042221 190.166702 190.289627 190.411011 190.530884 190.649246 190.766144 190.881561 190.995544 191.108109 191.219254 191.329025 191.437408 191.544449 191.650146 191.754517 191.857590 191.959366 192.059875 192.159134 192.257141 192.353928 192.449509 192.543884 192.637085 192.729126 192.820007 192.909760 192.998383 193.085907 193.172333

193.979370 194.054626 194.128952 194.202332 194.274811 194.346375 194.417053 194.486832 194.555756 194.623810 194.691010 194.757370 194.822906 194.887619 194.951523 195.014633 195.076950 195.138489 195.199265 195.259277 195.318542 195.377060 195.434845 195.491913 195.548264 195.603912 195.658859 195.713135 195.766724 195.819641 195.871902 195.923508 195.974472 196.024796 196.074493

196.538513 196.581787 196.624512 196.666702 196.708374 196.749512 196.790146 196.830261 196.869888 196.909012 196.947647 196.985809 197.023483 197.060699 197.097443 197.133728 197.169556 197.204941 197.239883 197.274384 197.308456 197.342102 197.375320 197.408127 197.440521 197.472519 197.504105 197.535309 197.566116 197.596542 197.626587 197.656250 197.685547 197.714478 197.743042

198.009827 198.034698 198.059265 198.083527 198.107483 198.131134 198.154495 198.177567 198.200348 198.222839 198.245056 198.266998 198.288666 198.310059 198.331177 198.352036 198.372635 198.392975 198.413071 198.432907 198.452499 198.471848 198.490952 198.509811 198.528442 198.546829 198.565002 198.582932 198.600647 198.618134 198.635406 198.652466 198.669312 198.685944 198.702377

198.855759 198.870056 198.884186 198.898132 198.911911 198.925507 198.938934 198.952194 198.965286 198.978226 198.990997 199.003616 199.016068 199.028366 199.040512 199.052505 199.064346 199.076050 199.087601 199.099014 199.110275 199.121399 199.132385 199.143234 199.153946 199.164520 199.174973 199.185287 199.195465 199.205521 199.215454 199.225266 199.234955 199.244522 199.253967

199.342178 199.350403 199.358521 199.366547 199.374466 199.382294 199.390015 199.397644 199.405167 199.412613 199.419952 199.427200 199.434357 199.441422 199.448410 199.455307 199.462112 199.468842 199.475479 199.482040 199.488510 199.494904 199.501221 199.507462 199.513611 199.519699 199.525696 199.531631 199.537476 199.543259 199.548965 199.554611 199.560181 199.565674 199.571106

199.621811 199.626541 199.631210 199.635818 199.640366 199.644867 199.649307 199.653687 199.658020 199.662292 199.666519 199.670685 199.674805 199.678864 199.682877 199.686844 199.690750 199.694626 199.698441 199.702209 199.705933 199.709610 199.713242 199.716827 199.720367 199.723862 199.727310 199.730713 199.734085 199.737411 199.740692 199.743942 199.747147 199.750305 199.753433

199.756516 199.759567 199.762573 199.765549 199.768478 199.771378 199.774231 199.777054 199.779846 199.860031 199.861786 199.863510 199.865219 199.866898 199.868561 199.870209 199.871826 199.873428 199.919571 199.920578 199.921570 199.922546 199.923523 199.924469 199.925415 199.926346 199.927261 199.953766 199.954346 199.954910 199.955475 199.956024 199.956573 199.957108 199.957642 199.958176 199.973389 199.973724 199.974045 199.974380 199.974701 199.975021 199.975327 199.975632 199.975937 199.984726 199.984909 199.985107 199.985291 199.985474 199.985657 199.985840 199.986023 199.986191 199.991257 199.991364 199.991470 199.991577 199.991684 199.991791 199.991898 199.992004 199.992096 199.782593 199.785309 199.787994 199.790649 199.793259 199.795853 199.798401 199.800919 199.803406 199.805862 199.808289 199.810684 199.813049 199.815384 199.817688 199.819962 199.822220 199.824432 199.826630 199.828796 199.830933 199.833054 199.835144 199.837204 199.839233 199.841248 199.843231 199.845200 199.847137 199.849045 199.850937 199.852798 199.854645 199.856461 199.858261

199.875015 199.876572 199.878113 199.879639 199.881149 199.882629 199.884094 199.885544 199.886978 199.888397 199.889786 199.891174 199.892532 199.893875 199.895203 199.896515 199.897812 199.899094 199.900360 199.901611 199.902847 199.904068 199.905273 199.906464 199.907639 199.908798 199.909943 199.911072 199.912186 199.913284 199.914368 199.915436 199.916489 199.917526 199.918564

199.928177 199.929077 199.929962 199.930832 199.931702 199.932556 199.933395 199.934235 199.935059 199.935867 199.936676 199.937469 199.938248 199.939026 199.939789 199.940536 199.941284 199.942017 199.942749 199.943466 199.944168 199.944870 199.945557 199.946243 199.946915 199.947586 199.948242 199.948883 199.949524 199.950150 199.950775 199.951385 199.951996 199.952591 199.953186

199.958694 199.959213 199.959717 199.960220 199.960724 199.961212 199.961700 199.962173 199.962646 199.963120 199.963577 199.964035 199.964478 199.964920 199.965363 199.965790 199.966217 199.966644 199.967056 199.967468 199.967880 199.968277 199.968674 199.969070 199.969452 199.969833 199.970215 199.970581 199.970947 199.971313 199.971664 199.972015 199.972366 199.972717 199.973053

199.976242 199.976532 199.976822 199.977112 199.977402 199.977676 199.977966 199.978241 199.978516 199.978790 199.979050 199.979309 199.979568 199.979828 199.980072 199.980331 199.980576 199.980820 199.981064 199.981293 199.981537 199.981766 199.981995 199.982224 199.982437 199.982666 199.982880 199.983093 199.983307 199.983521 199.983719 199.983932 199.984131 199.984329 199.984528

199.986374 199.986542 199.986710 199.986877 199.987045 199.987213 199.987366 199.987534 199.987686 199.987839 199.987991 199.988144 199.988297 199.988449 199.988586 199.988739 199.988876 199.989014 199.989151 199.989288 199.989426 199.989563 199.989685 199.989822 199.989944 199.990067 199.990189 199.990311 199.990433 199.990555 199.990677 199.990799 199.990906 199.991028 199.991135

199.992203 199.992294 199.992401 199.992493 199.992584 199.992676 199.992767 199.992859 199.992950 199.993042 199.993134 199.993225 199.993301 199.993393 199.993469 199.993561 199.993637 199.993713 199.993790 199.993866 199.993942 199.994019 199.994095 199.994171 199.994247 199.994324 199.994400 199.994476 199.994537 199.994614 199.994675 199.994751 199.994812 199.994873 199.994934

199.994995 199.995056 199.995117 199.995178 199.995239 199.995300 199.995361 199.995422 199.995483 199.996368 199.996414 199.996460 199.996506 199.996552 199.996597 199.996643 199.996689 199.996735 199.997375 199.997406 199.997437 199.997467 199.997498 199.997528 199.997559 199.997589 199.997620 199.998123 199.998138 199.998169 199.998184 199.998215 199.998230 199.998260 199.998276 199.998306 199.998627 199.998642 199.998657 199.998672 199.998688 199.998703 199.998718 199.998734 199.998749 199.999008 199.999023 199.999039 199.999054 199.999069 199.999084 199.999100 199.999115 199.999130 199.999344 199.999344 199.999359 199.999359 199.999374 199.999374 199.999390 199.999390 199.999405 199.995544 199.995605 199.995667 199.995712 199.995773 199.995819 199.995880 199.995926 199.995987 199.996033 199.996094 199.996140 199.996185 199.996231 199.996277 199.996323

199.996780 199.996826 199.996872 199.996902 199.996948 199.996979 199.997025 199.997055 199.997101 199.997131 199.997177 199.997208 199.997253 199.997284 199.997314 199.997345

199.997650 199.997681 199.997711 199.997742 199.997772 199.997803 199.997833 199.997864 199.997894 199.997925 199.997955 199.997986 199.998016 199.998047 199.998077 199.998093

199.998322 199.998352 199.998367 199.998398 199.998413 199.998444 199.998459 199.998489 199.998505 199.998520 199.998535 199.998550 199.998566 199.998581 199.998596 199.998611

199.998764 199.998779 199.998795 199.998810 199.998825 199.998840 199.998856 199.998871 199.998886 199.998901 199.998917 199.998932 199.998947 199.998962 199.998978 199.998993

199.999146 199.999161 199.999176 199.999191 199.999207 199.999222 199.999237 199.999252 199.999268 199.999283 199.999298 199.999298 199.999313 199.999313 199.999329 199.999329

199.999405 199.999420 199.999420 199.999435 199.999435 199.999451 199.999451 199.999466 199.999466 199.999481 199.999481 199.999496 199.999496 199.999512 199.999512

PID控制算法的C语言实现五 积分分离的PID控制算法C语言实现

通过三、四两篇文章,基本上已经弄清楚了PID控制算法的最常规的表达方法。在普通PID控制中,引入积分环节的目的,主要是为了消除静差,提高控制精度。但是在启动、结束或大幅度增减设定时,短时间内系统输出有很大的偏差,会造成PID运算的积分积累,导致控制量超过执行机构可能允许的最大动作范围对应极限控制量,从而引起较大的超调,甚至是震荡,这是绝对不允许的。 为了克服这一问题,引入了积分分离的概念,其基本思路是 当被控量与设定值偏差较大时,取消积分作用; 当被控量接近给定值时,引入积分控制,以消除静差,提高精度。其具体实现代码如下: pid.Kp=0.2; pid.Ki=0.04;

pid.Kd=0.2; //初始化过程

if(abs(pid.err)>200) {

index=0; }else{ index=1;

pid.integral+=pid.err; }

pid.voltage=pid.Kp*pid.err+index*pid.Ki*pid.integral+pid.Kd*(pid.err-pid.err_last); //算法具体实现过程

其它部分的代码参见《PID控制算法的C语言实现三》中的讲解,不再赘述。同样采集1000个量,会发现,系统到199所有的时间是原来时间的1/2,系统的快速性得到了提高。

199.003571 199.036804 199.068924 199.099960 199.129974 199.158981 199.187012

199.214111 199.240311 199.265640 199.290115 199.313797 199.336655 199.358795

199.380157 199.400818 199.420792 199.440109 199.458771 199.476807 199.494263

199.511124 199.527420 199.543182 199.558426 199.573135 199.587372 199.601120

199.614426 199.627289 199.639694 199.651718 199.663315 199.674561 199.685410

199.695908 199.706039 199.715851 199.725311 199.734482 199.743332 199.751907

199.760162 199.768173 199.775894 199.783371 199.790588 199.797577 199.804337

PID控制算法的C语言实现(完整版)

intmain(){PID_init();intcount=0;while(count<1000){floatspeed=PID_realize(200.0);printf(\count++;}retur
推荐度:
点击下载文档文档为doc格式
53adw1dpq51j03u4hzb9
领取福利

微信扫码领取福利

微信扫码分享