• 大小: 159KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-07
  • 语言: 其他
  • 标签: 模糊控制  倒立摆  

资源简介

运用模糊控制方法实现一级倒立摆稳定。里面有相应的源程序代码及其课件,简单易懂。

资源截图

代码片段和文件信息

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 倒立摆平衡控制问题
% 模糊控制器(S函数)
% 2009/06
% 栗丽英(20081135)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function[sysx0strts]=spacemodel(txuflag)
switch flag
    case 0
        [sysx0strts]=mdlInitializeSizes;
        case 3
    sys=mdlOutputs(txu);
    case {249}
    sys=[];
    otherwise
    error([‘Unhandled flag=‘num2str(flag)]);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function[sysx0strts]=mdlInitializeSizes
sizes=simsizes;
% 连续状态个数
sizes.NumContStates  =0;
% 离散状态个数
sizes.NumDiscStates  =0;
% 输出值个数
sizes.NumOutputs     =1;
% 输入值个数
sizes.NumInputs      =2;
sizes.DirFeedthrough =1;
% 采样时间
sizes.NumSampleTimes =1;
sys=simsizes(sizes);
x0=[];
str=[];
ts=[0 0];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function sys=mdlOutputs(txu)
x=[u(1);u(2)];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%load K_file;%
K1=[357.4135   45.3333];
K2=[341.4135   45.3333];
K3=[662.5861  102.6667];
K4=[680.4563  109.5949];
K5=[680.4563  95.7385];

ut1=K1*x;
ut2=K2*x;
ut3=K3*x;
ut4=K4*x;
ut5=K5*x;
% 辅初始值
h40=0;
h41=0;
h30=0;
h31=0; 
h40=0;
h41=0;
h50=0;
h51=0;
h10=0;
h11=0;
h20=0;
h21=0;

L1=-pi/2;
L2=pi/2;
L=L2-L1;

N=2;
for i=1:N+1
    e(i)=(L1+L/N*(i-1));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 定义模糊规则
h10=trimf(u(1)[e(1)e(2)e(3)]);   %The middle
h11=trimf(u(2)[e(1)e(2)e(3)]);   %The middle

if     x(1)<0  x(2)>0
   h50=trimf(x(1)[e(1)e(1)e(2)]);   %The last
    h51=trimf(x(2)[e(2)e(2)e(3)]);   %The last
elseif  x(1)>0  x(2)<0
    h50=trimf(x(1)[e(2)e(2)e(3)]);
    h51=trimf(x(1)[e(1)e(1)e(2)]);
end
if   x(1)>0  x(2)>0  
    h40=trimf(x(1)[e(2)e(3)e(3)]);   %The last
    h41=trimf(x(2)[e(2)e(3)e(3)]);   %The last
    elseif  x(1)<0   x(2)<0
        h40=trimf(x(1)[e(1)e(1)e(2)]);   %The last
    h41=trimf(x(2)[e(1)e(1)e(2)]);   %The last
end

if  x(1)>0   x(2)=0 
    h30=trimf(x(1)[e(2)e(3)e(3)]);   %The last
    h31=trimf(x(2)[e(1)e(2)e(3)]);   %The last
    elseif  x(1)<0  x(2)=0
        h30=trimf(x(1)[e(1)e(1)e(2)]);   %The last
    h31=trimf(x(2)[e(1)e(2)e(3)]);   %The last
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%h1+h2
ut=h10*h11*ut1+h30*h31*ut3+h40*h41*ut4+h50*h51*ut5;

%ut=ut1+ut2+ut3+ut4+ut5
%ut=ut1*5/13+ut2*2/13+ut3*2/13+ut4*2/13+ut5*2/13
sys(1)=8*ut;



 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      10280  2009-06-15 13:11  6.倒立摆\chap4_10sim.mdl

     文件       2793  2009-06-28 21:49  6.倒立摆\Control.m

     文件      17427  2009-06-29 16:05  6.倒立摆\daolibai.mdl

     文件       1426  2009-06-28 21:50  6.倒立摆\Plant.m

    ..A.SH.      5120  2009-06-29 18:29  6.倒立摆\Thumbs.db

     文件     254464  2009-06-29 19:17  6.倒立摆\倒立摆.ppt

     目录          0  2009-08-20 12:33  6.倒立摆

----------- ---------  ---------- -----  ----

               291510                    7


评论

共有 条评论