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

📄 doevent.m

📁 为了下载东西
💻 M
📖 第 1 页 / 共 3 页
字号:
   %
   %  Define callback strings for the command buttons.  These strings 
   %  specify how to respond when the user clicks the buttons.
   %
   cmdOK = [ ' watchon; global SOCLR SOCTC SOCDP;',...
             ' hUserInput1 = findobj(''Tag'',''hUserInput1''); ',...
             ' hUserInput2 = findobj(''Tag'',''hUserInput2''); ',...
             ' hUserInput3 = findobj(''Tag'',''hUserInput3''); ',...
             ' NewSOCLR = str2num(get(hUserInput1,''String'')); ', ...
             ' NewSOCTC = str2num(get(hUserInput2,''String'')); ', ...
             ' NewSOCDP = str2num(get(hUserInput3,''String'')); ', ...
             ' if ~isempty(NewSOCLR), ', ...
             '    SOCLR = NewSOCLR; ', ...
             ' end;',...
             ' if ~isempty(NewSOCTC), ', ...
             '    SOCTC = NewSOCTC; ', ...
             ' end;',...
             ' if ~isempty(NewSOCDP), ', ...
             '    SOCDP = NewSOCDP; ', ...
             ' end;',...
             ' delete(gcf); clear NewSOCLR NewSOCTC NewSOCDP;watchoff;'];
   cmdCancel   = 'delete(gcf);';
   KeyPressFcn = [''];
   %
   %  Load and get a handle to the input window, command buttons and editbox.
   %
   h = figure('Visible','off','NumberTitle','off','MenuBar','none', ...
              'Name',strTitle,'Position',posBox,'Resize','off','Color',[.75 .75 .75] ,'KeyPressFcn',KeyPressFcn);
   uicontrol('Style','frame','String','','Position',posFrame,'BackgroundColor',[.75 .75 .75]);
   uicontrol('Style','pushbutton','Units','pixels','Enable','on', ...
             'Position',posOK,'String','OK','Callback',cmdOK );
   uicontrol('Style','pushbutton','Units','pixels','Enable','on', ...
             'Position',posCancel,'String','Cancel','Callback',cmdCancel );
   uicontrol('Style','text','String',strSOCLR,'Position',posSOCLRLbl, ...
             'BackgroundColor',[.75 .75 .75],'HorizontalAlignment','left');
   uicontrol('Style','text','String',strSOCTC,'Position',posSOCTCLbl, ...
             'BackgroundColor',[.75 .75 .75],'HorizontalAlignment','left');
   uicontrol('Style','text','String',strSOCDP,'Position',posSOCDPLbl, ...
             'BackgroundColor',[.75 .75 .75],'HorizontalAlignment','left');
   uicontrol('Style','edit','Position',posSOCLREdit,'String',num2str(SOCLR), ...
             'BackgroundColor','White','Callback','','Tag','hUserInput1');
   uicontrol('Style','edit','Position',posSOCTCEdit,'String',num2str(SOCTC), ...
             'BackgroundColor','White','Callback','','Tag','hUserInput2');
   uicontrol('Style','edit','Position',posSOCDPEdit,'String',num2str(SOCDP), ...
             'BackgroundColor','White','Callback','','Tag','hUserInput3');
   set(h,'Visible','on');
   watchoff(fignumber);
   
elseif strcmp(strEvent,'CartSOCLR'),
   cmdOK = [' watchon; global SOCLR;',...
            ' hUserInput1 = findobj(''Tag'',''hUserInput1''); ',...
            ' NewSOCLR = str2num(get(hUserInput1,''String'')); ', ...
            ' if ~isempty(NewSOCLR), ', ...
            '    SOCLR = NewSOCLR; ', ...
            '    delete(gcf); ', ...
            ' end; clear NewSOCLR; watchoff;' ];
   inputbox('SOC Learning Rate','New value:  []',num2str(SOCLR),cmdOK,'hUserInput1');
   watchoff(fignumber);

elseif strcmp(strEvent,'CartSOCTC'),
   cmdOK = [' watchon; global SOCTC;',...
            ' hUserInput1 = findobj(''Tag'',''hUserInput1''); ',...
            ' NewSOCTC = str2num(get(hUserInput1,''String'')); ', ...
            ' if fand(~isempty(NewSOCTC),NewSOCTC>=0), ', ...
            '    SOCTC = NewSOCTC; ', ...
            '    delete(gcf); ', ...
            ' end; clear NewSOCTC;' ];
   inputbox('SOC Time Constant','New value:  [s]',num2str(SOCTC),cmdOK,'hUserInput1');
   watchoff(fignumber);

elseif strcmp(strEvent,'CartSOCDP'),
   cmdOK = [' watchon; global SOCDP;',...
            ' hUserInput1 = findobj(''Tag'',''hUserInput1''); ',...
            ' NewSOCDP = str2num(get(hUserInput1,''String'')); ', ...
            ' if fand(~isempty(NewSOCDP),NewSOCDP>=0), ', ...
            '    SOCDP = NewSOCDP; ', ...
            '    delete(gcf); ', ...
            ' end; clear NewSOCDP;' ];
   inputbox('SOC Penalty Delay','New value:  [s]',num2str(SOCDP),cmdOK,'hUserInput1');
   watchoff(fignumber);

elseif strcmp(strEvent,'CartSOCDef'),
   %
   %  Set the cart SOC parameters to their default values.
   %
   SOCLR = 10; SOCTC = 0.5; SOCDP = 0.1;
   watchoff(fignumber);


%##############################################################################
%
%  BALL MENU EVENTS
%

elseif strcmp(strEvent,'BallGains'),
   MainPos = get(gcf,'Position');
   MainX = MainPos(1); MainY = MainPos(2); MainW = MainPos(3); MainH = MainPos(4);
   %
   %  Define spacing, width and height of buttons and input window:
   %
   numEdit=3;
   gap=10; 
   BtnW=100; BtnH=25; 
   LabelW = 100;
   EditW=50; EditH=20;
   BoxW=350; BoxH=(4+numEdit-1)*gap+numEdit*EditH; 
   %
   %  Set up position matrices for the window, editbox and buttons:
   %
   posBox      = [MainX+(MainW-BoxW)/2 MainY+(MainH-BoxH)/2 BoxW BoxH];
   posFrame    = [gap gap BoxW-BtnW-3*gap BoxH-2*gap];
   posOK       = [BoxW-gap-BtnW BoxH-gap-BtnH BtnW BtnH];
   posCancel   = [BoxW-gap-BtnW BoxH-2*(gap+BtnH) BtnW BtnH];
   posG3Lbl    = [2*gap BoxH-2*gap-EditH LabelW EditH-gap/2];
   posG4Lbl    = [2*gap BoxH-3*gap-2*EditH LabelW EditH-gap/2];
   posGU2Lbl   = [2*gap BoxH-4*gap-3*EditH LabelW EditH-gap/2];
   posG3Edit   = [BoxW-BtnW-EditW-3*gap BoxH-2*gap-EditH EditW EditH];
   posG4Edit   = [BoxW-BtnW-EditW-3*gap BoxH-3*gap-2*EditH EditW EditH];
   posGU2Edit  = [BoxW-BtnW-EditW-3*gap BoxH-4*gap-3*EditH EditW EditH];
   strTitle    = 'Edit Ball Gains';
   strG3       = 'Ball Angle Gain';
   strG4       = 'Ball Velocity Gain';
   strGU2      = 'Ball Output Gain';
   %
   %  Define callback strings for the command buttons.  These strings 
   %  specify how to respond when the user clicks the buttons.
   %
   cmdOK = [ ' watchon; global G3 G4 GU2;',...
             ' hUserInput1 = findobj(''Tag'',''hUserInput1''); ',...
             ' hUserInput2 = findobj(''Tag'',''hUserInput2''); ',...    
             ' hUserInput3 = findobj(''Tag'',''hUserInput3''); ',... 
             ' NewG3 = str2num(get(hUserInput1,''String'')); ', ...
             ' NewG4 = str2num(get(hUserInput2,''String'')); ', ...
             ' NewGU2 = str2num(get(hUserInput3,''String'')); ', ...
             ' if ~isempty(NewG3), ', ...
             '    G3 = NewG3; hBallPos = findobj(''Tag'',''txtBallPos'');',...
             '    dispinfo(''G3'',G3,hBallPos); ', ...
             ' end;',...
             ' if ~isempty(NewG4), ', ...
             '    G4 = NewG4; hBallVel = findobj(''Tag'',''txtBallVel'');',...
             '    dispinfo(''G4'',G4,hBallVel); ', ...
             ' end;',...
             ' if ~isempty(NewGU2), ', ...
             '    GU2 = NewGU2; hBallOut = findobj(''Tag'',''txtBallOut'');',...
             '    dispinfo(''GU2'',GU2,hBallOut); ', ...
             ' end;',...
             ' delete(gcf); clear NewG3 NewG4 NewGU2;'];
   cmdCancel   = 'delete(gcf);';
   KeyPressFcn = [''];
   %
   %  Load and get a handle to the input window, command buttons and editbox.
   %
   h = figure('Visible','off','NumberTitle','off','MenuBar','none', ...
              'Name',strTitle,'Position',posBox,'Resize','off','Color',[.75 .75 .75] ,'KeyPressFcn',KeyPressFcn);
   uicontrol('Style','frame','String','','Position',posFrame,'BackgroundColor',[.75 .75 .75]);                            
   uicontrol('Style','pushbutton','Units','pixels','Enable','on', ...
             'Position',posOK,'String','OK','Callback',cmdOK );
   uicontrol('Style','pushbutton','Units','pixels','Enable','on', ...
             'Position',posCancel,'String','Cancel','Callback',cmdCancel );
   uicontrol('Style','text','String',strG3,'Position',posG3Lbl, ...
             'BackgroundColor',[.75 .75 .75],'HorizontalAlignment','left');
   uicontrol('Style','text','String',strG4,'Position',posG4Lbl, ...
             'BackgroundColor',[.75 .75 .75],'HorizontalAlignment','left');
   uicontrol('Style','text','String',strGU2,'Position',posGU2Lbl, ...
             'BackgroundColor',[.75 .75 .75],'HorizontalAlignment','left');
   uicontrol('Style','edit','Position',posG3Edit,'String',num2str(G3), ...
             'BackgroundColor','White','Callback','','Tag','hUserInput1');
   uicontrol('Style','edit','Position',posG4Edit,'String',num2str(G4), ...
             'BackgroundColor','White','Callback','','Tag','hUserInput2');
   uicontrol('Style','edit','Position',posGU2Edit,'String',num2str(GU2), ...
             'BackgroundColor','White','Callback','','Tag','hUserInput3');
   set(h,'Visible','on');
   watchoff(fignumber);

elseif strcmp(strEvent,'BallGainAng'),
   cmdOK = [' watchon; global G3;',...
            ' hUserInput1 = findobj(''Tag'',''hUserInput1''); ',...
            ' NewG3 = str2num(get(hUserInput1,''String'')); ', ...
            ' if ~isempty(NewG3), ', ...
            '    G3 = NewG3; hBallPos = findobj(''Tag'',''txtBallPos'');', ...
            '    delete(gcf); dispinfo(''G3'',G3,hBallPos);', ...
            ' end; clear NewG3;' ];
   inputbox('Ball Angle Gain','New value:  []',num2str(G3),cmdOK,'hUserInput1');
   watchoff(fignumber);

elseif strcmp(strEvent,'BallGainVel'),
   cmdOK = [' watchon; global G4;',...
            ' hUserInput1 = findobj(''Tag'',''hUserInput1''); ',...
            ' NewG4 = str2num(get(hUserInput1,''String'')); ', ...
            ' if ~isempty(NewG4), ', ...
            '    G4 = NewG4; hBallVel = findobj(''Tag'',''txtBallVel'');', ...
            '    delete(gcf); dispinfo(''G4'',G4,hBallVel);', ...
            ' end; clear NewG4;' ];
   inputbox('Ball Velocity Gain','New value:  []',num2str(G4),cmdOK,'hUserInput1');
   watchoff(fignumber);

elseif strcmp(strEvent,'BallGainOut'),
   cmdOK = [' watchon; global GU2;',...
            ' hUserInput1 = findobj(''Tag'',''hUserInput1''); ',...
            ' NewGU2 = str2num(get(hUserInput1,''String'')); ', ...
            ' if ~isempty(NewGU2), ', ...
            '    GU2 = NewGU2; hBallOut = findobj(''Tag'',''txtBallOut'');', ...
            '    delete(gcf); dispinfo(''GU2'',GU2,hBallOut);', ...
            ' end; clear NewGU2;' ];
   inputbox('Ball Output Gain','New value:  []',num2str(GU2),cmdOK,'hUserInput1');
   watchoff(fignumber);

elseif strcmp(strEvent,'BallGainDef'),
   %
   %  Set the ball gains to their default values and
   %  update the gains displayed in the main window.
   %
   G3 = 332; G4 = 86; GU2 = 0.5;
   hBallPos = findobj('Tag','txtBallPos');
   hBallVel = findobj('Tag','txtBallVel');
   hBallOut = findobj('Tag','txtBallOut');
   dispinfo('G3',G3,hBallPos);
   dispinfo('G4',G4,hBallVel);
   dispinfo('GU2',GU2,hBallOut);
   watchoff(fignumber);

elseif strcmp(strEvent,'BallSets'),
   %
   %  Open the fuzzy set editing window.
   %
   editsets('ballsets');
   watchoff(fignumber);

elseif strcmp(strEvent,'BallBase'),
   %
   %  Open the fuzzy rule base editing window.
   %
   editbase('ballbase.txt');
   watchoff(fignumber);

elseif strcmp(strEvent,'BallTable'),
   %
   %  Load both of the fuzzy control tables.  Recompute the ball
   %  control table, and then save both tables again.
   %
   load fzytable;
   BallTable = balltabl(BallRules);
   save fzytable CartTable BallTable;
   watchoff(fignumber);

elseif strcmp(strEvent,'BallSurface'),
   %
   %  Load the control tables.  Display a filled surface plot of
   %  the cart table.  Set appropriate titles and axis limits.
   %
   load fzytable;
   window('Ball Control Surface','figure');
   surfl(-100:10:100,-100:10:100,BallTable'); 
   title('Ball Control Surface');
   xlabel('Angle'); ylabel('Angular Velocity');
   axis([-100 100 -100 100 -200 200]);view([1,-1,1])
   watchoff(fignumber);


%##############################################################################
%
%  SIMULATION MENU EVENTS
%
elseif ~isempty(findstr(strEvent,'SimCon')),
   %
   %  Set the global variable ConType and check menus.
   %
   hConType = findobj('Tag','txtConType');
   ConType = setctrlr(strEvent,hConType);
   %
   %  Recompute fuzzy control tables if the table based or SOC controller
   %  was selected.
   %
   if (strcmp(strEvent,'SimConTbl') | strcmp(strEvent,'SimConSOC')),
      load fzytable;
      BallTable = balltabl(BallRules);
      CartTable = carttabl(CartRules);
      save fzytable CartTable BallTable ;
   end;
   watchoff(fignumber);
 
elseif strcmp(strEvent,'SimInt'),
   cmdOK = [' watchon; global Ts;',...
            ' hUserInput1 = findobj(''Tag'',''hUserInput1''); ',...
            ' NewTs = str2num(get(hUserInput1,''String'')); ', ...
            ' if fand(~isempty(NewTs),NewTs>=0), ', ...
            '    Ts = NewTs; hStep = findobj(''Tag'',''txtStep'');', ...
            '    delete(gcf); dispinfo(''Ts'',Ts,hStep);', ...
            ' end; clear NewTs;' ];
   inputbox('Step size','New value:  [s]',num2str(Ts),cmdOK,'hUserInput1');
   watchoff(fignumber);
   
elseif strcmp(strEvent,'SimPer'),
   cmdOK = [' watchon; global Ttot;',...
            ' hUserInput1 = findobj(''Tag'',''hUserInput1''); ',...   
            ' NewTtot = str2num(get(hUserInput1,''String'')); ', ...
            ' if fand(~isempty(NewTtot),NewTtot>=0), ', ...
            '    Ttot = NewTtot; hTtot = findobj(''Tag'',''txtTtot'');', ...
            '    delete(gcf); dispinfo(''Ttot'',Ttot,hTtot);', ...
            ' end; clear NewTtot;' ];
   inputbox('Stop Time','New value:  [s]',num2str(Ttot),cmdOK,'hUserInput1');
   watchoff(fignumber);

elseif strcmp(strEvent,'SimIni'),
   MainPos = get(gcf,'Position');
   MainX = MainPos(1); MainY = MainPos(2); MainW = MainPos(3); MainH = MainPos(4);
   %
   %  Define spacing, width and height of buttons and input window:
   %
   numEdit=4;
   gap=10; 
   BtnW=100; BtnH=25; 
   LabelW = 100;
   EditW=50; EditH=20;
   BoxW=350; BoxH=(4+numEdit-1)*gap+numEdit*EditH; 
   %
   %  Set up position matrices for the window, editbox and buttons:
   %
   posBox      = [MainX+(MainW-BoxW)/2 MainY+(MainH-BoxH)/2 BoxW BoxH];
   posFrame    = [gap gap BoxW-BtnW-3*gap BoxH-2*gap];
   posOK       = [BoxW-gap-BtnW BoxH-gap-BtnH BtnW BtnH];
   posCancel   = [BoxW-gap-BtnW BoxH-2*(gap+BtnH) BtnW BtnH];
   posYLbl     = [2*gap BoxH-2*gap-EditH LabelW EditH-gap/2];
   posdYLbl    = [2*gap BoxH-3*gap-2*EditH LabelW EditH-gap/2];
   posPhiLbl   = [2*gap BoxH-4*gap-3*EditH LabelW EditH-gap/2];
   posdPhiLbl  = [2*gap BoxH-5*gap-4*EditH LabelW EditH-gap/2];   
   posYEdit    = [BoxW-BtnW-EditW-3*gap BoxH-2*gap-EditH EditW EditH];
   posdYEdit   = [BoxW-BtnW-EditW-3*gap BoxH-3*gap-2*EditH EditW EditH];
   posPhiEdit  = [BoxW-BtnW-EditW-3*gap BoxH-4*gap-3*EditH EditW EditH];
   posdPhiEdit = [BoxW-BtnW-EditW-3*gap BoxH-5*gap-4*EditH EditW EditH];   
   strTitle = 'Edit Initial Conditions';
   strY = 'Cart Position';
   strdY = 'Cart Velocity';
   strPhi = 'Ball Angle';
   strdPhi = 'Ball Angular Velocity';   
   %
   %  Define callback strings for the command buttons.  These strings 
   %  specify how to respond when the user clicks the buttons.
   %
   cmdOK = [ 'watchon; global Y dY Phi dPhi;',...
             'hUserInput1 = findobj(''Tag'',''hUserInput1''); ',...
             'hUserInput2 = findobj(''Tag'',''hUserInput2''); ',...
             'hUserInput3 = findobj(''Tag'',''hUserInput3''); ',...
             'hUserInput4 = findobj(''Tag'',''hUserInput4''); ',...
             'NewY = str2num(get(hUserInput1,''String'')); ', ...
             'NewdY = str2num(get(hUserInput2,''String'')); ', ...

⌨️ 快捷键说明

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