chenjian0715 发表于 2008-11-3 20:09

[求教]帮我看看这个程序错在哪里?关于倒立摆模糊控制

%线性化程序: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=

b1=-a/(4/3*l-a*m*l);
B1=

%Equation 2
x2=200*pi/180;
a2=(g-a*m*l*x2^2)/(4/3*l-a*m*l);
A2=

b2=b1;
B2=

%Equation 3
x1=15*pi/180;
a3=g/(4/3*l-a*m*l*(cos(x1))^2);
A3=
b3=-a*cos(x1)/(4/3*l-a*m*l*(cos(x1))^2);
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=
b4=b3;
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=
b5=b3;
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',*pi/180);
tc=addmf(tc,'input',1,'ZR','gaussmf',*pi/180);
tc=addmf(tc,'input',1,'PO','gaussmf',*pi/180);

tc=addvar(tc,'input','omega',[-200,200]*pi/180);
tc=addmf(tc,'input',2,'NG','gaussmf',*pi/180);
tc=addmf(tc,'input',2,'ZR','gaussmf',*pi/180);
tc=addmf(tc,'input',2,'PO','gaussmf',*pi/180);

tc=addvar(tc,'output','u',[-300,0]);
tc=addmf(tc,'output',1,'No.1','linear',);
tc=addmf(tc,'output',1,'No.2','linear',);
tc=addmf(tc,'output',1,'No.3','linear',);
tc=addmf(tc,'output',1,'No.4','linear',);
tc=addmf(tc,'output',1,'No.5','linear',);

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',*pi/180);
model=addmf(model,'input',1,'ZR','gaussmf',*pi/180);
model=addmf(model,'input',1,'PO','gaussmf',*pi/180);

model=addvar(model,'input','omega',[-200,200]*pi/180);
model=addmf(model,'input',2,'NG','gaussmf',*pi/180);
model=addmf(model,'input',2,'ZR','gaussmf',*pi/180);
model=addmf(model,'input',2,'PO','gaussmf',*pi/180);

model=addvar(model,'input','u',[-5,5]);
model=addmf(model,'input',3,'Any','gaussmf',);

model=addvar(model,'output','d-theta',[-200,200]*pi/180);
model=addmf(model,'output',1,'No.1','linear',);
model=addmf(model,'output',1,'No.2','linear',);
model=addmf(model,'output',1,'No.3','linear',);
model=addmf(model,'output',1,'No.4','linear',);
model=addmf(model,'output',1,'No.5','linear',);

model=addvar(model,'output','d_omega',[-200,200]*pi/180);
model=addmf(model,'output',2,'No.1','linear',);
model=addmf(model,'output',2,'No.2','linear',);
model=addmf(model,'output',2,'No.3','linear',);
model=addmf(model,'output',2,'No.4','linear',);
model=addmf(model,'output',2,'No.5','linear',);

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=;   %initial state

for k=1:1:100
    time(k)=k*ts;
    u(k)=(-1)*evalfis(,tc);    %Using feedback control
   
    k0=evalfis(,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
= evalfismex(input, fis, numofpoints);

Error in ==> chap3_9 at 88
    u(k)=(-1)*evalfis(,tc);    %Using feedback control

evalfismex 是什么呀?matlab的帮助文件里也没有,小弟初学,哪位高手帮忙看看,谢谢啦

ch_j1985 发表于 2008-11-3 20:30

LZ看看evalfis的用法
doc evalfis

chenjian0715 发表于 2008-11-5 13:52

evalfismex这个函数是什么意思呀?在matlab的帮助文件里面怎么没有呀?

sigma665 发表于 2008-11-5 14:37

回复 板凳 chenjian0715 的帖子

help evalfismex
页: [1]
查看完整版本: [求教]帮我看看这个程序错在哪里?关于倒立摆模糊控制