声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1378|回复: 3

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

[复制链接]
发表于 2008-11-3 20:09 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

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的帮助文件里也没有,小弟初学,哪位高手帮忙看看,谢谢啦
回复
分享到:

使用道具 举报

发表于 2008-11-3 20:30 | 显示全部楼层
LZ看看evalfis的用法
doc evalfis

评分

1

查看全部评分

 楼主| 发表于 2008-11-5 13:52 | 显示全部楼层
evalfismex这个函数是什么意思呀?在matlab的帮助文件里面怎么没有呀?
发表于 2008-11-5 14:37 | 显示全部楼层

回复 板凳 chenjian0715 的帖子

help evalfismex
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-12-4 12:32 , Processed in 0.058490 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表