📄 autogui.m
字号:
str = get(ud.Tuning,'String');
TUNING_METHOD = deblank(upper(str(get(ud.Tuning,'Value'),:)));
if strcmp(TUNING_METHOD,'ZN (OL)')
set(ud.TunParText,'String','');
set(ud.TuningParam,'Style','edit');
set(ud.TuningParam,'Visible','off');
set(ud.TuningParam,'String','');
TUNING_PARAM = [];
IDENTIFICATION_METHOD = 'STEP';
set(ud.Ident,'Value',1);
elseif strcmp(TUNING_METHOD,'ZN (CL)')
set(ud.TunParText,'String','');
set(ud.TuningParam,'Style','edit',...
'Visible','off',...
'String','');
TUNING_PARAM = [];
IDENTIFICATION_METHOD = 'RELAY';
set(ud.Ident,'Value',2);
elseif strcmp(TUNING_METHOD,'KT')
set(ud.TunParText,'String','Ms ');
set(ud.TuningParam,'Style','popupmenu',...
'String',['1.4';'2.0'],...
'Value',1,...
'Visible','on');
TUNING_PARAM = 1.4;
IDENTIFICATION_METHOD = 'STEP';
set(ud.Ident,'Value',1);
elseif strcmp(TUNING_METHOD,'IMC')
set(ud.TunParText,'String','lambda ');
set(ud.TuningParam,'Style','edit',...
'String','1',...
'Visible','on');
TUNING_PARAM = 1;
IDENTIFICATION_METHOD = 'STEP';
set(ud.Ident,'Value',1);
end
% end LocalTuning
%=============================================================================
% LocalEditParam
% The callback function for the edit field of the method of the parameter
%=============================================================================
function LocalEditParam
global TUNING_PARAM
global TUNING_METHOD
ud = get(gcbf,'UserData');
if strcmp(TUNING_METHOD,'KT')
if get(ud.TuningParam,'Value')==1;
TUNING_PARAM = 1.4;
elseif get(ud.TuningParam,'Value')==2;
TUNING_PARAM = 2.0;
end
elseif strcmp(TUNING_METHOD,'IMC')
TUNING_PARAM = str2num(get(ud.TuningParam,'String'));
end
% end LocalEditParam
%=============================================================================
% LocalStructure
% The callback function for the selection of the regulator structure
%=============================================================================
function LocalStructure
global TUNING_STRUCTURE
ud = get(gcbf,'UserData');
str = get(ud.Structure,'String');
TUNING_STRUCTURE = deblank(upper(str(get(ud.Structure,'Value'),:)));
% end LocalStructure
%=============================================================================
% LocalPIDSets
% Local function to set the position of the graphics objects in the PID GUI
% animation window.
%=============================================================================
function LocalPIDSets(time,ud,u)
global AUTOMAN
global AUTOTUNE
global PIDPARAMETERS
global INACTIVE
PVValue = u(1);
SPValue = str2num(get_param(ud.RefBlock,'Value'));
CVValue = u(2);
% time field
set(ud.TimeField,...
'String',num2str(time));
% process value & setpoint
set(ud.PV,...
'YData',[0 PVValue PVValue 0]);
set(ud.PVField,...
'String',num2str(PVValue,'%1.4f'));
set(ud.RefMark,...
'YData',[SPValue+0.25 SPValue SPValue-0.25]);
set(ud.SlideSP,...
'Value',SPValue);
set(ud.EditSP,...
'String',num2str(SPValue,'%1.4f'));
% process value & setpoint
set(ud.CV,...
'YData',[0 CVValue CVValue 0]);
if ~AUTOTUNE
set(ud.SlideCV,...
'Value',CVValue);
set(ud.EditCV,...
'String',num2str(CVValue,'%1.4f'));
end
if ~AUTOTUNE & INACTIVE
% Autotuning process completed (update parameters and set the GUI
% active)
% PID parameters
set(ud.SlideSP,'Enable','on');
set(ud.EditSP,'Enable','on');
if ~AUTOMAN
set(ud.SlideCV,'Enable','on');
set(ud.EditCV,'Enable','on');
end
set(ud.Man,'Enable','on');
set(ud.Auto,'Enable','on');
set(ud.EditK,'Enable','on');
set(ud.EditTi,'Enable','on');
set(ud.EditTd,'Enable','on');
set(ud.Editb,'Enable','on');
set(ud.EditN,'Enable','on');
set(ud.Ident,'Enable','on');
set(ud.Tuning,'Enable','on');
set(ud.TuningParam,'Enable','on');
set(ud.Structure,'Enable','on');
set(ud.EditK,...
'String',num2str(PIDPARAMETERS(1)));
set(ud.EditTi,...
'String',num2str(PIDPARAMETERS(2)));
set(ud.EditTd,...
'String',num2str(PIDPARAMETERS(3)));
set(ud.EditN,...
'String',num2str(PIDPARAMETERS(4)));
set(ud.Editb,...
'String',num2str(PIDPARAMETERS(5)));
INACTIVE = 0;
end
% Force plot to be drawn
pause(0), drawnow
% end LocalPIDSets
%=============================================================================
% LocalPIDInit
% Local function to initialize the PID GUI animation. If the animation
% window already exists, it is brought to the front. Otherwise, a new
% figure window is created.
%=============================================================================
function LocalPIDInit(RefBlock)
% The name of the reference is derived from the name of the
% subsystem block that owns the PID animation S-function block.
% This subsystem is the current system and is assumed to be the same
% layer at which the reference block resides.
sys = get_param(gcs,'Parent');
global AUTOTUNE
global AUTOMAN
global PIDPARAMETERS
global IDENTIFICATION_METHOD
global TUNING_METHOD
global TUNING_PARAM
global TUNING_STRUCTURE
global INACTIVE
INACTIVE = 1;
IDENTIFICATION_METHOD = 'STEP';
TUNING_METHOD = 'KT';
TUNING_PARAM = 1.4;
TUNING_STRUCTURE ='PID';
AUTOTUNE = 0;
AUTOMAN = 1;
TimeClock = 0;
PVValue = 0;
SPValue = str2num(get_param([sys '/' RefBlock],'Value'));
CVValue = 0;
% The animation figure handle is stored in the PID block's UserData.
% If it exists, initialize all the fields
Fig = get_param(gcbh,'UserData');
if ishandle(Fig),
FigUD = get(Fig,'UserData');
% time field
set(FigUD.TimeField,...
'String',num2str(TimeClock));
% process value & set point
set(FigUD.PV,...
'YData',[0 PVValue PVValue 0]);
set(FigUD.PVField,...
'String',num2str(PVValue));
set(FigUD.RefMark,...
'YData',[SPValue+0.25 SPValue SPValue-0.25]);
set(FigUD.SlideSP,...
'Value',0);
set(FigUD.EditSP,...
'String',num2str(PVValue));
% control variable
set(FigUD.CV,...
'YData',[0 CVValue CVValue 0]);
set(FigUD.EditCV,...
'String',num2str(CVValue),...
'Enable','off');
set(FigUD.SlideCV,...
'Value',CVValue,...
'Enable','inactive');
% auto/man selector
set(FigUD.Man,...
'Value',0);
set(FigUD.Auto,...
'Value',1);
% PID parameters
set(FigUD.EditK,...
'String',num2str(PIDPARAMETERS(1)),...
'Enable','on');
set(FigUD.EditTi,...
'String',num2str(PIDPARAMETERS(2)),...
'Enable','on');
set(FigUD.EditTd,...
'String',num2str(PIDPARAMETERS(3)),...
'Enable','on');
set(FigUD.EditN,...
'String',num2str(PIDPARAMETERS(4)),...
'Enable','on');
set(FigUD.Editb,...
'String',num2str(PIDPARAMETERS(5)),...
'Enable','on');
% autotuning
set(FigUD.Ident,...
'Value',1,...
'Enable','on');
set(FigUD.Tuning,...
'Value',2,...
'Enable','on');
set(FigUD.Structure,...
'Value',1,...
'Enable','on');
set(FigUD.TunParText,...
'String','Ms ');
set(FigUD.TuningParam,...
'Style','popupmenu',...
'String',['1.4';'2.0'],...
'Value',1,...
'Enable','on',...
'Visible','on');
% bring it to the front
figure(Fig);
return
end
% the animation figure doesn't exist, create a new one and store its
% handle in the animation block's UserData
FigureName = 'PID Control Panel';
% Figure
FigH = 610; % figure height
FigW = 272; % figure width
Fig = figure(...
'Units', 'pixel',...
'Position', [740 740-FigH FigW FigH],...
'Name', FigureName,...
'NumberTitle', 'off',...
'IntegerHandle', 'off',...
'HandleVisibility', 'callback',...
'MenuBar', 'none',...
'Resize', 'off',...
'DoubleBuffer', 'on',...
'DeleteFcn', 'autogui([],[],[],''DeleteFigure'')',...
'CloseRequestFcn', 'autogui([],[],[],''Close'');');
% Setpoint slider
SlideControlSP = uicontrol(...
'Parent', Fig,...
'Style', 'slider',...
'Units', 'pixel', ...
'Position', [25 FigH-325 22 300],...
'Min', -9,...
'Max', 9,...
'Value', 0,...
'BackgroundColor', [1 1 0],...
'Callback', 'autogui([],[],[],''SliderSP'');');
uicontrol(...
'Parent', Fig,...
'Style', 'text',...
'Units', 'pixel',...
'Position', [25 FigH-20 22 12], ...
'HorizontalAlignment','center',...
'String', 'SP',...
'Backgroundcolor', [0.8 0.8 0.8],...
'Foregroundcolor', [1 1 0],...
'Fontweight', 'bold');
% Process value
AxesPV = axes(...
'Parent', Fig,...
'Units', 'pixel',...
'Position', [75 FigH-325 22 300],...
'CLim', [1 64], ...
'Xlim', [-1 1],...
'Ylim', [-10 10],...
'Visible', 'on',...
'XTick', [],...
'XTickLabel', [],...
'FontSize', 8,...
'Box', 'on');
uicontrol(...
'Parent', Fig,...
'Style', 'text',...
'Units', 'pixel',...
'Position', [75 FigH-20 22 12], ...
'HorizontalAlignment','center',...
'String', 'PV',...
'Backgroundcolor', [0.8 0.8 0.8],...
'Foregroundcolor', [1 0 1],...
'Fontweight', 'bold');
PV = patch(...
'Parent', AxesPV,...
'XData', [-1 -1 1 1],...
'YData', [0 PVValue PVValue 0],...
'FaceColor', [1 0 1]);
uicontrol(...
'Parent', Fig,...
'Style', 'text',...
'Units', 'pixel',...
'Position', [106 FigH-175 50 14], ...
'Backgroundcolor', [0.8 0.8 0.8],...
'Foregroundcolor', [1 0 1],...
'HorizontalAlignment','center',...
'Fontweight', 'bold',...
'String', 'PV');
PVField = uicontrol(...
'Parent', Fig,...
'Style', 'text',...
'Units', 'pixel',...
'Position', [106 FigH-191 50 14], ...
'Backgroundcolor', [1 1 1],...
'Foregroundcolor', [0 0 0],...
'HorizontalAlignment','center',...
'String', num2str(PVValue));
RefMark = patch(...
'Parent', AxesPV,...
'XData', [-1 -0 -1],...
'YData', [SPValue+0.25 SPValue SPValue-0.25],...
'FaceColor', [1 1 0]);
uicontrol(...
'Parent', Fig,...
'Style', 'text',...
'Units', 'pixel',...
'Position', [106 FigH-100 50 14], ...
'Backgroundcolor', [0.8 0.8 0.8],...
'Foregroundcolor', [1 1 0],...
'HorizontalAlignment','center',...
'Fontweight', 'bold',...
'String', 'SP');
EditSP = uicontrol(...
'Parent', Fig,...
'Style', 'edit',...
'Units', 'pixel',...
'Position', [106 FigH-118 50 18], ...
'HorizontalAlignment','center',...
'String', num2str(SPValue),...
'Foregroundcolor', [0 0 0],...
'Backgroundcolor', [1 1 1],...
'Callback', 'autogui([],[],[],''EditSP'');');
% Control variable
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -