版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、C語(yǔ)言實(shí)現(xiàn)PID算法#includestruct_pidintpv;/*integerthatcontainstheprocessvalue*/intsp;/*integerthatcontainsthesetpoint*/floatintegral;floatpgain;floatigain;floatdgain;intdeadband;intlast_error;struct_pidwarm,*pid;intprocess_point,set_point,dead_band;floatp_gain,i_gain,d_gain,integral_val,new_integ;/*pid_ini
2、tDESCRIPTIONThisfunctioninitializesthepointersinthe_pidstructuretotheprocessvariableandthesetpoint.*pvand*spareintegerpointers.*/voidpid_init(struct_pid*warm,intprocess_point,intset_point)struct_pid*pid;pid=warm;pid-pv=process_point;pid-sp=set_point;/*pid_tuneDESCRIPTIONSetstheproportionalgain(p_gai
3、n),integralgain(i_gain),derivitivegain(d_gain),andthedeadband(dead_band)ofapidcontrolstructure_pid.*/voidpid_tune(struct_pid*pid,floatp_gain,floati_gain,floatd_gain,intdead_band)pid-pgain=p_gain;pid-igain=i_gain;pid-dgain=d_gain;pid-deadband=dead_band;pid-integral=integral_val;pid-last_error=0;/*pid
4、_setintegDESCRIPTIONSetanewvaluefortheintegraltermofthepidequation.Thisisusefulforsettingtheinitialoutputofthepidcontrolleratstartup.*/voidpid_setinteg(struct_pid*pid,floatnew_integ)pid-integral=new_integ;pid-last_error=0;/*pid_bumplessDESCRIPTIONBumplesstransferalgorithim.Whensuddenlychangingsetpoi
5、nts,orwhenrestartingthePIDequationafteranextendedpause,thederivativeoftheequationcancauseabumpinthecontrolleroutput.Thisfunctionwillhelpsmoothoutthatbump.Theprocessvaluein*pvshouldbetheupdatedjustbeforethisfunctionisused.*/voidpid_bumpless(struct_pid*pid)pid-last_error=(pid-sp)-(pid-pv);/*pid_calcDE
6、SCRIPTIONPerformsPIDcalculationsforthe_pidstructure*a.Thisfunctionusesthepositionalformofthepidequation,andincorporatesanintegralwinduppreventionalgorithim.Rectangularintegrationisused,sothisfunctionmustberepeatedonaconsistenttimebasisforaccuratecontrol.RETURNVALUEThenewoutputvalueforthepidloop.USAG
7、E#includecontrol.h*/floatpid_calc(struct_pid*pid)interr;floatpterm,dterm,result,ferror;err=(pid-sp)-(pid-pv);if(abs(err)pid-deadband)ferror=(float)err;/*dointegertofloatconversiononlyonce*/pterm=pid-pgain*ferror;if(pterm100|ptermintegral=0.0;elsepid-integral+=pid-igain*ferror;if(pid-integral100.0)pi
8、d-integral=100.0;elseif(pid-integralintegral=0.0;dterm=(float)(err-pid-last_error)*pid-dgain;result=pterm+pid-integral+dterm;elseresult=pid-integral;pid-last_error=err;return(result);voidmain(void)floatdisplay_value;intcount=0;pid=&warm;/printf(EnterthevaluesofProcesspoint,Setpoint,Pgain,Igain,Dgain
9、n);/scanf(%d%d%f%f%f,&process_point,&set_point,&p_gain,&i_gain,&d_gain);process_point=30;set_point=40;p_gain=(float)(5.2);i_gain=(float)(0.77);d_gain=(float)(0.18);dead_band=2;integral_val=(float)(0.01);printf(ThevaluesofProcesspoint,Setpoint,Pgain,Igain,Dgainn);printf(%6d%6d%4f%4f%4fn,process_point
10、,set_point,p_gain,i_gain,d_gain);printf(EnterthevaluesofProcesspointn);while(count4095000)PID_UK=4095000;elseif(PID_UKSetPoint-NextPoint;/偏差pp-SumError+=Error;/積分dError=pp-LastError-pp-PrevError;/當(dāng)前微分pp-PrevError=pp-LastError;pp-LastError=Error;return(pp-Proportion*Error/比例項(xiàng)+pp-Integral*pp-SumError/
11、積分項(xiàng)+pp-Derivative*dError/微分項(xiàng));/*=InitializePIDStructure=*/voidPIDInit(PID*pp)memset(pp,0,sizeof(PID);/*=MainProgram=*doublesensor(void)/DummySensorFunctionreturn100.0;voidactuator(doublerDelta)/DummyActuatorFunctionvoidmain(void)PIDsPID;/PIDControlStructuredoublerOut;/PIDResponse(Output)doublerIn;/PIDFeedback(Input)PIDInit(&sPID);/InitializeStructuresPID.Proportion=0.5;/SetPIDCoefficientssPID.Integral=0.5;sPID.De
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度新能源汽車電池供應(yīng)與購(gòu)銷合同樣本
- 2025版消防風(fēng)機(jī)系統(tǒng)工程后期維護(hù)合同3篇
- 2025年度智能屋面蓋瓦施工與維護(hù)一體化服務(wù)合同
- 2025年度國(guó)家教育考試智能安檢門售后服務(wù)保障合同
- 2025年危險(xiǎn)化學(xué)品運(yùn)輸保險(xiǎn)合同模板
- 2025年度金融服務(wù)分公司戰(zhàn)略合作合同范本
- 2025年度特色農(nóng)產(chǎn)品直供合同范本
- 2025版礦產(chǎn)資源探礦權(quán)轉(zhuǎn)讓合同協(xié)議書(shū):促進(jìn)地質(zhì)勘查產(chǎn)業(yè)升級(jí)3篇
- 2025年度廣告創(chuàng)意設(shè)計(jì)版權(quán)授權(quán)合同-@-3
- 二零二五年度工程竣工測(cè)量驗(yàn)收合同4篇
- 國(guó)際貿(mào)易地理 全套課件
- GB/T 20878-2024不銹鋼牌號(hào)及化學(xué)成分
- 某房屋建筑工程監(jiān)理大綱
- 英語(yǔ)考綱詞匯表3500詞
- 主題一:人文之美 第7課《天下第一大佛-樂(lè)山大佛》 課件
- 印度與阿拉伯的數(shù)學(xué)
- 會(huì)陰切開(kāi)傷口裂開(kāi)的護(hù)理查房
- 《鋼鐵是怎樣煉成的》選擇題100題(含答案)
- 2024年國(guó)新國(guó)際投資有限公司招聘筆試參考題庫(kù)含答案解析
- 食堂餐廳服務(wù)方案投標(biāo)方案(技術(shù)標(biāo))
- Creo-7.0基礎(chǔ)教程-配套課件
評(píng)論
0/150
提交評(píng)論