倒立摆离散型模糊控制器设计与仿真

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

倒立摆离散型模糊控制器设计与仿真1.数学模型θf图1倒立摆示意图如上图1倒立摆示意图所示,)(θ°为杆与垂线的夹角,)(Nf为作用力,杆的质量kgmp1.0,杆和小车的总质量kgm1.1,半杆长ml5.0,重力加速度2/8.9smg,采样周期sT02.0。其数学模型为:π180θcos-)3/4(]θsin2)^180/πθ([θcos-θsinθ2×+=lmmllmfmgpp2.离散模糊控制器的设计(1)确定输入、输出变量,选择维数本文为倒立摆控制系统设计了一个双输入、单输出结构的模糊控制器。模糊控制器系统的输入变量为系统设定0θ与实际测得θ之间的偏差θ-θ0=e及其偏差变化率1--Δiieee=,输出语言变量为控制量u。(2)确定基本论域和论域(比例因子)e,eΔ,u都是实数域上的连续变量,在该例中它们的变化范围分别为:e的范围为]15,15-[,eΔ的范围为]60,60-[,u的范围为]10,10-[,将它们全部变换到离散论域}6,5,4,3,2,1,0,1-3-,4-5-,6-{,得到离散论域上的输入、输出变量*e,*Δe,*u。(3)定义模糊集合及隶属函数表对*e,*Δe,*u分别定义7个模糊集合NL,NM,NS,Z,PS,PM,PL。对*e,*Δe,*u定义相同的隶属度函数,如表1所示。表1*e,*Δe,*u隶属度函数表(4)设计模糊控制规则总结工作经验得出52条控制规则,见表2。表2控制规则表(5)求模糊关系矩阵R和模糊控制表在Matlab中新建文件,编写M文件计算模糊控制表,M文件如下。Input1_Terms=[1,2,3,4,5,6,7];Input2_Terms=[1,2,3,4,5,6,7];Output_Terms=[1,2,3,4,5,6,7];Input1_Terms_Membership=[0,0,0,0,0,0,0,0,0,0,0.2,0.7,1;0,0,0,0,0,0,0,0,0.2,0.8,1,0.8,0.2;0,0,0,0,0,0,0,0.8,1,0.8,0.2,0,0;0,0,0,0,0,0.5,1,0.5,0,0,0,0,0;0,0,0.2,0.8,1,0.8,0,0,0,0,0,0,0;0.2,0.8,1,0.8,0.2,0,0,0,0,0,0,0,0;1,0.7,0.2,0,0,0,0,0,0,0,0,0,0];Input2_Terms_Membership=Input1_Terms_Membership;Output_Terms_Membership=Input1_Terms_Membership;Rule=[0,0,7,7,7,7,7;7,7,6,6,6,6,6;7,5,5,5,3,2,2;6,5,5,4,3,2,2;6,6,5,3,3,3,1;2,2,2,2,2,3,1;1,1,1,1,1,0,0];fori=1:169forj=1:13R(i,j)=0;endendforInput1_Terms_Index=1:7forInput2_Terms_Index=1:7if(Rule(Input1_Terms_Index,Input2_Terms_Index)~=0)Output_Terms_Index=Rule(Input1_Terms_Index,Input2_Terms_Index);A=Input1_Terms_Membership(Input1_Terms_Index,:);B=Input2_Terms_Membership(Input2_Terms_Index,:);C=Output_Terms_Membership(Output_Terms_Index,:);fori=1:13forj=1:13R1(i,j)=min(A(i),B(j));endendR2=[];fork=1:13R2=[R2;R1(k,:)'];endfori=1:169forj=1:13R3(i,j)=min(R2(i),C(j));endendR=max(R,R3);endendendforInput1_value_index=1:13forInput2_value_index=1:13Input1_value_membership=Input1_Terms_Membership(:,Input1_value_index);[Max_Input1_value,Max_Input1_index]=max(Input1_value_membership);Ad=Input1_Terms_Membership(Max_Input1_index,:);Input2_value_membership=Input2_Terms_Membership(:,Input2_value_index);[Max_Input2_value,Max_Input2_index]=max(Input2_value_membership);Bd=Input2_Terms_Membership(Max_Input2_index,:);fori=1:13forj=1:13Rd1(i,j)=min(Ad(i),Bd(j));endendRd2=[];fork=1:13Rd2=[Rd2;Rd1(k,:)'];endforj=1:13Cd(j)=max(min(Rd2,R(:,j)));endsum1=0;sum2=0;fori=1:13sum1=sum1+Cd(i);sum2=sum2+Cd(i)*(i-7);endOUT=round(sum2/sum1);Fuzzy_Table(Input1_value_index,Input2_value_index)=OUT;endend3.仿真实现(1)在Matlab软件下搭建仿真模型图3仿真模型(2)修改参数8060/115/1321===KKK(3)编写s函数,并导入模块首先在matlab程序输入框输入“editsfuntmpl”调出s函数模板,在此基础上修改程序如下。function[sys,x0,str,ts]=sdaolibai(~,x,u,flag)switchflagcase0[sys,x0,str,ts]=mdlInitializeSizes();case1sys=mdlDerivatives(x,u);case3sys=mdlOutputs(x);case{2,4,9}sys=[];otherwiseerror(['Unhandledflag=',num2str(flag)]);end;function[sys,x0,str,ts]=mdlInitializeSizes()sizes=simsizes;sizes.NumContStates=2;sizes.NumDiscStates=0;sizes.NumOutputs=1;sizes.NumInputs=1;sizes.DirFeedthrough=0;sizes.NumSampleTimes=1;sys=simsizes(sizes);x0=[5;30];str=[];ts=[00];functionsys=mdlDerivatives(x,u)sys(1,1)=x(2);sys(2,1)=(1.1*9.8*sin(x(1)*pi/180)-cos(x(1)*pi/180)*(u+0.1*0.5*(x(2)*pi/180)^2*sin(x(1)*pi/180)))/((4/3)*1.1*0.5-0.1*0.5*(cos(x(1)*pi/180))^2)*180/pi;functionsys=mdlOutputs(x)sys=x(1);点开s函数模块,将所编写的程序名填入,点击“Edit”导入程序。(4)将M文件导入“2DLookuptable”模块并修改参数(5)运行及结果

1 / 6
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功