《算机控制技术与系统课程设计报告--DDC单回路PID闭环控制系统的设计及实时仿真.docx》由会员分享,可在线阅读,更多相关《算机控制技术与系统课程设计报告--DDC单回路PID闭环控制系统的设计及实时仿真.docx(17页珍藏版)》请在优知文库上搜索。
1、课程设计报告(20132014年度第2学期)名称:计算机控制技术与系统题目:DDC单回路PID闭环控制系统的设计及实时仿真PID飞升曲线绘制程序#include#include#include#include*理想PID参数定义*/*比例增益1.0*/*采样周期1.0$*/*积分时间10.0s*/*微分时间5.0s*/*惯性时间0.0s*/*增量型PID运算系数*/#defineKpl1.0#defineTl1#defineTil10.0#defineTdl5.0#defineTfl0#defineCll(Tfl(Tl+Tfl)NdefineC21(Kpl*Tl*(l+Tl/TiI+TdlTl
2、)(Tl+Tfl)#defineC31(0-Kpl*Tl*(l+2*TdlTl)(Tl+Tfl)#defineC41(Kpl*Tdl(Tl+Tfl)/*实际PID参数定义*/*比例增益1.0*/*采样周期LOs*/*积分时间IOQs*/*微分时间5.0s*/*惯性时间2.0s*/*增量型PlD运算系数*/defineKp21.0#defineT21.0#defineTi210.0#defineTd25.0#defineTf22ttdefineC12(Tf2(T2+Tf2)defineC22(Kp2*T2*(l+T2Ti2+Td2T2)(T2+Tf2)#defineC32(O-KP2*T2*(l
3、+2*Td2T2)(T2+Tf2)#defineC42(Kp2*Td2(T2+Tf2)/*坐标轴定义*/defineox40#defineoy440#definexx620ttdefinexy440#defineIenx580#defineIeny400#defineyx40ttdefineyy20*定义作图区域,/#defineleft20Adefinetop20Sdefineright620definebottom460*坐标轴注释*/Adefinextetlx450Sdefinextetly450defineytextlx10ftdefineytextIy65Adefinextet261
4、0#definextext2y450#defineytext2x10#defineytext2y20*坐标子程序/voidDrawAxis(Void)i11ti;setbkcolor(7);setcolor(5);Iine(OX,oy,xx,xy);line(xx-5,xy-5,xx,y);Iine(XX,xy,xx-5,xy+5);Iine(OX,oy,yx,yy);line(y-5,yy+10,yx,yy);line(yx+5,yy+10,yx,yy);*原点横坐标*/*原点纵坐标*/*x轴顶点横坐标*/*x轴顶点纵坐标*/*横轴长*/*纵轴长*/*y轴顶点横坐标*/*y轴顶点纵坐标*/*
5、背景颜色*/*线条颜色*/*x-axis*/*画X轴箭头/*y-ais*/*画y轴箭头*/for(i=0;i51;i+)(line(o+10*i,oy,o+10*i,oy-10);line(ox+10*i+5,oox+10*i+5,oy-5);)for(i=l;i=10;i+)line(ox,oy-40*i,o+10,oy-40*i);/*标X轴刻度值*/outtextxy(ox+50*0-7,oy+20,0);/*刻度值值表示点*/outtextxy(ox+50*l-7,oy+20,5);outtexty(ox+50*2-7,oy+20,10);outtexty(o+50*3-7,oy+20
6、,15);outtety(ox+50*4-7,oy+20,20);outtexty(ox+50*5-7zoy+20,25);outtexty(ox+50*6-7,oy+20,30);outtexty(o+50*7-7,oy+20,35);outtexty(o+50*8-7,oy+20,40);outtety(ox+50*9-7,oy+20,45);outtexty(ox+50*10-7,oy+20,50);/*标y轴刻度值*/outtety(o-20,oy-401,1);outtexty(o-20,oy-40*2,2);outtexty(o-20,oy-403,3);outtexty(o-20
7、,oy-40*4,4);outtexty(o-20,oy-40*5,5);outtexty(o-20,oy-40*6,6);outtextxy(ox-20,oy-407,7);outtexty(o-20,oy-408,8);outtety(o-20,oy-40*9,9);outtextxy(ox-20,oy-40*10,10);settextstyle(SMALL_FONTHORIZ_DIR,5);/*坐标轴坐标量注释*/OUtteXtXy(XteXtlX,XtextlyJTime);outtextxy(xtext2x,xtet2ts);SetteXtStyIe(SMALL_F0N1VERT_
8、DIR,5);oUttextxy(ytextlx,ytextly,Theoutput(Response);outtextxy(ytext2xzytet2UV);)voidlnitial_Sys(void)*初始化*/intgdriver=DETECTzgmode;initgraph(&gdriver,&gmode,C:TC20HtcBGI);/*pD运算*L*/floatPIDl(floatNew,floatSp)*理想*/staticfloatel3=0.0,0.0,0.0,ul=0.0,dul=0.0;el2=el(l);*数据更新*/ell=el(01;elO=Sp-New;dul=Cl
9、l*dul+C21*el0+C31*ell+C41*el2;*PID运算*/ul=ul+dul;returnul;floatPID2(floatNewJIoatSP)*实际*/staticfloate23=0.0,0.0,0.0,u2=0.0,du2=0.0;e22=e2l);*数据更新*/e2l=e20;e20=Sp-New;du2=C12*du2+C22*e20+C32e2l+C42*e22;u2=u2+du2;returnu2;)*绘图*/voiddraw(floata)intk=5;*x轴间距*/intl,yl,x,y;inti;xO=O;y0=(int)(a0*25);*规整*/fo
10、r(i=l;i100;i+)xl=x+k;yl=(int)(ai*25);delay(100);setcolor(14);/*标注*/settextstyle(SMALL_F0NT,H0RIZ_DIR,5);outtextxy(600,20,);Iine(ox+x0,oy-y0,ox+xlzoy-y0);line(ox+xlzoy-yO,ox+xl,oy-yl);setcolor(14);outtextxy(620,20,Sp);line(ox+xO,oy-25,ox+xl,oy-25);O=xl;/*数据更新*/y=yi;)voiddraw2(floatb)intk=5;*x轴间距*/int
11、xlzyl,x,y;inti;xO=O;y0=(int)(b0*25);for(i=l;i100;i+)l=x+k;yl=(int)(bi*25);delay(100);setcolor(6);OUttextXy(600,40,U);Iine(ox+x0,oy-y0,o+xl,oy-y0);line(ox+xl,oy-yO,o+l,oy-yl);setcolor(6);OUtteXtXy(620,40,Sp);line(o+x0,oy-25,ox+xl,oy-25);O=xl;*数据更新*/y=yi;)*主程序*/voidmain(void)floata100;floatb100;inti;f
12、or(i=0;i100;i+)(ai=PIDl(O.O,lO);)lnitial-Sys();DrawAxis();draw(a);for(i=0;i100;i+)(bi=PID2(0.040);)draw2(b);)getch();实际采样显示控制程序/*头文件定义/#includestdio.h#includemath.h#includegraphics.ht,*forgraphdriverinstalling,onlycanbecalledinTurboC*/#includestring.h#includedos.h#includebios.h#includeconio.h*中断程序头文
13、件*/#includestdlib.h#includeio.h#includemath.h*按键地址定义7doublekey_ESC=0x011b;*definecannotsuitthelengthofbioskey*/doublekey-E=0xl265;doublekey-A=0xle61;doublekey-H=02368;doublekey-U=01675;doublekey-D=02064;doublekey_l=0x1769;doublekey-P=0xl970;doublekey_up=0x4800;doublekey_down=0x5000;doublekeyJeft=04b00;doublekey-right=04d00;doublekey-pgup=0x49;doublekey_pgdown=0x5