|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
%线性化程序:chen3_9f.m,赋初值
%Local linearization for single inverted pendulum
clc;
clear all;
close all;
g=9.8;m=2;M=8;l=0.5;
a=l/(M+m);
%输入状态方程的状态矩阵
%Equation 1
a1=g/(4/3*l-a*m*l);
A1=[0 1;a1 0]
b1=-a/(4/3*l-a*m*l);
B1=[0;b1]
%Equation 2
x2=200*pi/180;
a2=(g-a*m*l*x2^2)/(4/3*l-a*m*l);
A2=[0 1;a2 0]
b2=b1;
B2=[0;b2]
%Equation 3
x1=15*pi/180;
a3=g/(4/3*l-a*m*l*(cos(x1))^2);
A3=[0 1;a3 0]
b3=-a*cos(x1)/(4/3*l-a*m*l*(cos(x1))^2);
B3=[0;b3]
%Equation 4
x1=15*pi/180;
x2=200*pi/180;
a41=g/(4/3*l-a*m*l*(cos(x1))^2);
a42=-a*m*l*x2*sin(2*x1)*0.5/(4/3*l-a*m*l*(cos(x1))^2);
A4=[0 1;a41 a42]
b4=b3;
B4=[0;b4]
%Equation 5
x1=-15*pi/180;
x2=200*pi/180;
a51=g/(4/3*l-a*m*l*(cos(x1))^2);
a52=-a*m*l*x2*sin(2*x1)*0.5/(4/3*l-a*m*l*(cos(x1))^2);
A5=[0 1;a51 a52]
b5=b3;
B5=[0;b5]
%Sugeno type fuzzy control for single inverted pendulum
close all;
P=[-10+10i;-10-10i] %stable pole point
F1=place(A1,B1,P)
F2=place(A2,B2,P)
F3=place(A3,B3,P)
F4=place(A4,B4,P)
F5=place(A5,B5,P)
tc=newfis('tc','sugeno');
tc=addvar(tc,'input','theta',[-15,15]*pi/180);
tc=addmf(tc,'input',1,'NG','gaussmf',[5,-15]*pi/180);
tc=addmf(tc,'input',1,'ZR','gaussmf',[5,0]*pi/180);
tc=addmf(tc,'input',1,'PO','gaussmf',[5,15]*pi/180);
tc=addvar(tc,'input','omega',[-200,200]*pi/180);
tc=addmf(tc,'input',2,'NG','gaussmf',[50,-200]*pi/180);
tc=addmf(tc,'input',2,'ZR','gaussmf',[50,0]*pi/180);
tc=addmf(tc,'input',2,'PO','gaussmf',[50,200]*pi/180);
tc=addvar(tc,'output','u',[-300,0]);
tc=addmf(tc,'output',1,'No.1','linear',[F1(1),F1(2)]);
tc=addmf(tc,'output',1,'No.2','linear',[F2(1),F2(2)]);
tc=addmf(tc,'output',1,'No.3','linear',[F3(1),F3(2)]);
tc=addmf(tc,'output',1,'No.4','linear',[F4(1),F4(2)]);
tc=addmf(tc,'output',1,'No.5','linear',[F5(1),F5(2)]);
rulelist=[1 1 4 1 1;
1 2 3 1 1;
1 3 5 1 1;
2 1 2 1 1;
2 2 1 1 1;
2 3 2 1 1;
3 1 5 1 1;
3 2 3 1 1;
3 3 4 1 1];
tc=addrule(tc,rulelist)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
model=newfis('model','sugeno');
model=addvar(model,'input','theta',[-15,15]*pi/180);
model=addmf(model,'input',1,'NG','gaussmf',[5,-15]*pi/180);
model=addmf(model,'input',1,'ZR','gaussmf',[5,0]*pi/180);
model=addmf(model,'input',1,'PO','gaussmf',[5,15]*pi/180);
model=addvar(model,'input','omega',[-200,200]*pi/180);
model=addmf(model,'input',2,'NG','gaussmf',[50,-200]*pi/180);
model=addmf(model,'input',2,'ZR','gaussmf',[50,0]*pi/180);
model=addmf(model,'input',2,'PO','gaussmf',[50,200]*pi/180);
model=addvar(model,'input','u',[-5,5]);
model=addmf(model,'input',3,'Any','gaussmf',[1.5,-5]);
model=addvar(model,'output','d-theta',[-200,200]*pi/180);
model=addmf(model,'output',1,'No.1','linear',[0 1 0 0]);
model=addmf(model,'output',1,'No.2','linear',[0 1 0 0]);
model=addmf(model,'output',1,'No.3','linear',[0 1 0 0]);
model=addmf(model,'output',1,'No.4','linear',[0 1 0 0]);
model=addmf(model,'output',1,'No.5','linear',[0 1 0 0]);
model=addvar(model,'output','d_omega',[-200,200]*pi/180);
model=addmf(model,'output',2,'No.1','linear',[A1(2,1),0,B1(2),0]);
model=addmf(model,'output',2,'No.2','linear',[A2(2,1),0,B2(2),0]);
model=addmf(model,'output',2,'No.3','linear',[A3(2,1),0,B3(2),0]);
model=addmf(model,'output',2,'No.4','linear',[A4(2,1),A4(2,2),B4(2),0]);
model=addmf(model,'output',2,'No.5','linear',[A5(2,1),A5(2,2),B5(2),0]);
rulelist1=[1 1 0 4 4 1 1;
1 2 0 3 3 1 1;
1 3 0 5 5 1 1;
2 1 0 2 2 1 1;
2 2 0 1 1 1 1;
2 3 0 2 2 1 1;
3 1 0 5 5 1 1;
3 2 0 3 3 1 1;
3 3 0 4 4 1 1];
model=addrule(model,rulelist1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%系统仿真
ts=0.020;
x=[0.20 0]; %initial state
for k=1:1:100
time(k)=k*ts;
u(k)=(-1)*evalfis([x(1),x(2)],tc); %Using feedback control
k0=evalfis([x(1),x(2),u(k)],model); %Using fuzzy T-S model
x=x+ts*k0;
y1(k)=x(1);
y2(k)=x(2);
end
figure(1);
subplot(211);
plot(time,y1),grid on;
xlabel('time(s)'),ylabel('Angle');
subplot(212);
plot(time,y2),grid on;
xlabel('time(s)'),ylabel('Angle rate');
figure(2);
plot(time,u),grid on;
xlabel('time(s)'),ylabel('controller output');
figure(3);
plotmf(tc,'input',1);
figure(4);
plotmf(tc,'input',2);
showrule(tc)
showrule(model)
仿真的时候总是说我的出错,
??? Invalid FIS. PARAMS field of linear output MF has incorrect length.
Error in ==> evalfis at 84
[output,IRR,ORR,ARR] = evalfismex(input, fis, numofpoints);
Error in ==> chap3_9 at 88
u(k)=(-1)*evalfis([x(1),x(2)],tc); %Using feedback control
evalfismex 是什么呀?matlab的帮助文件里也没有,小弟初学,哪位高手帮忙看看,谢谢啦 |
|