最近在写一个模糊PID控制的
matlab m程序(原程序如下,)但是我运行的时候出现了如下这种错误:
- ??? Error using ==> close at 82 Specified window does not exist.
-
- Error in ==> Fuzzypidm at 1
- close all;
- ??? Attempted to access rules(1,6); index out of bounds because
- size(rules)=[49,5].
-
- Error in ==> setfis at 103
- fis.rule(i).weight=rules(i, numInputs+numOutputs+1);
-
- Error in ==> addrule at 44
- fis=setfis(fis,'ruleList',newRuleList);
-
- Error in ==> Fuzzypidm at 97
- a=addrule(a,rulelist);
复制代码
本人新手,不知道哪里有问题,请地里各位前辈帮忙看看程序。不甚感激!
- clear all;close all;
-
- a=newfis('fuzzpidm');
-
- a=addvar(a,'input','e',[-3,3]);
- a=addmf(a,'input',1,'NB','trimf',[-3,-3,-2]);
- a=addmf(a,'input',1,'NM','trimf',[-3,-2,-1]);
- a=addmf(a,'input',1,'NS','trimf',[-2,-1,0]);
- a=addmf(a,'input',1,'Z','trimf',[-1,0,1]);
- a=addmf(a,'input',1,'PS','trimf',[0,1,2]);
- a=addmf(a,'input',1,'PM','trimf',[1,2,3]);
- a=addmf(a,'input',1,'PB','trimf',[2,3,3]);
-
- a=addvar(a,'input','ec',[-3,3]);
- a=addmf(a,'input',2,'NB','trimf',[-3,-3,-2]);
- a=addmf(a,'input',2,'NM','trimf',[-3,-2,-1]);
- a=addmf(a,'input',2,'NS','trimf',[-2,-1,0]);
- a=addmf(a,'input',2,'Z','trimf',[-1,0,1]);
- a=addmf(a,'input',2,'PS','trimf',[0,1,2]);
- a=addmf(a,'input',2,'PM','trimf',[1,2,3]);
- a=addmf(a,'input',2,'PB','trimf',[2,3,3]);
-
- a=addvar(a,'output','kp',[0,3]);
- a=addmf(a,'output',1,'Z','trimf',[0,0,1]);
- a=addmf(a,'output',1,'PS','trimf',[0,1,2]);
- a=addmf(a,'output',1,'PM','trimf',[1,2,3]);
- a=addmf(a,'output',1,'PB','trimf',[2,3,3]);
-
- a=addvar(a,'output','ki',[0,3]);
- a=addmf(a,'output',2,'Z','trimf',[0,0,1]);
- a=addmf(a,'output',2,'PS','trimf',[0,1,2]);
- a=addmf(a,'output',2,'PM','trimf',[1,2,3]);
- a=addmf(a,'output',2,'PB','trimf',[2,3,3]);
-
- a=addvar(a,'output','kd',[0,3]);
- a=addmf(a,'output',3,'Z','trimf',[0,0,1]);
- a=addmf(a,'output',3,'PS','trimf',[0,1,2]);
- a=addmf(a,'output',3,'PM','trimf',[1,2,3]);
- a=addmf(a,'output',3,'PB','trimf',[2,3,3]);
-
- rulelist=[1 1 6 4 5;
- 1 2 5 5 6;
- 1 3 6 6 7;
- 1 4 6 7 5;
- 1 5 6 6 5;
- 1 6 5 5 6;
- 1 7 6 4 7;
-
- 2 1 7 4 5;
- 2 2 6 5 5;
- 2 3 7 7 6;
- 2 4 7 7 6;
- 2 5 7 7 4;
- 2 6 6 5 5;
- 2 7 5 4 5;
-
- 3 1 7 4 5;
- 3 2 6 4 4;
- 3 3 7 7 4;
- 3 4 7 7 5;
- 3 5 7 7 6;
- 3 6 6 4 4;
- 3 7 5 4 5;
-
- 4 1 7 4 7;
- 4 2 6 4 7;
- 4 3 7 7 5;
- 4 4 4 7 5;
- 4 5 7 7 5;
- 4 6 6 4 5;
- 4 7 5 4 4;
-
- 5 1 7 4 4;
- 5 2 6 4 5;
- 5 3 7 7 6;
- 5 4 7 7 4;
- 5 5 7 7 5;
- 5 6 6 4 5;
- 5 7 5 4 5;
-
- 6 1 7 4 5;
- 6 2 6 5 5;
- 6 3 7 7 5;
- 6 4 7 7 5;
- 6 5 7 7 5;
- 6 6 6 5 6;
- 6 7 5 4 5;
-
- 7 1 6 4 7;
- 7 2 5 5 7;
- 7 3 6 6 5;
- 7 4 6 7 5;
- 7 5 6 6 7;
- 7 6 5 5 7;
- 7 7 6 4 5];
-
- a=addrule(a,rulelist);
- a1=setfis(a,'DefuzzMethod','mom');%Defuzzy
- writefis(a1,'fuzzpidm');
-
- a=readfis('fuzzpidm');
-
- %PID controller
- ts=10;
- sys=tf(2,[144,1],'inputdelay',30);%
- dsys=c2d(sys,ts,'zoh');
- [num,den]=tfdata(dsys,'v');
-
- u_1=0.0;u_2=0.0;u_3=0.0;u_4=0.0;
- y_1=0.0;
- x=[0,0,0]';
-
- error_1=0;
- e_1=0.0;
- ec_1=0.0;
-
- kp0=2.88;
- kd0=0.048;
- ki0=43.2;
复制代码
%看
论坛上加zero限定值。?也不知道这里加的对不对,但是如果不加的话,for循环里面的以下变量就会出现warning:说变量的值会随着循环而变化,考虑以下prealloca
ting 什么的...
- time=zero(500);
- rin=zero(500);
- kp=zero(500);
- ki=zero(500);
- kd=zero(500);
- u=zero(500);
- yout=zero(500);
- error=zero(500);
-
- for k=1:1:500;
- time(k)=k*ts;
-
- rin(k)=1;
- %using fuzzy inference to tunning PID
- k_pid=evalfis([e_1,ec_1],a);
- kp(k)=k_pid(1);
- ki(k)=k_pid(2);
- kd(k)=k_pid(3);
- u(k)=kp(k)*x(1)+kd(k)*x(2)+10.5*ki(k)*x(3);
-
- yout(k)=-den(2)*y_1+num(2)*u_4;
- error(k)=rin(k)-yout(k);
-
- u_4=u_3;
- u_3=u_2;
- u_2=u_1;
- u_1=u(k);
-
-
- y_1=yout(k);
-
- x(1)=error(k);
- x(2)=error(k)-error_1;
- x(3)=x(3)+error(k);
-
- e_1=x(1);
- ec_1=x(2);
-
- error_2=error_1;
- error_1=errpr(k);
- end
-
- showrule(a)
- figure(1);plot(time,rin,'b',time,yout,'r');
- xlabel('time(s)');ylabel('rin,yout');
- figure(2);plot(time,error,'r');
- xlabel('time(s)');ylabel('error');
- figure(3);plot(time,u,'r');
- xlabel('time(s)');ylabel('u');
- figure(4);plot(time,kp,'r');
- xlabel('time(s)');ylabel('kp');
- figure(5);plot(time,ki,'r');
- xlabel('time(s)');ylabel('ki');
- figure(6);plot(time,kd,'r');
- xlabel('time(s)');ylabel('kd');
- figure(7);plotmf(a,'input',1);
- figure(8);plotmf(a,'input',2);
- figure(9);plotmf(a,'output',1);
- figure(10);plotmf(a,'output',2);
- figure(11);plotmf(a,'output',3);
- plotfis(a);
- fuzzy fuzzpidm.fis
复制代码
谢谢你的回答
可是改了,还是不行。。。
??? Error using ==> parsrule at 181
Output MF index is too high
Error in ==> readfis at 231
out=parsrule(out,txtRuleList,'indexed');
Error in ==> Fuzzypidm at 102
a=readfis('fuzzpidm');
一周热门 更多>