设计模糊控制的具体详解请参照链接: https://blog.csdn.net/LOVE_105/article/details/112135599.
按照相同的方法得到模糊推理系统
设置被控对象为
G(s) = 400/(s^2+500s)
设计两输入单输出模糊控制器,输入为偏差和偏差变化率,输出为控制量U,使系统输出能实时跟踪输入信号。
模糊控制器
clear all;
close all;
a = newfis('fuzzf');
a = addvar(a,'input','e',[-0.3,0.3]);
a = addmf(a,'input',1,'NB','zmf',[-0.3,-0.1]);
a = addmf(a,'input',1,'NM','trimf',[-0.3,-0.2,0]);
a = addmf(a,'input',1,'NS','trimf',[-0.3,-0.1,0.1]);
a = addmf(a,'input',1,'Z','trimf',[-0.2,0,0.2]);
a = addmf(a,'input',1,'PS','trimf',[-0.1,0.1,0.3]);
a = addmf(a,'input',1,'PM','trimf',[0,0.2,0.3]);
a = addmf(a,'input',1,'PB','smf',[0.1,0.3]);
a = addvar(a,'input','ec',[-0.3,0.3]);
a = addmf(a,'input',2,'NB','zmf',[-0.3,-0.1]);
a = addmf(a,'input',2,'NM','trimf',[-0.3,-0.2,0]);
a = addmf(a,'input',2,'NS','trimf',[-0.3,-0.1,0.1]);
a = addmf(a,'input',2,'Z','trimf',[-0.2,0,0.2]);
a = addmf(a,'input',2,'PS','trimf',[-0.1,0.1,0.3]);
a = addmf(a,'input',2,'PM','trimf',[0,0.2,0.3]);
a = addmf(a,'input',2,'PB','smf',[0.1,0.3]);
a = addvar(a,'output','u',[-30,30]);
a = addmf(a,'output',1,'NB','zmf',[-30,30]);
a = addmf(a,'output',1,'NM','trimf',[-30,-20,0]);
a = addmf(a,'output',1,'NS','trimf',[-30,-10,10]);
a = addmf(a,'output',1,'Z','trimf',[-20,0,20]);
a = addmf(a,'output',1,'PS','trimf',[-10,10,30]);
a = addmf(a,'output',1,'PM','trimf',[0,20,30]);
a = addmf(a,'output',1,'PB','smf',[10,30]);
rulelist = [1 1 1 1 1;
1 2 1 1 1;
1 3 2 1 1;
1 4 2 1 1;
1 5 3 1 1;
1 6 3 1 1;
1 7 4 1 1;
2 1 1 1 1;
2 2 2 1 1;
2 3 2 1 1;
2 4 3 1 1;
2 5 3 1 1;
2 6 4 1 1;
2 7 5 1 1;
3 1 2 1 1;
3 2 2 1 1;
3 3 3 1 1;
3 4 3 1 1;
3 5 4 1 1;
3 6 5 1 1;
3 7 5 1 1;
4 1 2 1 1;
4 2 3 1 1;
4 3 3 1 1
4 4 4 1 1;
4 5 4 1 1;
4 6 5 1 1;
4 7 6 1 1;
5 1 3 1 1;
5 2 3 1 1;
5 3 4 1 1
5 4 5 1 1;
5 5 5 1 1;
5 6 6 1 1;
5 7 6 1 1;
6 1 3 1 1;
6 2 4 1 1;
6 3 5 1 1
6 4 5 1 1;
6 5 6 1 1;
6 6 6 1 1;
6 7 7 1 1;
7 1 4 1 1;
7 2 5 1 1;
7 3 5 1 1
7 4 6 1 1;
7 5 6 1 1;
7 6 7 1 1;
7 7 7 1 1;
];
a = addrule(a,rulelist);
showrule(a)
a1 = setfis(a,'DefuzzMethod','mom');
writefis(a1,'fuzzf');
a2 = readfis('fuzzf');
disp('------------------------------------------------------');
disp('fuzzy controller tabel:e = [-3,+3],ec = [-3.+3] ');
disp('------------------------------------------------------');
Ulist = zeros(7,7);
for i = 1:7
for j = 1:7
e(i) = -4+i;
ec(j) = -4+j;
Ulist(i,j) = evalfis([e(i),ec(j)],a2);
end
end
Ulist=ceil(Ulist);
figure(1);
plotfis(a2);
figure(2);
plotmf(a,'input',1);
figure(3);
plotmf(a,'input',2);
figure(4);
plotmf(a,'output',1);
位置跟踪
close all;
figure(1);
plot(t,y(:,1),'r',t,y(:,2),'k:','linewidth',2);
xlabel('time(s)');ylabel('yd,y');
legend('Ideal position signal','position tracking');
模糊控制器的代码详解可参照https://blog.csdn.net/LOVE_105/article/details/112135599.
我们知道我们需要建立类似如图所示的控制系统。
Simulink的仿真是根据图所示,设计一个双输入单输出的模糊控制系统。
具体做法可参照https://blog.csdn.net/LOVE_105/article/details/112143886最后通过得到的t画出跟踪结果
位置跟踪
close all;
figure(1);
plot(t,y(:,1),'r',t,y(:,2),'k:','linewidth',2);
xlabel('time(s)');ylabel('yd,y');
legend('Ideal position signal','position tracking');
t来自于Simulink的结果。