⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gui_pi1.m

📁 FISMAT accommodates different arithmetic operators, fuzzification and defuzzification algorithm, imp
💻 M
字号:
function GUI_PI1(action,in1,in2);% GUI_PI1%% GUI driven demonstration file for a fuzzy PI type controller.%%% FSTB - Fuzzy Systems Toolbox for MATLAB% Copyright (c) 1993-1996 by Olaf Wolkenhauer% Control Systems Centre at UMIST% Manchester M60 1QD, UK%% 19-October-19946% Last change 21/11/96%	possible actions:%	  'start'          	initialises the demo file.%	  'redraw'		following each change in menus redraw%	  'done'		exit the demo%	  'reason'		approximate reasoning procedure if nargin<1,    action='start';end;% Declare handles of menus global :  global AND_Hndl OR_Hndl% Declare variables global :  global ESET OSET E AND_OP OR_OP OUTPUT% Declare axes for plots global :  global surf_axes cont_axesif strcmp(action,'start'),	  % Graphics initialization  oldFigNumber = watchon;  figNumber = figure;  set(gcf, ...      'NumberTitle','off', ...      'Name','Fuzzy PI Control', ...      'backingstore','off',...      'Units','normalized');  % Information for all buttons  labelColor=192/255*[1 1 1];  top=0.95; bottom=0.05;  yInitLabelPos=0.90;  left = 0.78; left_label=left-0.004;  labelWid=0.18; labelHt=0.05;  btnWid = 0.18; btnHt=0.07;  % Spacing between the label and the button for the same command  btnOffset=0.003;    % Spacing between the button and the next command's label  spacing=0.05; % vertical gap    % The CONSOLE frame  frmBorder=0.02;  yPos=0.05-frmBorder;  frmPos=[left-frmBorder yPos btnWid+2*frmBorder 0.9+2*frmBorder];  console_Hndl=uicontrol( ...    'Style','frame', ...    'Units','normalized', ...    'Position',frmPos, ...    'BackgroundColor',[0.5 0.5 0.5]);   % The AND_OP command popup button/menu  btnNumber=1;  yLabelPos=top-(btnNumber-1)*(btnHt+labelHt+spacing);  % Generic label information  labelPos=[left_label yLabelPos-labelHt labelWid labelHt];  uicontrol( ...    'Style','text', ...    'Units','normalized', ...    'Position',labelPos, ...    'BackgroundColor',labelColor, ...    'HorizontalAlignment','Center', ...    'String',' AND');  btnPos=[left yLabelPos-labelHt-btnHt-btnOffset btnWid btnHt];  AND_Hndl=uicontrol( ...    'Style','Popup',...    'String','t3mi|twdp|t1bd|t15ep|t2ap',...    'Position', btnPos, ...    'Value',[ 1 ],...    'Units','normalized',...    'CallBack','GUI_PI1(''redraw'')');   % The OR_OP command popup button/menu  btnNumber=2;  yLabelPos=top-(btnNumber-1)*(btnHt+labelHt+spacing);    % Generic label information  labelPos=[left_label yLabelPos-labelHt labelWid labelHt];  uicontrol( ...    'Style','text', ...    'Units','normalized', ...    'Position',labelPos, ...    'BackgroundColor',labelColor, ...    'HorizontalAlignment','Center', ...    'String',' OR');  % Generic popup button information  btnPos=[left yLabelPos-labelHt-btnHt-btnOffset btnWid btnHt];  OR_Hndl = uicontrol( ...    'Style','popup', ...    'Units','normalized', ...    'Position',btnPos, ...    'String','s3ma|swds|s1bs|s15es|s2as', ...    'Value', [ 1 ], ...    'Callback','GUI_PI1(''redraw'')');    % The INFO button  uicontrol( ...    'Style','push', ...    'Units','normalized', ...    'Position',[left bottom+(2*labelHt)+spacing btnWid 2*labelHt], ...    'String','Info', ...    'Callback','GUI_PI1(''info'')');   % The CLOSE button  done_button=uicontrol('Style','Pushbutton', ...    'Position',[left bottom btnWid 2*labelHt], ...    'Units','normalized','Callback',...    'GUI_PI1(''done'')','String','Close');  % Define input and output sets :  ESET=[-1 0 1];  OSET=[-1 -0.5 0 0.5 1];  % Create axes for plots :  surf_axes  = axes('Position',[.1 .58 .3 .3], ...                    'XLim',[-1 1],'YLim',[-1 1],'ZLim',[-1 1]);  cont_axes = axes('Position',[.1 .14 .3 .3], ...                   'XLim',[-1 1],'YLim',[-1 1]);  eset_axes = axes('Position',[.47 .63 .25 .2], ...                    'XLIm',[-1 1],'YLim',[0 1.1]);  oset_axes = axes('Position',[.47 .19 .25 .2], ...                    'XLIm',[-1 1],'YLim',[0 1.1]);  % Note: if the sets will later to be manipulaed with click&drag,  %       declare axes global and put the following things under   %       redraw :  axes(eset_axes); plot_set(ESET); title('Input Fuzzy Sets');  xlabel('error and error rate');  axes(oset_axes); plot_set(OSET); title('Output Fuzzy Sets');  xlabel('universe of discourse');  % Create intial result for reasonig procedure :  GUI_PI1('redraw');elseif strcmp(action,'done'),  close(gcf);  clear global ESET OSET AND_OP OR_OP E OUTPUT  clear global AND_Hndl OR_Hndl  clear global surf_axes cont_axeselseif strcmp(action,'redraw'),  % recomputes outset and output value and updates display  val = get(AND_Hndl,'Value');  if (val == 1),    AND_OP='t3mi';  elseif (val == 2),    AND_OP='twdp';  elseif (val == 3),   AND_OP='t1bd';  elseif (val == 4),   AND_OP='t15ep';  elseif (val == 5),   AND_OP='t2ap';  end;  val = get(OR_Hndl,'Value');  if (val == 1),    OR_OP='s3ma';  elseif (val == 2),    OR_OP='swds';  elseif (val == 3),    OR_OP='s1bs';  elseif (val == 4),    OR_OP='s15es';  elseif (val == 5),    OR_OP='s2as';  end;  % Determine control surface of the specified controller :  % Procedure is taken from the file ctr_surf.m  stepsize=10;		% defines resolution.  bo=[-1 1 -1 1]; 	% defines range  bs=(bo(4)-bo(3))/stepsize;  as=(bo(2)-bo(1))/stepsize;  zvalues=zeros(stepsize+1,stepsize+1); % +1 to get the full range.  error=bo(1);  xv=zeros(3,1);  % ESET corresponds to the x-axis. DESET corresponds to the y-axis.  for x=1:stepsize+1,          % x-axis corresponds to e - and the columns.    derror=bo(3);    for y=1:stepsize+1,        % y-axis corresponds to de - and the rows.      E=[error;derror];      GUI_PI1('reason');      zvalues(y,x)=OUTPUT;      xv(1)=error; xv(3)=OUTPUT;      derror=derror+bs;    end;    xv(2)=derror;    error=error+as;  end;  xvalues=linspace(bo(1),bo(2),stepsize+1);  yvalues=linspace(bo(3),bo(4),stepsize+1);   watchoff(oldFigNumber);  axes(surf_axes);  surf(xvalues,yvalues,zvalues); grid  set(surf_axes, ...     'XLabel', text(0,0,'error'), ...     'YLabel', text(0,0,'rate'), ...     'ZLabel', text(0,0,'output'));  text(1.5, 5,'                                       Fuzzy PI Control');  axes(cont_axes);  contour(xvalues,yvalues,zvalues);  set(cont_axes, ...     'XLabel', text(0,0,'error e'), ...     'YLabel', text(0,0,'de/dt'));  drawnowelseif strcmp(action,'reason'),  % Fuzzification :  enT=fuzzsiyi(ESET,E(1));       % E(1) corresponds to the error   rnT=fuzzsiyi(ESET,E(2));       % E(2) corresponds to the rate of error  % horizontal direction corresponds to enT.  % vertical direction corresponds to rnT.  NB=1; NS=2; NZ=3; PS=4; PB=5;  rt=[NB NS NZ ;      NS NZ PS ;      NZ PS PB];  rb=rtinf(rt,enT,rnT,AND_OP,OR_OP);   % Defuzzification:  OUTPUT=OSET*rb; elseif strcmp(action,'info'),  ttlStr = 'Fuzzy PI Control';   hlpStr1= ...                                                  ['  						  '];  hlpStr2= ...                                                   ['  						  '];  hlpStr3= str2mat(...                       ' ', ...    ' File name: GUI_PI1.m');  helpfun(ttlStr, hlpStr1, hlpStr2, hlpStr3);end; % of GUI_PI1.m

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -