模糊PID控制的MATLAB仿真代码.txt资料文档下载
《模糊PID控制的MATLAB仿真代码.txt资料文档下载》由会员分享,可在线阅读,更多相关《模糊PID控制的MATLAB仿真代码.txt资料文档下载(5页珍藏版)》请在冰豆网上搜索。
![模糊PID控制的MATLAB仿真代码.txt资料文档下载](https://file1.bdocx.com/fileroot1/2022-10/7/1cd64711-f33a-4697-a427-6ec220ef566b/1cd64711-f33a-4697-a427-6ec220ef566b1.gif)
NS'
[-3,-1,1]);
Z'
[-2,0,2]);
PS'
[-1,1,3]);
PM'
[0,2,3]);
PB'
smf'
[1,3]);
ec'
%Parameterec
2,'
output'
kp'
[-0.3,0.3]);
%Parameterkp
[-0.3,-0.1]);
[-0.3,-0.2,0]);
[-0.3,-0.1,0.1]);
[-0.2,0,0.2]);
[-0.1,0.1,0.3]);
[0,0.2,0.3]);
[0.1,0.3]);
ki'
[-0.06,0.06]);
%Parameterki
[-0.06,-0.02]);
[-0.06,-0.04,0]);
[-0.06,-0.02,0.02]);
[-0.04,0,0.04]);
[-0.02,0.02,0.06]);
[0,0.04,0.06]);
[0.02,0.06]);
kd'
%Parameterkp
3,'
rulelist=[1171511;
1271311;
1362111;
1462111;
1553111;
1644211;
1744511;
2171511;
2271311;
2362111;
2453211;
2553211;
2644311;
2734411;
3161411;
3262311;
3363211;
3453211;
3544311;
3635311;
3735411;
4162411;
4262311;
4353311;
4444311;
4535311;
4626311;
4726411;
5152411;
5253411;
5344411;
5435411;
5535411;
5626411;
5727411;
6154711;
6244511;
6335511;
6425511;
6526511;
6627511;
6717711;
7144711;
7244611;
7325611;
7426611;
7526511;
7617511;
7717711];
a=addrule(a,rulelist);
a=setfis(a,'
DefuzzMethod'
mom'
writefis(a,'
a=readfis('
%PIDController
ts=0.001;
sys=tf(5.235e005,[1,87.35,1.047e004,0]);
dsys=c2d(sys,ts,'
tustin'
[num,den]=tfdata(dsys,'
v'
u_1=0.0;
u_2=0.0;
u_3=0.0;
y_1=0;
y_2=0;
y_3=0;
x=[0,0,0]'
;
error_1=0;
e_1=0.0;
ec_1=0.0;
kp0=0.40;
kd0=1.0;
ki0=0.0;
fork=1:
1:
500
time(k)=k*ts;
rin(k)=1;
%UsingfuzzyinferencetotunningPID
k_pid=evalfis([e_1,ec_1],a);
kp(k)=kp0+k_pid
(1);
ki(k)=ki0+k_pid
(2);
kd(k)=kd0+k_pid(3);
u(k)=kp(k)*x
(1)+kd(k)*x
(2)+ki(k)*x(3);
ifk==300%Addingdisturbance(1.0vattime0.3s)
u(k)=u(k)+1.0;
end
ifu(k)>
=10
u(k)=10;
ifu(k)<
=-10
u(k)=-10;
yout(k)=-den
(2)*y_1-den(3)*y_2-den(4)*y_3+num
(1)*u(k)+num
(2)*u_1+num(3)*u_2+num(4)*u_3;
error(k)=rin(k)-yout(k);
%%%%%%%%%%%%%%ReturnofPIDparameters%%%%%%%%%%%%%%%
u_3=u_2;
u_2=u_1;
u_1=u(k);
y_3=y_2;
y_2=y_1;
y_1=yout(k);
x
(1)=error(k);
%CalculatingP
x
(2)=error(k)-error_1;
%CalculatingD
x(3)=x(3)+error(k);
%CalculatingI
e_1=x
(1);
ec_1=x
(2);
error_2=error_1;
error_1=error(k);
showrule(a)
figure
(1);
plot(time,rin,'
b'
time,yout,'
r'
xlabel('
time(s)'
ylabel('
rin,yout'
figure
(2);
plot(time,error,'
error'
figure(3);
plot(time,u,'
u'
figure(4);
plot(time,kp,'
figure(5);
plot(time,ki,'
figure(6);
plot(time,kd,'
figure(7);
plotmf(a,'
1);
figure(8);
2);
figure(9);
figure(10);
figure(11);
3);
plotfis(a);
fuzzyfuzzpid.fis