模糊PID控制的C程序

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

//e:[-3,3]ec:[-3,3]kp:[-0.3,0.3]#includestdio.h#defineNB0#defineNM1#defineNS2#defineZO3#definePS4#definePM5#definePB6/*********************************************************/floatuf(floatx,floata,floatb,floatc);floatcuf(floatx,floata,floatb,floatc);floatufl(floatx,floata,floatb);floatcufl(floatx,floata,floatb);floatufr(floatx,floata,floatb);floatcufr(floatx,floata,floatb);floatufr(floatx,floata,floatb);floatcufr(floatx,floata,floatb);floatfand(floata,floatb);floatforr(floata,floatb);floatFuzzyKp(floate,floatec);//主程序voidmain(){floata,b,Kp;printf(TheEis:);scanf(%f,&a);printf(TheEcis:);scanf(%f,&b);Kp=FuzzyKp(a,b);printf(TheparameterKpis:%f\n\n,Kp);floatFuzzyKp(floate,floatec){floates[7];floatecs[7];/******模糊推理规则的可信度通过取小点运算得到*****/floatform[7][7];//(表X7)(隶属度表)inti,j;/*************求得的最大值赋给form[a][b]*********/inta=0,b=0;floatlsd;intp;floatdetkp;/**************************/intkp[7][7]={{PB,PB,PM,PS,PS,ZO,ZO},{PB,PB,PM,PS,PS,ZO,NS},{PM,PM,PM,PS,ZO,NS,NS},{PM,PM,PS,ZO,NS,NM,NM},{PS,PS,ZO,NS,NS,NM,NM},{PS,ZO,NS,NM,NM,NM,NB},{ZO,ZO,NM,NM,NM,NB,NB}};es[NB]=ufl(e,-3,-1);es[NM]=uf(e,-3,-2,0);es[NS]=uf(e,-3,-1,1);es[ZO]=uf(e,-2,0,2);es[PS]=uf(e,-1,1,3);es[PM]=uf(e,0,2,3);es[PB]=ufr(e,1,3);ecs[NB]=ufl(ec,-3,-1);//ececs[NM]=uf(ec,-3,-2,0);ecs[NS]=uf(ec,-3,-1,1);ecs[ZO]=uf(ec,-2,0,2);ecs[PS]=uf(ec,-1,1,3);ecs[PM]=uf(ec,0,2,3);ecs[PB]=ufr(ec,1,3);for(i=0;i7;i++){floatw,h,r;for(j=0;j7;j++){h=es[i];r=ecs[j];w=fand(h,r);form[i][j]=w;}}for(i=0;i7;i++){for(j=0;j7;j++){if(form[a][b]form[i][j]){a=i;b=j;}}}lsd=form[a][b];//es和ecs最值中的最大值p=kp[a][b];if(p==NB)detkp=cufl(lsd,-0.3,-0.1);elseif(p==NM)detkp=cuf(lsd,-0.3,0.2,0);elseif(p==NS)detkp=cuf(lsd,-0.3,-0.1,0.1);elseif(p==ZO)detkp=cuf(lsd,-0.2,0,0.2);elseif(p==PS)detkp=cuf(lsd,-0.1,0.1,0.3);elseif(p==PM)detkp=cuf(lsd,0,0.2,0.3);elseif(p==PB)detkp=cufr(lsd,0.1,0.3);returndetkp;}/**************************************以下为附属子函数*//**************求隶属度(三角形)模糊化处理***************/floatuf(floatx,floata,floatb,floatc){if(x=a)return(0);elseif((ax)&&(x=b))return((x-a)/(b-a));elseif((bx)&&(x=c))return((c-x)/(c-b));elseif(xc)return(0);}/****************三角形反模糊化处理(最大隶属度法)**********************/floatcuf(floatx,floata,floatb,floatc){floaty,z;z=(b-a)*x+a;y=c-(c-b)*x;return(y+z)/2;}/*****************梯形(左)求隶属度模糊化*******************/floatufl(floatx,floata,floatb){if(x=a)return1;elseif((ax)&&(x=b))return(b-x)/(b-a);elseif(xb)return0;}/*******************梯形反模糊化***********************/floatcufl(floatx,floata,floatb){returnb-(b-a)*x;}/*****************梯形(右)求隶属度模糊化*******************/floatufr(floatx,floata,floatb){if(x=a)return0;if((ax)&&(xb))return(x-a)/(b-a);if(x=b)return1;}/*******************梯形反模糊化***********************/floatcufr(floatx,floata,floatb){return(b-a)*x+a;}/*******************求交集***********************/floatfand(floata,floatb){return(ab)?a:b;//(返回a,b中较小值)}/*******************求并集***********************/floatforr(floata,floatb){return(ab)?b:a;}

1 / 5
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功