📄 ctrllab.m
字号:
%CtrlLAB is the main module of CtrlLAB. The function syntax is as follows:
%
% ctrllab(key,arg1,agr2)
%
%if no argument is specified, then the command executes the main interface.
%If there are extra arguments, then
%
% key=0, for program initialization if arg1 not existing,
% or menu enabling, if arg1 exists
% key=1, displays and executes the tutorials
% key=2, perform and display realization of plant model
% key=3, add extra block to the plant model not
% implemented yet.
%
%The functions available in the module are
%
% ctrllab_blocks -- draw the system blocks
% ctrllab_toolbar -- creates a toolbar (for MATLAB 5.2+ only)
% ctrllab_menu -- creates the main menu system
% arrow_shw -- draw arrows in current window
% ctrllab_init -- perform initialization in CtrlLAB
% shw_tutorial -- activate the toturial program in CtrlLAB
% plant_realiz -- displays the realization of plant model
% add_sys_blocks -- adds the extra system properties to the plant
% file_proc -- process the file open/save and quiting tasks
% select_sigs -- allows one to select signals from the block diagram
%
%Copyright (c) 1997-1999 by Professor Dingyu Xue
%School of Information Science and Engineering, Northeastern University
%Shenyang 110006, P R China
%Email: xue_dy@hotmail.com
%-------------------------------------------------------------------------
function ctrllab(key,arg1,agr2)
%get the handle of the main window
h_main=findobj('Tag','CtrlLABMain');
if nargin==0
%start the program
if length(h_main)==0
%if no such a window exists, then open a new main window
h_main=figure('Units','normalized','Position',[0.1575 0.34 0.56125 0.448333], ...
'NumberTitle','off','Name','CtrlLAB Feedback Control Systems Laboratory', ...
'MenuBar','none','Color',0.8*[1,1,1],'CloseRequestFcn','ctrllab(5,4);',...
'Tag','CtrlLABMain','Resize','off');
ctrllab_blocks;
[v,d]=version; v1=eval(v(1)); v2=eval(v(3));
if v1>=5 & v2>=2,
ctrllab_toolbar;
set_contxtmenu(0); set_contxtmenu(1); set_contxtmenu(2);
set_contxtmenu(3); set_contxtmenu(4);
end
ctrllab_menu;
ctrllab_init(0);
else,
%if the main window exists, bring it to front
figure(h_main);
end
else
%perform extra actions
switch key
case 0, %initialization of the program
if nargin==1, ctrllab_init(0);
else, ctrllab_init(arg1); end
case 1, shw_tutorial(arg1); %perform tutorials
case 2, plant_realiz(arg1); %perform and display the realization of the plant model
case 3, add_sys_blocks(arg1); %add extra blocks to the plant model
case 5, file_proc(arg1); %call file_proc to process the File menu
case 6, select_sigs(arg1); %select output signals
case 7, set_openloop; %setting open-loop selections
case 8,
uu0=get(h_main,'UserData'); g1=get(uu0{1}(1),'UserData');
if length(g1)>0, matx_proc;
else,
warndlg('Plant model dose not exist, please enter it first!','Matrix Processor Warning:');
end
end
end
%---------------------------------------------------------------------------------
%ctrllab_blocks is used to create all the block buttons and draw the block diagram
%of typical feedback control structure on the main window.
%---------------------------------------------------------------------------------
function ctrllab_blocks()
extra_funs(1,[0.05,0.05,0.9,0.6]);
fill([0 1 1 0 0],[0 0 1 1 0],[0.502, 1, 1])
set(gca,'visible','off');
arrow_shw([0.87 0.60],[0.97,0.60],0.5,[0 0 0]);
arrow_shw([0.615 0.60],[0.715,0.60],0.5,[0 0 0]);
arrow_shw([0.395 0.60],[0.495,0.60],0.5,[0 0 0]);
arrow_shw([0.14 0.60],[0.24,0.60],0.5,[0 0 0]);
arrow_shw([0.01 0.60],[0.10,0.60],0.5,[0 0 0]);
hc(1)=line([0.92,0.92 0.70],[0.60,0.175 0.175]);
t=0:.1:2*pi+0.1; x1=0.12+0.02*cos(t); y1=0.60+0.05*sin(t);
hc(2)=line(x1,y1);
arrow_shw([0.70 0.175],[0.60,0.175],0.5,[0 0 0]);
arrow_shw([0.12 0.175],[0.12,0.55],0.05,[0 0 0]);
hc(3)=line([0.12,0.50],[0.175,0.175]); set(hc,'Color','k');
%display the title and its shading
display_str(0.116,0.83,'Typical Continuous Linear Feedback Structure',[1,1,0],'on',16,'Brush Script MT');
display_str(0.11,0.85,'Typical Continuous Linear Feedback Structure',[1,0,0],'on',16,'Brush Script MT');
hc=extra_funs(10,[0.4824,0.3224],[0.8969,0.7450]);
set(hc,'LineStyle',':','Color',[0,0,1]);
display_str(0.64,0.39,'Plant Model',[0,0,1],'on',9,'Times New Roman','normal','italic');
%labelling signal legends
[xL,h_Sig(1)]=display_str(0.17,0.67,'e(t)',[0.6,0.6,0],'on',9);
[xL,h_Sig(2)]=display_str(0.42,0.67,'u(t)',[0.6,0.6,0],'on',9);
[xL,h_Sig(3)]=display_str(0.92,0.67,'y(t)',[1,0,0],'on',9);
[xL,h_Sig(4)]=display_str(0.03,0.67,'\gamma(t)',[0,0,0],'on',9);
display_str(0.09,0.53,'\_',[0,0,0],'on',9);
set(h_Sig(1),'ButtonDownFcn','ctrllab(6,1);');
set(h_Sig(2),'ButtonDownFcn','ctrllab(6,2);');
set(h_Sig(3),'ButtonDownFcn','ctrllab(6,3);');
bSys(1) = uicontrol('Style','PushButton','String','G(s)',...
'Units','normalized','Position',[0.50 0.35 0.14 0.115],'Callback','proc_model(0,1);');
bSys(2) = uicontrol('Style','PushButton','String','Gc(s)',...
'Units','normalized','Position',[0.269 0.35 0.14 0.115],'Callback','proc_model(0,2);');
bSys(3) = uicontrol('Style','PushButton','String','H(s)',...
'Units','normalized','Position',[0.45 0.10 0.14 0.115],'Callback','proc_model(0,3);');
bSys(4) = uicontrol('Style','PushButton','String','Exp(-Ts)',...
'Units','normalized','Position',[0.695 0.35 0.14 0.112],'Callback','proc_model(0,4);');
%set the information to window's UserData. The first four elements are the handles
%of the four blocks. The fifth,
%the sixth if 1 if there is unsaved model
%the seventh is the handle of the main window. The eighth is the signal selection.
set(gcf,'UserData',{[bSys,0,0,0,h_Sig]});
%----------------------------------------------------------------------
%ctrllab_menus is used to create all the menu items in the main window.
%----------------------------------------------------------------------
function ctrllab_toolbar()
load ctrllab_cdata; load clab_disp_cdata;
yy=get(gcf,'Position'); screen=get(0,'ScreenSize'); ymax=yy(4)*screen(4)-20;
uicontrol('Style','PushButton','Units','pixels','Position',[2,ymax,20,20],...
'CData',fnew_dat,'CallBack','ctrllab(0);','TooltipString','CtrlLAB initialization');
uicontrol('Style','PushButton','Units','pixels','Position',[22,ymax,20,20],...
'CData',fopen_dat,'CallBack','ctrllab(5,1);','TooltipString','Load models');
uicontrol('Style','PushButton','Units','pixels','Position',[42,ymax,20,20],...
'CData',fsave_dat,'CallBack','ctrllab(5,2);','TooltipString','Save models');
uicontrol('Style','PushButton','Units','pixels','Position',[65,ymax,20,20],...
'CData',help_dat,'CallBack','clab_help(0);','TooltipString','Introduction');
uicontrol('Style','PushButton','Units','pixels','Position',[88,ymax,20,20],...
'CData',tf_dat,'CallBack','extra_funs(4,3,''Checked'',20,[21:23]); proc_model(1);',...
'TooltipString','Transfer Function');
uicontrol('Style','PushButton','Units','pixels','Position',[108,ymax,20,20],...
'CData',ss_dat,'CallBack','extra_funs(4,3,''Checked'',21,[20,22,23]); proc_model(1);',...
'TooltipString','State Space');
uicontrol('Style','PushButton','Units','pixels','Position',[128,ymax,20,20],...
'CData',ftf_dat,'CallBack','extra_funs(4,3,''Checked'',23,[20:22]); proc_model(1);',...
'TooltipString','Factorized Transfer Function');
uicontrol('Style','PushButton','Units','pixels','Position',[148,ymax,20,20],...
'CData',matx_dat,'CallBack','ctrllab(8);','TooltipString','Matrix Processor');
uicontrol('Style','PushButton','Units','pixels','Position',[168,ymax,20,20],...
'CData',red_dat,'CallBack','mod_reduction(1);','TooltipString','Model Reduction');
uicontrol('Style','PushButton','Units','pixels','Position',[188,ymax,20,20],...
'CData',simu_dat,'CallBack','simu_modlib;','TooltipString','Model Library');
uicontrol('Style','PushButton','Units','pixels','Position',[211,ymax,20,20],...
'String','Bo','CallBack','sys_analysis(1);','TooltipString','Bode Diagram');
uicontrol('Style','PushButton','Units','pixels','Position',[231,ymax,20,20],...
'String','Ny','CallBack','sys_analysis(2);','TooltipString','Nyquist Plot');
uicontrol('Style','PushButton','Units','pixels','Position',[251,ymax,20,20],...
'String','Nic','CallBack','sys_analysis(3);','TooltipString','Nichols Chart');
uicontrol('Style','PushButton','Units','pixels','Position',[271,ymax,20,20],...
'String','Inv','CallBack','sys_analysis(4);','TooltipString','Inverse Nyquist Plot');
uicontrol('Style','PushButton','Units','pixels','Position',[291,ymax,20,20],...
'String','RL','CallBack','sys_analysis(5);','TooltipString','Inverse Nyquist Plot');
uicontrol('Style','PushButton','Units','pixels','Position',[311,ymax,20,20],...
'String','St','CallBack','sys_analysis(6);','TooltipString','Step Response');
uicontrol('Style','PushButton','Units','pixels','Position',[331,ymax,20,20],...
'String','Im','CallBack','sys_analysis(7);','TooltipString','Impulse Response');
uicontrol('Style','PushButton','Units','pixels','Position',[354,ymax,20,20],...
'CData',openl_dat,'CallBack','ctrllab(6,5);','TooltipString','Open Loop');
uicontrol('Style','PushButton','Units','pixels','Position',[374,ymax,20,20],...
'CData',closel_dat,'CallBack','ctrllab(6,6);','TooltipString','Closed Loop');
uu0=get(gcf,'UserData');
set(uu0{1}(1),'TooltipString','Plant Model'); set(uu0{1}(2),'TooltipString','Controller Model');
set(uu0{1}(3),'TooltipString','Feedback Model Model'); set(uu0{1}(4),'TooltipString','Time Delay Model');
%----------------------------------------------------------------------
%ctrllab_menus is used to create all the menu items in the main window.
%----------------------------------------------------------------------
function ctrllab_menu()
% Defining menu systems
%
% (1) The File menu system definitions
hMFile(1)=uimenu(gcf,'Label','&File');
hMFile(2)=uimenu(hMFile(1),'Label','&New','CallBack','ctrllab(0);');
hMFile(3)=uimenu(hMFile(1),'Label','&Open ...','CallBack','ctrllab(5,1);');
hMFile(4)=uimenu(hMFile(1),'Label','&Save','CallBack','ctrllab(5,2);');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -