% 模糊PID
% 模糊PID控制
clear all;
close all;
%%%%%%%%%%%%%%%%%%%%% 伸缩因子模糊控制器
b = newfis('shensuoyinzi');
f1 = 1.0; %
b = addvar(b,'input','e',[-15 * f1,15 * f1]);
b = addmf(b,'input',1,'NB','gaussmf',[2 * f1,-15 * f1]);
b = addmf(b,'input',1,'NM','gaussmf',[2 * f1,-10 * f1]);
b = addmf(b,'input',1,'NS','gaussmf',[1.5 * f1,-5 * f1]);
b = addmf(b,'input',1,'NZ','gaussmf',[1.2 * f1,-3 * f1]);
b = addmf(b,'input',1,'Z','gaussmf',[1.5 * f1,0]);
b = addmf(b,'input',1,'PZ','gaussmf',[1.2 * f1,3 * f1]);
b = addmf(b,'input',1,'PS','gaussmf',[1.5 * f1,5 * f1]);
b = addmf(b,'input',1,'PM','gaussmf',[2 * f1,10 * f1]);
b = addmf(b,'input',1,'PB','gaussmf',[2 * f1,15 * f1]);
f2 = 0.5; %
b = addvar(b,'input','ec',[-6 * f2,6 * f2]);
b = addmf(b,'input',2,'NB','zmf',[-6 * f2,-4 * f2]);
b = addmf(b,'input',2,'NM','trimf',[-6 * f2,-4 * f2,-2 * f2]);
b = addmf(b,'input',2,'NS','trimf',[-4 * f2,-2 * f2,0 * f2]);
b = addmf(b,'input',2,'Z','trimf',[-2.0 * f2,0,2.0 * f2]);
b = addmf(b,'input',2,'PS','trimf',[0 * f2,2 * f2,4 * f2]);
b = addmf(b,'input',2,'PM','trimf',[2 * f2,4 * f2,6 * f2]);
b = addmf(b,'input',2,'PB','smf',[4 * f2,6 * f2]);
% f3 = 1.4;
f3 = 1;
b = addvar(b,'output','alphae',[0.5 * f3,2 * f3]);
b = addmf(b,'output',1,'ZE','gaussmf',[0.1 * f3,0.5 * f3]);
b = addmf(b,'output',1,'VS','gaussmf',[0.08 * f3,0.75 * f3]);
b = addmf(b,'output',1,'S','gaussmf',[0.05 * f3,0.875 * f3]);
b = addmf(b,'output',1,'SB','gaussmf',[0.2 * f3,1 * f3]);
b = addmf(b,'output',1,'M','gaussmf',[0.1* f3,1.125 * f3]);
b = addmf(b,'output',1,'B','gaussmf',[0.1 *f3,1.5 * f3]);
b = addmf(b,'output',1,'PB','gaussmf',[0.15 * f3,2 * f3]);
f4 = 1;
b = addvar(b,'output','alphaec',[0.5 * f4,2 * f4]);
b = addmf(b,'output',2,'ZE','gaussmf',[0.1 * f4,0.5 * f4]);
b = addmf(b,'output',2,'VS','gaussmf',[0.08 * f4,0.75 * f4]);
b = addmf(b,'output',2,'S','gaussmf',[0.05 * f4,0.875 * f4]);
b = addmf(b,'output',2,'SB','gaussmf',[0.2 * f4,1 * f4]);
b = addmf(b,'output',2,'M','gaussmf',[0.1 * f4,1.125 * f4]);
b = addmf(b,'output',2,'B','gaussmf',[0.1 * f4,1.5 * f4]);
b = addmf(b,'output',2,'PB','gaussmf',[0.15 * f4,2 * f4]);
f5 = 1;
b = addvar(b,'output','beta',[0.4 * f5,1.5 * f5]);
b = addmf(b,'output',3,'ZE','gaussmf',[0.3 * f5,0.4 * f5]);
b = addmf(b,'output',3,'VS','gaussmf',[0.4 * f5,0.5 * f5]);
b = addmf(b,'output',3,'S','gaussmf',[0.4 * f5,0.8 * f5]);
b = addmf(b,'output',3,'SB','gaussmf',[0.5 * f5,1 * f5]);
b = addmf(b,'output',3,'M','gaussmf',[0.8 * f5,1.2 * f5]);
b = addmf(b,'output',3,'B','gaussmf',[0.8 * f5,1.4 * f5]);
b = addmf(b,'output',3,'PB','gaussmf',[1.0 * f5,1.5 * f5]);
alphae_list = [1 2 2 3 4 4 4;
1 2 2 3 4 4 4;
4 4 4 6 6 5 5;
5 5 6 7 6 5 5;
6 6 6 7 6 6 6;
6 6 6 7 4 6 6;
5 5 6 6 6 5 5;
4 4 4 3 2 2 2;
4 4 4 3 2 2 2];
alphaec_list = [1 2 2 3 4 4 4;
1 2 2 3 4 4 4;
2 2 3 6 6 5 5;
6 6 7 7 7 6 6;
6 6 7 7 7 6 6;
6 6 7 7 7 6 6;
5 5 6 6 2 2 3;
4 4 4 3 2 2 2;
4 4 4 3 2 2 2];
beta_list = [7 7 7 6 6 5 5;
7 7 7 6 6 5 5;
6 6 5 4 4 4 4;
3 3 3 3 3 3 3;
3 2 2 2 2 2 3;
3 3 3 3 3 3 3;
4 4 4 4 5 6 6;
4 4 4 4 4 4 4;
4 4 4 4 4 4 4];
r_Kp = zeros(prod(size(alphae_list)),3);
k = 1;
for i = 1:size(alphae_list,1)
for j = 1:size(alphae_list,2)
shensuoyinzi_r(k,:) = [i,j,alphae_list(i,j),alphaec_list(i,j),beta_list(i,j)];
k = k+1;
end
end
[r1,s1] = size(shensuoyinzi_r);
r2 = ones(r1,2);
rulelist = [shensuoyinzi_r,r2];
b = addrule(b,rulelist);
b1 = setfis(b,'DefuzzMethod','centroid');
writefis(b,'shensuoyinzi');
b2 = readfis('shensuoyinzi');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%常规模糊PID控制器
a = newfis('fuzzytunningPID');
f1 = 1.0; %
a = addvar(a,'input','e',[-7 * f1,7 * f1]);
a = addmf(a,'input',1,'NB','zmf',[-7 * f1,-4 * f1]);
a = addmf(a,'input',1,'NM','trimf',[-7 * f1,-5 * f1,-3 * f1]);
a = addmf(a,'input',1,'NS','trimf',[-5 * f1,-3 * f1,-1 * f1]);
a = addmf(a,'input',1,'NZ','trimf',[-3 * f1,-1 * f1,0 * f1]);
a = addmf(a,'input',1,'Z','trimf',[-2 * f1,0,2 * f1]);
a = addmf(a,'input',1,'PZ','trimf',[0 * f1,1* f1,3 * f1]);
a = addmf(a,'input',1,'PS','trimf',[1 * f1,3 * f1,5 * f1]);
a = addmf(a,'input',1,'PM','trimf',[3 * f1,5 * f1,7 * f1]);
a = addmf(a,'input',1,'PB','smf',[4 * f1,7 * f1]);
f2 = 0.5; %
a = addvar(a,'input','ec',[-6 * f2,6 * f2]);
a = addmf(a,'input',2,'NB','zmf',[-6 * f2,-4 * f2]);
a = addmf(a,'input',2,'NM','trimf',[-6 * f2,-4 * f2,-2 * f2]);
a = addmf(a,'input',2,'NS','trimf',[-4 * f2,-2 * f2,0 * f2]);
a = addmf(a,'input',2,'Z','trimf',[-2.0 * f2,0,2.0 * f2]);
a = addmf(a,'input',2,'PS','trimf',[0 * f2,2 * f2,4 * f2]);
a = addmf(a,'input',2,'PM','trimf',[2 * f2,4 * f2,6 * f2]);
a = addmf(a,'input',2,'PB','smf',[4 * f2,6 * f2]);
% f3 = 1.4;
f3 = 1;
a = addvar(a,'output','Kp',[-6 * f3,6 * f3]);
a = addmf(a,'output',1,'NB','zmf',[-6 * f2,-4 * f2]);
a = addmf(a,'output',1,'NM','trimf',[-6 * f2,-4 * f2,-2 * f2]);
a = addmf(a,'output',1,'NS','trimf',[-4 * f2,-2 * f2,0 * f2]);
a = addmf(a,'output',1,'Z','trimf',[-2.0 * f2,0,2.0 * f2]);
a = addmf(a,'output',1,'PS','trimf',[0 * f2,2 * f2,4 * f2]);
a = addmf(a,'output',1,'PM','trimf',[2 * f2,4 * f2,6 * f2]);
a = addmf(a,'output',1,'PB','smf',[4 * f2,6 * f2]);
f4 = 1;
a = addvar(a,'output','Ki',[-6 * f4,6 * f4]);
a = addmf(a,'output',2,'NB','zmf',[-6 * f2,-4 * f2]);
a = addmf(a,'output',2,'NM','trimf',[-6 * f2,-4 * f2,-2 * f2]);
a = addmf(a,'output',2,'NS','trimf',[-4 * f2,-2 * f2,0 * f2]);
a = addmf(a,'output',2,'Z','trimf',[-2.0 * f2,0,2.0 * f2]);
a = addmf(a,'output',2,'PS','trimf',[0 * f2,2 * f2,4 * f2]);
a = addmf(a,'output',2,'PM','trimf',[2 * f2,4 * f2,6 * f2]);
a = addmf(a,'output',2,'PB','smf',[4 * f2,6 * f2]);
f5 = 1;
a = addvar(a,'output','Kd',[-6 * f5,6 * f5]);
a = addmf(a,'output',3,'NB','zmf',[-6 * f2,-4 * f2]);
a = addmf(a,'output',3,'NM','trimf',[-6 * f2,-4 * f2,-2 * f2]);
a = addmf(a,'output',3,'NS','trimf',[-4 * f2,-2 * f2,0 * f2]);
a = addmf(a,'output',3,'Z','trimf',[-2.0 * f2,0,2.0 * f2]);
a = addmf(a,'output',3,'PS','trimf',[0 * f2,2 * f2,4 * f2]);
a = addmf(a,'output',3,'PM','trimf',[2 * f2,4 * f2,6 * f2]);
a = addmf(a,'output',3,'PB','smf',[4 * f2,6 * f2]);
delta_Kplist = [6 6 7 7 5 5 4;
6 6 6 6 5 5 4;
4 4 4 4 5 5 3;
3 4 5 5 5 4 3;
3 4 5 5 5 4 3;
3 4 5 5 5 4 3;
3 5 5 5 5 4 4;
4 5 5 6 6 6 6;
4 5 5 7 7 6 6];
delta_Kilist = [1 1 1 1 1 1 1;
1 1 1 1 1 1 1;
4 4 4 4 4 1 1;
3 3 4 4 4 3 3;
3 3 4 4 4 3 3;
3 3 4 4 4 3 3;
1 1 4 4 4 4 4;
1 1 1 1 1 1 1;
1 1 1 1 1 1 1];
delta_Kdlist = [1 1 1 1 1 1 1;
1 1 1 1 1 1 1;
4 4 4 5 5 1 1;
2 4 5 5 5 4 2;
2 4 5 5 5 4 2;
2 4 5 5 5 4 2;
1 1 5 5 4 4 4;
1 1 1 1 1 1 1;
1 1 1 1 1 1 1];
r_pid = zeros(prod(size(delta_Kplist)),5);
k = 1;
for i = 1:size(delta_Kplist,1)
for j = 1:size(delta_Kplist,2)
r_pid(k,:) = [i,j,delta_Kplist(i,j),delta_Kilist(i,j),delta_Kdlist(i,j)];
k = k+1;
end
end
[r,s] = size(r_pid);
r2 = ones(r,2);
rulelist = [r_pid,r2];
a = addrule(a,rulelist);
a1 = setfis(a,'DefuzzMethod','centroid');
writefis(a,'fuzzyPID');
a2 = readfis('fuzzyPID');
%%%%%%%%%%% 控制�
- 1
- 2
前往页