算機(jī)控制技術(shù)與系統(tǒng)課程設(shè)計(jì)報(bào)告-DDC單回路PID閉環(huán)控制系統(tǒng)的設(shè)計(jì)及實(shí)時(shí)仿真_第1頁(yè)
算機(jī)控制技術(shù)與系統(tǒng)課程設(shè)計(jì)報(bào)告-DDC單回路PID閉環(huán)控制系統(tǒng)的設(shè)計(jì)及實(shí)時(shí)仿真_第2頁(yè)
算機(jī)控制技術(shù)與系統(tǒng)課程設(shè)計(jì)報(bào)告-DDC單回路PID閉環(huán)控制系統(tǒng)的設(shè)計(jì)及實(shí)時(shí)仿真_第3頁(yè)
算機(jī)控制技術(shù)與系統(tǒng)課程設(shè)計(jì)報(bào)告-DDC單回路PID閉環(huán)控制系統(tǒng)的設(shè)計(jì)及實(shí)時(shí)仿真_第4頁(yè)
算機(jī)控制技術(shù)與系統(tǒng)課程設(shè)計(jì)報(bào)告-DDC單回路PID閉環(huán)控制系統(tǒng)的設(shè)計(jì)及實(shí)時(shí)仿真_第5頁(yè)
已閱讀5頁(yè),還剩12頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

課程設(shè)計(jì)報(bào)告(2013--2014年度第2學(xué)期)名稱:計(jì)算機(jī)控制技術(shù)與系統(tǒng)題目:DDC單回路PID閉環(huán)控制系統(tǒng)的設(shè)計(jì)及實(shí)時(shí)仿真PID飛升曲線繪制程序#include<graphics.h>#include<stdio.h>#include<dos.h>#include<conio.h>/*理想PID參數(shù)定義*/#defineKp11.0 /*比例增益1.0*/#defineT11 /*采樣周期1.0s*/#defineTi110.0 /*積分時(shí)間10.0s*/#defineTd15.0 /*微分時(shí)間5.0s*/#defineTf10 /*慣性時(shí)間0.0s*/#defineC11(Tf1/(T1+Tf1)) /*增量型PID運(yùn)算系數(shù)*/#defineC21(Kp1*T1*(1+T1/Ti1+Td1/T1)/(T1+Tf1))#defineC31(0-Kp1*T1*(1+2*Td1/T1)/(T1+Tf1))#defineC41(Kp1*Td1/(T1+Tf1))/*實(shí)際PID參數(shù)定義*/#defineKp21.0 /*比例增益1.0*/#defineT21.0 /*采樣周期1.0s*/#defineTi210.0 /*積分時(shí)間10.0s*/#defineTd25.0 /*微分時(shí)間5.0s*/#defineTf22 /*慣性時(shí)間2.0s*/#defineC12(Tf2/(T2+Tf2)) /*增量型PID運(yùn)算系數(shù)*/#defineC22(Kp2*T2*(1+T2/Ti2+Td2/T2)/(T2+Tf2))#defineC32(0-Kp2*T2*(1+2*Td2/T2)/(T2+Tf2))#defineC42(Kp2*Td2/(T2+Tf2))/*坐標(biāo)軸定義*/#defineox40 /*原點(diǎn)橫坐標(biāo)*/#defineoy440 /*原點(diǎn)縱坐標(biāo)*/#definexx620 /*x軸頂點(diǎn)橫坐標(biāo)*/#definexy440 /*x軸頂點(diǎn)縱坐標(biāo)*/#definelenx580/*橫軸長(zhǎng)*/#defineleny400/*縱軸長(zhǎng)*/#defineyx40 /*y軸頂點(diǎn)橫坐標(biāo)*/#defineyy20 /*y軸頂點(diǎn)縱坐標(biāo)*//*定義作圖區(qū)域*/#defineleft20#definetop20#defineright620#definebottom460/*坐標(biāo)軸注釋*/#definextext1x450#definextext1y450#defineytext1x10#defineytext1y65#definextext2x610#definextext2y450#defineytext2x10#defineytext2y20/*坐標(biāo)子程序*/voidDrawAxis(void){inti;setbkcolor(7);/*背景顏色*/setcolor(5);/*線條顏色*/line(ox,oy,xx,xy); /*x_axis*/line(xx-5,xy-5,xx,xy); /*畫(huà)x軸箭頭*/line(xx,xy,xx-5,xy+5);line(ox,oy,yx,yy); /*y_axis*/line(yx-5,yy+10,yx,yy); /*畫(huà)y軸箭頭*/line(yx+5,yy+10,yx,yy);for(i=0;i<51;i++){line(ox+10*i,oy,ox+10*i,oy-10);/*刻度值值表示點(diǎn)*/line(ox+10*i+5,oy,ox+10*i+5,oy-5);} for(i=1;i<=10;i++) line(ox,oy-40*i,ox+10,oy-40*i);/*標(biāo)x軸刻度值*/outtextxy(ox+50*0-7,oy+20,"0");outtextxy(ox+50*1-7,oy+20,"5");outtextxy(ox+50*2-7,oy+20,"10");outtextxy(ox+50*3-7,oy+20,"15");outtextxy(ox+50*4-7,oy+20,"20");outtextxy(ox+50*5-7,oy+20,"25");outtextxy(ox+50*6-7,oy+20,"30");outtextxy(ox+50*7-7,oy+20,"35");outtextxy(ox+50*8-7,oy+20,"40");outtextxy(ox+50*9-7,oy+20,"45");outtextxy(ox+50*10-7,oy+20,"50");/*標(biāo)y軸刻度值*/ outtextxy(ox-20,oy-40*1,"1"); outtextxy(ox-20,oy-40*2,"2"); outtextxy(ox-20,oy-40*3,"3"); outtextxy(ox-20,oy-40*4,"4"); outtextxy(ox-20,oy-40*5,"5"); outtextxy(ox-20,oy-40*6,"6"); outtextxy(ox-20,oy-40*7,"7"); outtextxy(ox-20,oy-40*8,"8"); outtextxy(ox-20,oy-40*9,"9"); outtextxy(ox-20,oy-40*10,"10");settextstyle(SMALL_FONT,HORIZ_DIR,5); /*坐標(biāo)軸坐標(biāo)量注釋*/outtextxy(xtext1x,xtext1y,"Time");outtextxy(xtext2x,xtext2y,"t/s");settextstyle(SMALL_FONT,VERT_DIR,5);outtextxy(ytext1x,ytext1y,"Theoutput(Response)");outtextxy(ytext2x,ytext2y,"U/V");}voidInitial_Sys(void)/*初始化*/{intgdriver=DETECT,gmode;initgraph(&gdriver,&gmode,"C:\TC20H\tc\BGI");}/**********************PID運(yùn)算***********************/floatPID1(floatNew,floatSp)/*理想*/{staticfloate1[3]={0.0,0.0,0.0},u1=0.0,du1=0.0;e1[2]=e1[1]; /*數(shù)據(jù)更新*/e1[1]=e1[0];e1[0]=Sp-New;du1=C11*du1+C21*e1[0]+C31*e1[1]+C41*e1[2]; /*PID運(yùn)算*/u1=u1+du1;returnu1;}floatPID2(floatNew,floatSp)/*實(shí)際*/{staticfloate2[3]={0.0,0.0,0.0},u2=0.0,du2=0.0;e2[2]=e2[1]; /*數(shù)據(jù)更新*/e2[1]=e2[0];e2[0]=Sp-New;du2=C12*du2+C22*e2[0]+C32*e2[1]+C42*e2[2];u2=u2+du2;returnu2;}/*********************繪圖**************/voiddraw(floata[]){intk=5; /*x軸間距*/intx1,y1,x0,y0;inti;x0=0;y0=(int)(a[0]*25);/*規(guī)整*/for(i=1;i<100;i++){x1=x0+k;y1=(int)(a[i]*25);delay(100);setcolor(14);/*標(biāo)注*/settextstyle(SMALL_FONT,HORIZ_DIR,5);outtextxy(600,20,"U");line(ox+x0,oy-y0,ox+x1,oy-y0);line(ox+x1,oy-y0,ox+x1,oy-y1);setcolor(14);outtextxy(620,20,"Sp");line(ox+x0,oy-25,ox+x1,oy-25);x0=x1; /*數(shù)據(jù)更新*/y0=y1;}}voiddraw2(floatb[]){intk=5; /*x軸間距*/intx1,y1,x0,y0;inti;x0=0;y0=(int)(b[0]*25);for(i=1;i<100;i++){x1=x0+k;y1=(int)(b[i]*25);delay(100);setcolor(6);outtextxy(600,40,"U'");line(ox+x0,oy-y0,ox+x1,oy-y0);line(ox+x1,oy-y0,ox+x1,oy-y1);setcolor(6);outtextxy(620,40,"Sp'");line(ox+x0,oy-25,ox+x1,oy-25);x0=x1; /*數(shù)據(jù)更新*/y0=y1;}}/*******************主程序********************/voidmain(void){floata[100];floatb[100];inti;for(i=0;i<100;i++){a[i]=PID1(0.0,1.0);}Initial_Sys();DrawAxis();draw(a);for(i=0;i<100;i++){b[i]=PID2(0.0,1.0);}draw2(b);}getch();實(shí)際采樣顯示控制程序/*------------頭文件定義----------------*/#include"stdio.h"#include"math.h"#include"graphics.h" /*forgraphdriverinstalling,onlycanbecalledinTurboC*/#include"string.h"#include"dos.h"#include"bios.h"#include"conio.h" /*-------中斷程序頭文件--------------*/#include"stdlib.h"#include"io.h"#include"math.h"/*---------------按鍵地址定義-------------------*/doublekey_ESC=0x011b; /*definecannotsuitthelengthofbioskey*/doublekey_E=0x1265;doublekey_A=0x1e61;doublekey_H=0x2368;doublekey_U=0x1675;doublekey_D=0x2064;doublekey_I=0x1769;doublekey_P=0x1970;doublekey_up=0x4800;doublekey_down=0x5000;doublekey_left=0x4b00;doublekey_right=0x4d00;doublekey_pgup=0x4900;doublekey_pgdown=0x5100;/*---------------PLCD780基地址定義-------------*/#defineBASE0x220 /*pleaselookupinPCL812PGdocument*/#defineREG1/*---------------定義繪圖坐標(biāo)---------------*/#defineox40/*-----原點(diǎn)橫坐標(biāo)--------*/#defineoy240/*------原點(diǎn)縱坐標(biāo)-------*/#definexx600/*------x軸頂點(diǎn)橫坐標(biāo)---*/#definexy240/*-----x軸頂點(diǎn)縱坐標(biāo)---*/#defineyx40/*-----y軸頂點(diǎn)橫坐標(biāo)-----*/#defineyy40/*------y軸頂點(diǎn)縱坐標(biāo)----*//*-------------PID參數(shù)定義-----------------*/floatKp=1.2;floatTi=30.0;/*9,0.6*/floatTd=4.5;floatTf0=5;floatTf=5;/*---------理想PID參數(shù)--------------*/floatT=0.2; /*---------采樣時(shí)間間隔-------------*/floatad,e;floatu=0.0;floatpv=0.0;floatsp=0.0;charA_H='H'; /*-------------PID手自動(dòng)狀態(tài)標(biāo)志------------*/charmanu;intkey=0;inttime_counter=0; /*----------------中斷次數(shù)-------------*/intspt=0; /*----------------采樣計(jì)數(shù)--------------*/intst_time=500; /*----------------采樣次數(shù)總和(x軸范圍)------------------*/intround=0;/*------------------函數(shù)聲明----------------------*/voidinterrupt(*fadd1C)(void);/*-----------申明中斷向量fadd1C-----------*/voidinterruptINT_1C(void); /*-----------8259中斷控制函數(shù)-------------*/intscankey();/*-----------------繪圖初始化----------------*/voidInitial_Sys(void);voidaxis(intround1);voidDrawline(intround1,intcj,floatpv1,floatsp1,floatu1,floate1);/*-----------PID設(shè)置及運(yùn)算------------*/voidPIDset(void);floatPID(floatsp1,floatpv1,floatKp1,floatTi1,floatTd1,floatTf1,charA_H1,floatT1);/*-----------程序?qū)崿F(xiàn)負(fù)增益三階慣性環(huán)節(jié)------------*/floatObject(floatu1,floatT1);floatAD_convert(unsignedcharchannal); /*----------------A/D采樣子函數(shù)-------------*/voidDA_convert(floatu); /*----------------D/A采樣子函數(shù)-------------*/floatDelayAction(floaty0);/*displayanddrawing*//*initiategraphdisplay*/voidInitial_Sys(void){ intGraphDriver; intGraphMode; detectgraph(&GraphDriver,&GraphMode);/*----------------------確定圖形驅(qū)動(dòng)程序和模式----------------*/ initgraph(&GraphDriver,&GraphMode,"C:\\TC201E\\BGI");/*-----------初始化圖形系統(tǒng)(前兩項(xiàng)為指針,后一項(xiàng)為路徑)------------*/}/*drawbasiccoordinateaxis*/voidaxis(intround1){ inti; chars[3];/*-----------注意刻度位置*/ Initial_Sys(); setbkcolor(15); /*white0/black15*/ setcolor(9); /*linghtblue*/ printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); printf("-----NOTE:PID-P/I,Mode-A/H,sp/u-U/D,Kp-up/dn,Ti-left/right,Td-pgup/pgdn-----"); rectangle(10,35,630,465); /*-------------繪制矩形,對(duì)角頂點(diǎn)坐標(biāo)(10,35),(630,465)------------*/ line(ox,oy,xx,xy); /*---------------畫(huà)y軸,始點(diǎn)坐標(biāo)(ox,oy),終點(diǎn)坐標(biāo)(xx,xy)---------------*/ line(xx-5,xy-5,xx,xy); line(xx,xy,xx-5,xy+5); line(ox,oy+200,yx,yy); line(yx-5,yy+5,yx,yy); line(yx+5,yy+5,yx,yy); settextstyle(2,1,5); /*------------設(shè)置文本屬性:字體Smallfont,橫排,大小5----------------*/ outtextxy(20,150,"TheOutput(Response)"); outtextxy(20,40,"U(t)/V");/*------------輸出文本----------------*/ settextstyle(2,0,5); outtextxy(300,455,"Time"); outtextxy(590,455,"t/sec"); setlinestyle(1,0,1); /*-------------------設(shè)置畫(huà)線類型(dotline,none,width)-------------*/ for(i=-5;i<=5;i++) /*----eachinportstartingposition*/ line(ox,oy-40*i,ox+500,oy-40*i); for(i=-5;i<=5;i++) { sprintf(s,"%d",i); outtextxy(ox-8,oy-40*i,s); } for(i=1;i<=500/50;i++) /*scale*/ line(ox+50*i,oy+200,ox+50*i,oy-200); /*1/T=10,thatis10px=1sec*/ for(i=1;i<=500/10;i++) line(ox+10*i,oy,ox+10*i,oy-10); setlinestyle(0,0,1); /*realline,none,width*/ for(i=0;i<=10;i++) { sprintf(s,"%d",10*i+100*round1); if(round1==0) outtextxy(ox-8+i*50,oy+2,s); elseif(round1>0) outtextxy(ox-12+i*50,oy+2,s); }}/*line-drawingandnotes*/voidDrawline(intround1,intcj1,floatpv1,floatsp1,floatu1,floate1){ staticintcj_0=0,cj_1=0,pv_0=0.0,pv_1=0.0,sp_0=0.0,sp_1=0.0,u_0=0.0,u_1=0.0,e_0=0.0,e_1=0.0; cj_1=cj1-500*round1; /*Xcoordinate*/ if(cj_1==0) cj_0=0; pv_1=(int)(pv1*40); sp_1=(int)(sp1*40); u_1=(int)(u1*40); e_1=(int)(e1*40); setcolor(2); /*green*/ line(ox+cj_0,oy-pv_0,ox+cj_1,oy-pv_1); outtextxy(590,40,"pv"); setcolor(8); /*darkgray*/ line(ox+cj_0,oy-sp_0,ox+cj_1,oy-sp_1); outtextxy(590,55,"sp"); setcolor(3); /*cyan*/ line(ox+cj_0,oy-u_0,ox+cj_1,oy-u_1); outtextxy(590,70,"u"); setcolor(4); /*red*/ line(ox+cj_0,oy-e_0,ox+cj_1,oy-e_1); outtextxy(590,85,"e"); cj_0=cj_1; pv_0=pv_1; sp_0=sp_1; u_0=u_1; e_0=e_1;}/*resetinterruptcontroller*/voidinterruptINT_1C(void){ time_counter++; outportb(0x20,0x20);/*--------重置8259中斷控制器,表明中斷結(jié)束----------*/}/*keyboardinputdetection*/intscankey(void){ intkey0; key0=bioskey(1); /*----------查詢是否按下按鍵,按下則返回非零值-----------*/ if(key0!=0) key0=bioskey(0); /*---------返回按鍵鍵值--------*/ returnkey0;}/*------------------按鍵控制PID子程序--------------------*/voidPIDset(void){ key=scankey();/*------------------按鍵掃描----------------*/ if(A_H=='H') { if(key==key_up)/*--------手動(dòng)狀態(tài)通過(guò)按鍵↑↓改變比例增益kp----------*/ Kp+=0.2; elseif(key==key_down) Kp-=0.2; elseif(key==key_left)/*-------手動(dòng)狀態(tài)通過(guò)按鍵→←改變積分時(shí)間Ti-----------*/ Ti-=0.2; elseif(key==key_right) Ti+=0.2; elseif(key==key_pgup)/*------手動(dòng)狀態(tài)通過(guò)按鍵pguppgdn改變微分時(shí)間Td-----*/ Td+=0.2; elseif(key==key_pgdown) Td-=0.2; elseif(key==key_U) /*-------手動(dòng)狀態(tài)通過(guò)按鍵UD改變階躍輸出-------*/ manu='+'; elseif(key==key_D) manu='-'; } if(A_H=='A') { if(key==key_U)/*-----------自動(dòng)狀態(tài)按鍵UD改變?cè)O(shè)定值sp----------*/ sp+=1; if(key==key_D) sp-=1; } if(key==key_E||key==key_ESC)/*-----------按鍵ESCE控制程序退出----------*/ {closegraph();exit(1);} if(key==key_A) A_H='A';/*-----------手自動(dòng)標(biāo)志----------*/ if(key==key_H) A_H='H'; if(key==key_I) Tf=0;/*---------理想,實(shí)際PID標(biāo)志----------*/ if(key==key_P) Tf=Tf0;}/*---------------------配置PID模塊子程序--------------------*/floatPID(floatsp1,floatpv1,floatKp1,floatTi1,floatTd1,floatTf1,charA_H1,floatT1){intdeath=0.001,A=5,k=0; floatdelta_u,u0,C1,C2,C3,C4; staticfloate1,e2,u1,delta_u1; if(Kp1<0||Ti1<0||Td1<0) printf("error."); else { C1=Tf1/(T1+Tf1); C2=Kp1*T1*(1+T1/Ti1+Td1/T1)/(T1+Tf1); C3=-Kp1*T1*(1+2*Td1/T1)/(T1+Tf1); C4=Kp1*Td1/(T1+Tf1); if(A_H1=='A') /*--------------按下按鍵A,PID處于自動(dòng)狀態(tài)---------------*/ { e=pv1-sp1; if(abs(e)<death)return;/*----------死區(qū)---------------*/ if(fabs(e)>A) k=10000;/*----------------積分分離算法(偏差較大不積分)---------------*/ else k=1; delta_u=C1*delta_u1+C2*e+C3*e1+C4*e2; u0=u1+delta_u; if(abs(u0)>5)/*------------抗積分飽和-------------*/ k=1;Ti=Ti*k; e2=e1; e1=e; delta_u1=delta_u; u1=u0; returnu0; } elseif(A_H1=='H') /*--------------按下按鍵H,PID處于手動(dòng)狀態(tài)---------------*/ { if(manu=='+') u+=1; if(manu=='-') u-=1; u1=u; e=0; sp1=pv1; /*PID處于手動(dòng)狀態(tài),設(shè)定值跟蹤PV*/sp=pv1; e1=0; e2=0; delta_u1=0; returnu; } }}/*三階負(fù)增益對(duì)象*/floatObject(floatu1,floatT1){/*G(s)=-3/(4.7s+1)^3,K=-3,Tp1=Tp2=Tp3=4.7*/ staticfloaty1,y2,y3; floaty;y=(103.82*y3-(311.469+66.27*T1)*y2+(311.469+132.54*T1+14.1*T1*T1)*y1-3*T1*T1*T1*u1)/(103.82+66.27*T1+14.1*T1*T1+T1*T1*T1); y3=y2; y2=y1;y1=y; returny;}/*mainprogram*/voidmain(void){ disable();/*----------------關(guān)閉中斷------------*/ fadd1C=getvect(0x1C);/*------取得中斷向量入口地址------------*/ setvect(0x1C,INT_1C);/*----------設(shè)置中斷向量入口------------*/ enable();/*----------------開(kāi)啟中斷------------*/drawcycle: axis(round); while(spt<st_time*(round+1)) { if((spt*T)<(time_counter/18.2))/*----------------定時(shí)輸出,定時(shí)采樣------------*/ { ad=AD_convert(0); /*----------------對(duì)二階慣性環(huán)節(jié)輸出進(jìn)行采樣-------*/ pv=DelayAction(ad);/*----------------采樣值進(jìn)行延時(shí)--------------*/ PIDset(); u=PID(sp,pv,Kp,Ti,Td,Tf,A_H,T); DA_convert(u); /*pv=Object(u,T);*/ /*pv=DelayAction(pv);*/ Drawline(round,spt,pv,sp,u,e);/*--------------繪制過(guò)度過(guò)程曲線----------*/ manu=0; /*statusbar,atthetopofthescreen*/ gotoxy(1,1);/*-------------設(shè)置光標(biāo)位置(1,1)------------------*/ if(Tf==0) printf("IdealPID,Mode:%c\t\tKp=%.2f,Ti=%.2f,Td=%.2f\t\n",A_H,Kp,Ti,Td); elseif(Tf>0) printf("ParallalPID,Mode:%c\tKp=%.2f,Ti=%.2f,Td=%.2f\t\n",A_H,Kp,Ti,Td); elseprintf("

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論