| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2009 人关注过本帖
标题:[求助],高手帮帮忙呀!MATLAB 关于倒立摆的模糊控制编程仿真
取消只看楼主 加入收藏
chenjian0715
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-11-3
收藏
 问题点数:0 回复次数:0 
[求助],高手帮帮忙呀!MATLAB 关于倒立摆的模糊控制编程仿真
%线性化程序: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)

仿真到这一步:u(k)=(-1)*evalfis([x(1),x(2)],tc);    %Using feedback control
说我的程序是:
??? 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

??? Invalid FIS. PARAMS field of linear output MF has incorrect length.
不知道哪里出错了?
郁闷,高手帮我看看呀,万分感谢!
搜索更多相关主题的帖子: MATLAB 模糊控制 仿真 倒立 
2008-11-03 16:19
快速回复:[求助],高手帮帮忙呀!MATLAB 关于倒立摆的模糊控制编程仿真
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033999 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved