基于matlab的模糊控制器仿真,通过matlab编程实现模糊规则,控制过程等

1.算法描述

       Zadeh创立的模糊数学,对不明确系统的控制有极大的贡献,自七十年代以后,一些实用的模糊控制器的相继出现,使得我们在控制领域中又向前迈进了一大步。模糊逻辑控制(Fuzzy Logic Control)简称模糊控制(Fuzzy Control),是以模糊集合论、模糊语言变量和模糊逻辑推理为基础的一种计算机数字控制技术。1965年,美国的L.A.Zadeh创立了模糊集合论;1973年他给出了模糊逻辑控制的定义和相关的定理。1974年,英国的E.H.Mamdani首次根据模糊控制语句组成模糊控制器,并将它应用于锅炉和蒸汽机的控制,获得了实验室的成功。这一开拓性的工作标志着模糊控制论的诞生。模糊控制实质上是一种非线性控制,从属于智能控制的范畴。模糊控制的一大特点是既有系统化的理论,又有大量的实际应用背景。模糊控制的发展最初在西方遇到了较大的阻力;然而在东方尤其是日本,得到了迅速而广泛的推广应用。近20多年来,模糊控制不论在理论上还是技术上都有了长足的进步,成为自动控制领域一个非常活跃而又硕果累累的分支。其典型应用涉及生产和生活的许多方面,例如在家用电器设备中有模糊洗衣机、空调、微波炉、吸尘器、照相机和摄录机等;在工业控制领域中有水净化处理、发酵过程、化学反应釜、水泥窑炉等;在专用系统和其它方面有地铁靠站停车、汽车驾驶、电梯、自动扶梯、蒸汽引擎以及机器人的模糊控制。

 

       模糊控制将人的经验知识转化为控制策略,不要求精确的数学模型,只需现场操作人员的经验知识,使模型难以确定的系统得以有效的控制,因此在对象参数发生变化的时候,模糊控制仍能达到较为满意的控制效果。但模糊控制的控制作用较粗糙,无法从根本上消除静态误差,控制精度较低,于是把模糊控制整合到PID控制器中,既保持了PID控制器的结构简单、适用性强和整定方便等优点,又通过智能技术调整了PID控制器的参数,以适应被控对象特性的变化。考虑到控制规则的灵活与细致性兼顾其简单与易行的要求,这里选取七个语言等级作为本文所设计的模糊控制器的语言等级,从负的最大到正的最大依次为:负大(NB)、负中(NM)、负小(NS)、零(ZO)、正小(PS)、正中(PM)、正大(PB)

 

        常用的隶属函数有矩形分布、梯形分布、三角形分布、柯西分布和正态分布等。隶属函数曲线的形状会导致不同的控制特性,隶属度函数曲线形状较尖的模糊子集器分辨率较高,控制灵敏度也较高;相反,隶属度函数曲线形状较缓,控制特性也较平缓,系统稳定性也较好。因此在选择模糊变量的模糊隶属函数时,在误差较大的区域采用低分辨率的模糊集,在误差较小的区域采用高分辨率的模糊集。

 

       模糊规则是指根据人的直觉思维推理,依据系统输出的误差及误差的变化趋势来消除系统误差的控制规则,它是由专家或者经验人员总结出来的。控制规则的基本形式为

 

 

 

 

        建立模糊控制规则表的基本原则是:当误差大或较大时,选取控制量以尽快消除误差为主;而当误差较小时,选取控制量要注意防止超调,以系统的稳定性为主要出发点。误差为正时与误差为负时相类同,相应的符号都要变化。 模糊规则表如下所示:

 

 

 

 

 

 

 

 

2.仿真效果预览

matlab2022a仿真结果如下:

 

 

 

 

3.MATLAB核心程序

 

fuzzyrules=[-1  -1   -1   -1  -1    -1  -0.8 -0.6 -0.4 -0.2  0;
	    -1  -1   -1   -1  -1   -0.8 -0.6 -0.4 -0.2   0  0.2;
	    -1  -1   -1   -1  -0.8 -0.6 -0.4 -0.2   0   0.2 0.4;
	    -1  -1   -1  -0.8 -0.6 -0.4 -0.2   0   0.2  0.4 0.6;
	    -1  -1  -0.8 -0.6 -0.4 -0.2   0   0.2  0.4  0.6 0.8;
	    -1 -0.8 -0.6 -0.4 -0.2   0   0.2  0.4  0.6  0.8  1;
	  -0.8 -0.6 -0.4 -0.2   0   0.2  0.4  0.6  0.8   1   1;
	  -0.6 -0.4 -0.2   0   0.2  0.4  0.6  0.8   1    1   1;
	  -0.4 -0.2   0   0.2  0.4  0.6  0.8   1    1    1   1;
	  -0.2  0    0.2  0.4  0.6  0.8   1    1    1    1   1;
	   0   0.2   0.4  0.6  0.8   1    1    1    1    1   1]*gu*gf;
 
% Next, we define some parameters for the fuzzy inverse model
 
gye=1/2;,gyc=1/2;
 
gp=0.2;
 
numye=11; 	% Number of input membership functions for the ye
			% universe of discourse
numyc=11; 	% Number of input membership functions for the yc
			% universe of discourse
 
wye=0.2*(1/gye);	% Sets the width of the membership functions for
					% ye from center to extremes
wyc=0.2*(1/gyc);	% Sets the width of the membership functions for
					% yc from center to extremes
invbase=0.4*gp; % Sets the base of the output membership functions
 
cye=[-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1]*(1/gye);
 
% For change in error input for learning mechanism
cyc=[-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1]*(1/gyc);
 
........................................................................
 
ym(index)=(1/(2+a_r*step))*((2-a_r*step)*ymold+...
                                    k_r*step*(r(index)+rold));
 
ymold=ym(index);
rold=r(index);
 
 
c_count=0;,e_count=0;   % These are used to count the number of
						% non-zero mf certainitie of e and c
e=r(index)-y(index);
			% Calculates the error input for the fuzzy controller
c=(e-eold)/step;
	% Calculates the change in error input for the fuzzy controller
eold=e;
 
 
	if e<=ce(1)		% Takes care of saturation of the left-most
					% membership function
         mfe=[1 0 0 0 0 0 0 0 0 0 0]; % i.e., the only one on is the
         							  %left-most one
	 e_count=e_count+1;,e_int=1; 	  %  One mf on, it is the
	 								  %left-most one.
	elseif e>=ce(nume)				  % Takes care ofsaturation
									  %of the right-most mf
	 mfe=[0 0 0 0 0 0 0 0 0 0 1];
	 e_count=e_count+1;,e_int=nume; % One mf on, it is the
	 								%right-most one
	else      % In this case the input is on the middle part of the
 
	   for i=1:nume
		 if e<=ce(i)
		  mfe(i)=max([0 1+(e-ce(i))/we]);
 
			if mfe(i)~=0
 
			 e_count=e_count+1;
			 e_int=i;	% This term holds the index last entry
			 			% with a non-zero term
			end
		 else
		  mfe(i)=max([0,1+(ce(i)-e)/we]);
		  						% In thiscase the input is to the
		  						% right ofthe center ce(i)
			if mfe(i)~=0
			 e_count=e_count+1;
			 e_int=i;  % This term holds the index of the
			 		   % last entry with a non-zero term
			end
		 end
		end
	end
 
 
meme_count=[e_count meme_count(1:9)];
meme_int=[e_int meme_int(1:9)];

 

  

 

posted @ 2023-03-20 15:59  我爱C编程  阅读(181)  评论(0编辑  收藏  举报