AutotunerPID Toolkit Previous page   Next Page

autogui

PURPOSE ^

Matlab S-function for making a simple PID GUI.

SYNOPSIS ^

function [sys,x0,str,ts] = autogui(t,x,u,flag,RefBlock)

DESCRIPTION ^

AUTOGUI S-function for making a simple PID GUI
 
   When the model autotunerPID.mdl is run, this S-function create a panel
   which closer resemble the layout of a typical real industrial autotuner
   (at least in the control options). 
   The upper part of the GUI is used to interact with the control system,
   by changing the set-point value and by reading the value of the process
   value and the control variable.  Moreover when used in MANUAL mode the
   control variable is under the direct control of the user.  The
   parameters area shows the parameter of the PID which can be changed 
   online (except for the derivative weight c which is fixed to 0.
   The last two areas allow to select the operating mode (AUTO/MANUAL) and
   the autotuning method, split in the selection of the identification
   method, the selection of the tuning method and the selection of the
   regulator structure.

   Everything started looking at PENDAN, an S-function for making pendulum
   animation

   Author:    William Spinelli (wspinell@elet.polimi.it)
   Copyright  2004 W.Spinelli
   $Revision: 1.0 $  $Date: 2004/02/27 12:00:00 $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [sys,x0,str,ts] = autogui(t,x,u,flag,RefBlock)
0002 %AUTOGUI S-function for making a simple PID GUI
0003 %
0004 %   When the model autotunerPID.mdl is run, this S-function create a panel
0005 %   which closer resemble the layout of a typical real industrial autotuner
0006 %   (at least in the control options).
0007 %   The upper part of the GUI is used to interact with the control system,
0008 %   by changing the set-point value and by reading the value of the process
0009 %   value and the control variable.  Moreover when used in MANUAL mode the
0010 %   control variable is under the direct control of the user.  The
0011 %   parameters area shows the parameter of the PID which can be changed
0012 %   online (except for the derivative weight c which is fixed to 0.
0013 %   The last two areas allow to select the operating mode (AUTO/MANUAL) and
0014 %   the autotuning method, split in the selection of the identification
0015 %   method, the selection of the tuning method and the selection of the
0016 %   regulator structure.
0017 %
0018 %   Everything started looking at PENDAN, an S-function for making pendulum
0019 %   animation
0020 %
0021 %   Author:    William Spinelli (wspinell@elet.polimi.it)
0022 %   Copyright  2004 W.Spinelli
0023 %   $Revision: 1.0 $  $Date: 2004/02/27 12:00:00 $
0024 
0025 % Plots every major integration step, but has no states of its own
0026 switch flag,
0027    
0028    % Initialization
0029    case 0,
0030       [sys,x0,str,ts] = mdlInitializeSizes(RefBlock);
0031       % Update
0032    case 2,
0033       sys = mdlUpdate(t,x,u);
0034       % Unused flags
0035    case { 1, 3, 4, 9 },
0036       sys = [];
0037       % DeleteBlock
0038    case 'DeleteBlock',
0039       LocalDeleteBlock
0040       % DeleteFigure
0041    case 'DeleteFigure',
0042       LocalDeleteFigure
0043       % SliderSP
0044    case 'SliderSP',
0045       LocalSliderSP
0046       % EditSP
0047    case 'EditSP',
0048       LocalEditSP
0049       % SliderCV
0050    case 'SliderCV',
0051       LocalSliderCV
0052       % EditCV
0053    case 'EditCV',
0054       LocalEditCV
0055       % Close
0056    case 'Close',
0057       LocalClose
0058       % Autotune
0059    case 'Autotune',
0060       LocalAutotune
0061       % Manual
0062    case 'Man',
0063       LocalMan
0064       % Auto
0065    case 'Auto',
0066       LocalAuto
0067       % EditK
0068    case 'EditK',
0069       LocalEditK
0070       % EditTi
0071    case 'EditTi',
0072       LocalEditTi
0073       % EditTd
0074    case 'EditTd',
0075       LocalEditTd
0076       % EditN
0077    case 'EditN',
0078       LocalEditN
0079       % Editb
0080    case 'Editb',
0081       LocalEditb
0082       % IdentMethod
0083    case 'Identification',
0084       LocalIdentification
0085       % TuningMethpd
0086    case 'Tuning',
0087       LocalTuning
0088       % Structure
0089    case 'Structure',
0090       LocalStructure
0091       % EditParam
0092    case 'EditParam',
0093       LocalEditParam
0094       % Unexpected flags
0095    otherwise
0096       error(['Unhandled flag = ',num2str(flag)]);
0097 end
0098 % end autogui
0099 
0100 %=============================================================================
0101 % mdlInitializeSizes
0102 % Return the sizes, initial conditions, and sample times for the S-function.
0103 %=============================================================================
0104 function [sys,x0,str,ts] = mdlInitializeSizes(RefBlock)
0105 % initialize parameters (setpoint)
0106 set_param(get_param([get_param(gcs,'Parent') '/' RefBlock],'Handle'),...
0107    'Value','0');
0108 
0109 % set up S-function
0110 sizes = simsizes;
0111 
0112 sizes.NumContStates  = 0;
0113 sizes.NumDiscStates  = 0;
0114 sizes.NumOutputs     = 0;
0115 sizes.NumInputs      = 2;
0116 sizes.DirFeedthrough = 1;
0117 sizes.NumSampleTimes = 1;
0118 
0119 sys = simsizes(sizes);
0120 
0121 x0  = [];
0122 str = [];
0123 ts  = [0.1 0];
0124 
0125 LocalPIDInit(RefBlock);
0126 % end mdlInitializeSizes
0127 
0128 
0129 %=============================================================================
0130 % mdlUpdate
0131 % Update the PID GUI animation.
0132 %=============================================================================
0133 function sys = mdlUpdate(t,x,u)
0134 fig = get_param(gcbh,'UserData');
0135 if ishandle(fig),
0136    if strcmp(get(fig,'Visible'),'on'),
0137       ud = get(fig,'UserData');
0138       LocalPIDSets(t,ud,u);
0139    end
0140 end
0141 sys = [];
0142 % end mdlUpdate
0143 
0144 
0145 %=============================================================================
0146 % LocalDeleteBlock
0147 % The animation block is being deleted, delete the associated figure.
0148 %=============================================================================
0149 function LocalDeleteBlock
0150 fig = get_param(gcbh,'UserData');
0151 if ishandle(fig),
0152    delete(fig);
0153    set_param(gcbh,'UserData',-1)
0154 end
0155 % end LocalDeleteBlock
0156 
0157 
0158 %=============================================================================
0159 % LocalDeleteFigure
0160 % The animation figure is being deleted, set the S-function UserData to -1.
0161 %=============================================================================
0162 function LocalDeleteFigure
0163 ud = get(gcbf,'UserData');
0164 set_param(ud.Block,'UserData',-1);
0165 % end LocalDeleteFigure
0166 
0167 
0168 %=============================================================================
0169 % LocalSliderSP
0170 % The callback function for the animation window slider SP control
0171 %=============================================================================
0172 function LocalSliderSP
0173 ud = get(gcbf,'UserData');
0174 set_param(ud.RefBlock,'Value',num2str(get(gcbo,'Value')));
0175 % end LocalSliderSP
0176 
0177 
0178 %=============================================================================
0179 % LocalSliderCV
0180 % The callback function for the animation window slider CV control
0181 %=============================================================================
0182 function LocalSliderCV
0183 global CVVALUE
0184 ud = get(gcbf,'UserData');
0185 CVVALUE = get(gcbo,'Value');
0186 set(ud.EditCV,'String',num2str(CVVALUE));
0187 % end LocalSliderCV
0188 
0189 
0190 %=============================================================================
0191 % LocalEditCV
0192 % The callback function for the edit field of parameter CV
0193 %=============================================================================
0194 function LocalEditCV
0195 global CVVALUE
0196 ud = get(gcbf,'UserData');
0197 CVVALUE = str2num(get(ud.EditCV,'String'));
0198 set(ud.SlideCV,'Value',CVVALUE);
0199 % end LocalEditCV
0200 
0201 
0202 %=============================================================================
0203 % LocalClose
0204 % The callback function for the animation window close button.  Delete
0205 % the animation figure window.
0206 %=============================================================================
0207 function LocalClose
0208 delete(gcbf)
0209 % end LocalClose
0210 
0211 
0212 %=============================================================================
0213 % LocalAutotune
0214 % The callback function for the autotune button. Start autotuning
0215 %=============================================================================
0216 function LocalAutotune
0217 global AUTOTUNE
0218 global INACTIVE
0219 AUTOTUNE = 1;
0220 INACTIVE = 1;
0221 ud = get(gcbf,'UserData');
0222 set(ud.SlideSP,'Enable','inactive');
0223 set(ud.EditSP,'Enable','off');
0224 set(ud.SlideCV,'Enable','inactive');
0225 set(ud.EditCV,'Enable','off');
0226 set(ud.Man,'Enable','off');
0227 set(ud.Auto,'Enable','off');
0228 set(ud.EditK,'Enable','inactive');
0229 set(ud.EditTi,'Enable','inactive');
0230 set(ud.EditTd,'Enable','inactive');
0231 set(ud.Editb,'Enable','inactive');
0232 set(ud.EditN,'Enable','inactive');
0233 set(ud.Ident,'Enable','off');
0234 set(ud.Tuning,'Enable','off');
0235 set(ud.TuningParam,'Enable','off');
0236 set(ud.Structure,'Enable','off');
0237 % end LocalAutotune
0238 
0239 
0240 %=============================================================================
0241 % LocalMan
0242 % The callback function for the manual selector button
0243 %=============================================================================
0244 function LocalMan
0245 global AUTOMAN
0246 ud = get(gcbf,'UserData');
0247 set(ud.Auto,'Value',0);
0248 set(ud.Man,'Value',1);
0249 set(ud.EditCV,'Enable','on');
0250 set(ud.SlideCV,'Enable','on');
0251 AUTOMAN = 0;
0252 % end LocalMan
0253 
0254 
0255 %=============================================================================
0256 % LocalAuto
0257 % The callback function for the automatic selector button
0258 %=============================================================================
0259 function LocalAuto
0260 global AUTOMAN
0261 ud = get(gcbf,'UserData');
0262 set(ud.Man,'Value',0);
0263 set(ud.Auto,'Value',1);
0264 set(ud.EditCV,'Enable','off');
0265 set(ud.SlideCV,'Enable','inactive');
0266 AUTOMAN = 1;
0267 % end LocalAuto
0268 
0269 
0270 %=============================================================================
0271 % LocalEditK
0272 % The callback function for the edit field of parameter K
0273 %=============================================================================
0274 function LocalEditK
0275 global PIDPARAMETERS
0276 ud = get(gcbf,'UserData');
0277 PIDPARAMETERS = [str2num(get(ud.EditK,'String')) PIDPARAMETERS(2:5)];
0278 % end LocalEditK
0279 
0280 
0281 %=============================================================================
0282 % LocalEditTi
0283 % The callback function for the edit field of parameter Ti
0284 %=============================================================================
0285 function LocalEditTi
0286 global PIDPARAMETERS
0287 ud = get(gcbf,'UserData');
0288 PIDPARAMETERS = [PIDPARAMETERS(1)...
0289       str2num(get(ud.EditTi,'String')) PIDPARAMETERS(3:5)];
0290 % end LocalEditTi
0291 
0292 
0293 %=============================================================================
0294 % LocalEditTd
0295 % The callback function for the edit field of parameter Td
0296 %=============================================================================
0297 function LocalEditTd
0298 global PIDPARAMETERS
0299 ud = get(gcbf,'UserData');
0300 PIDPARAMETERS = [PIDPARAMETERS(1:2)...
0301       str2num(get(ud.EditTd,'String')) PIDPARAMETERS(4:5)];
0302 % end LocalEditTd
0303 
0304 
0305 %=============================================================================
0306 % LocalEditN
0307 % The callback function for the edit field of parameter N
0308 %=============================================================================
0309 function LocalEditN
0310 global PIDPARAMETERS
0311 ud = get(gcbf,'UserData');
0312 PIDPARAMETERS = [PIDPARAMETERS(1:3)...
0313       str2num(get(ud.EditN,'String')) PIDPARAMETERS(5)];
0314 % end LocalEditN
0315 
0316 
0317 %=============================================================================
0318 % LocalEditb
0319 % The callback function for the edit field of parameter b
0320 %=============================================================================
0321 function LocalEditb
0322 global PIDPARAMETERS
0323 ud = get(gcbf,'UserData');
0324 PIDPARAMETERS = [PIDPARAMETERS(1:4) str2num(get(ud.Editb,'String'))];
0325 % end LocalEditb
0326 
0327 
0328 %=============================================================================
0329 % LocalEditSP
0330 % The callback function for the edit field of parameter SP
0331 %=============================================================================
0332 function LocalEditSP
0333 ud = get(gcbf,'UserData');
0334 set_param(ud.RefBlock,'Value',get(ud.EditSP,'String'));
0335 % end LocalEditSP
0336 
0337 
0338 %=============================================================================
0339 % LocalIdentification
0340 % The callback function for the selection of the identification method
0341 %=============================================================================
0342 function LocalIdentification
0343 global TUNING_PARAM
0344 global IDENTIFICATION_METHOD
0345 global TUNING_METHOD
0346 ud = get(gcbf,'UserData');
0347 str = get(ud.Ident,'String');
0348 IDENTIFICATION_METHOD = deblank(upper(str(get(ud.Ident,'Value'),:)));
0349 if strcmp(IDENTIFICATION_METHOD,'STEP')
0350    TUNING_PARAM = [];
0351    TUNING_METHOD = 'ZN (OL)';
0352    set(ud.TunParText,'String','');
0353    set(ud.TuningParam,'Style','edit');
0354    set(ud.TuningParam,'Visible','off');
0355    set(ud.Tuning,'Value',3);
0356 elseif strcmp(IDENTIFICATION_METHOD,'RELAY')
0357    TUNING_PARAM = [];
0358    TUNING_METHOD = 'ZN (CL)';
0359    set(ud.TunParText,'String','');
0360    set(ud.TuningParam,'Style','edit');
0361    set(ud.TuningParam,'Visible','off');
0362    set(ud.Tuning,'Value',4);
0363 end
0364 % end LocalIdentification
0365 
0366 
0367 %=============================================================================
0368 % LocalTuning
0369 % The callback function for the selection of the tuning method
0370 %=============================================================================
0371 function LocalTuning
0372 global TUNING_PARAM
0373 global TUNING_METHOD
0374 global IDENTIFICATION_METHOD
0375 ud = get(gcbf,'UserData');
0376 str = get(ud.Tuning,'String');
0377 TUNING_METHOD = deblank(upper(str(get(ud.Tuning,'Value'),:)));
0378 if strcmp(TUNING_METHOD,'ZN (OL)')
0379    set(ud.TunParText,'String','');
0380    set(ud.TuningParam,'Style','edit');
0381    set(ud.TuningParam,'Visible','off');
0382    set(ud.TuningParam,'String','');
0383    TUNING_PARAM = [];
0384    IDENTIFICATION_METHOD = 'STEP';
0385    set(ud.Ident,'Value',1);
0386 elseif strcmp(TUNING_METHOD,'ZN (CL)')
0387    set(ud.TunParText,'String','');
0388    set(ud.TuningParam,'Style','edit',...
0389       'Visible','off',...
0390       'String','');
0391    TUNING_PARAM = [];
0392    IDENTIFICATION_METHOD = 'RELAY';
0393    set(ud.Ident,'Value',2);
0394 elseif strcmp(TUNING_METHOD,'KT')
0395    set(ud.TunParText,'String','Ms ');
0396    set(ud.TuningParam,'Style','popupmenu',...
0397       'String',['1.4';'2.0'],...
0398       'Value',1,...
0399       'Visible','on');
0400    TUNING_PARAM = 1.4;
0401    IDENTIFICATION_METHOD = 'STEP';
0402    set(ud.Ident,'Value',1);
0403 elseif strcmp(TUNING_METHOD,'IMC')
0404    set(ud.TunParText,'String','lambda ');
0405    set(ud.TuningParam,'Style','edit',...
0406       'String','1',...
0407       'Visible','on');
0408    TUNING_PARAM = 1;
0409    IDENTIFICATION_METHOD = 'STEP';
0410    set(ud.Ident,'Value',1);
0411 end
0412 % end LocalTuning
0413 
0414 
0415 %=============================================================================
0416 % LocalEditParam
0417 % The callback function for the edit field of the method of the parameter
0418 %=============================================================================
0419 function LocalEditParam
0420 global TUNING_PARAM
0421 global TUNING_METHOD
0422 ud = get(gcbf,'UserData');
0423 if strcmp(TUNING_METHOD,'KT')
0424    if get(ud.TuningParam,'Value')==1;
0425       TUNING_PARAM = 1.4;
0426    elseif get(ud.TuningParam,'Value')==2;
0427       TUNING_PARAM = 2.0;
0428    end
0429 elseif strcmp(TUNING_METHOD,'IMC')
0430    TUNING_PARAM = str2num(get(ud.TuningParam,'String'));
0431 end
0432 % end LocalEditParam
0433 
0434 
0435 %=============================================================================
0436 % LocalStructure
0437 % The callback function for the selection of the regulator structure
0438 %=============================================================================
0439 function LocalStructure
0440 global TUNING_STRUCTURE
0441 ud = get(gcbf,'UserData');
0442 str = get(ud.Structure,'String');
0443 TUNING_STRUCTURE = deblank(upper(str(get(ud.Structure,'Value'),:)));
0444 % end LocalStructure
0445 
0446 
0447 %=============================================================================
0448 % LocalPIDSets
0449 % Local function to set the position of the graphics objects in the PID GUI
0450 % animation window.
0451 %=============================================================================
0452 function LocalPIDSets(time,ud,u)
0453 global AUTOMAN
0454 global AUTOTUNE
0455 global PIDPARAMETERS
0456 global INACTIVE
0457 
0458 PVValue = u(1);
0459 SPValue = str2num(get_param(ud.RefBlock,'Value'));
0460 CVValue = u(2);
0461 
0462 % time field
0463 set(ud.TimeField,...
0464    'String',num2str(time));
0465 % process value & setpoint
0466 set(ud.PV,...
0467    'YData',[0 PVValue PVValue 0]);
0468 set(ud.PVField,...
0469    'String',num2str(PVValue,'%1.4f'));
0470 set(ud.RefMark,...
0471    'YData',[SPValue+0.25 SPValue SPValue-0.25]);
0472 set(ud.SlideSP,...
0473    'Value',SPValue);
0474 set(ud.EditSP,...
0475    'String',num2str(SPValue,'%1.4f'));
0476 % process value & setpoint
0477 set(ud.CV,...
0478    'YData',[0 CVValue CVValue 0]);
0479 if ~AUTOTUNE
0480    set(ud.SlideCV,...
0481       'Value',CVValue);
0482    set(ud.EditCV,...
0483       'String',num2str(CVValue,'%1.4f')); 
0484 end
0485 if ~AUTOTUNE & INACTIVE
0486    % Autotuning process completed (update parameters and set the GUI
0487    % active)
0488    % PID parameters
0489    set(ud.SlideSP,'Enable','on');
0490    set(ud.EditSP,'Enable','on');
0491    if ~AUTOMAN
0492       set(ud.SlideCV,'Enable','on');
0493       set(ud.EditCV,'Enable','on');
0494    end
0495    set(ud.Man,'Enable','on');
0496    set(ud.Auto,'Enable','on');
0497    set(ud.EditK,'Enable','on');
0498    set(ud.EditTi,'Enable','on');
0499    set(ud.EditTd,'Enable','on');
0500    set(ud.Editb,'Enable','on');
0501    set(ud.EditN,'Enable','on');
0502    set(ud.Ident,'Enable','on');
0503    set(ud.Tuning,'Enable','on');
0504    set(ud.TuningParam,'Enable','on');
0505    set(ud.Structure,'Enable','on');
0506    set(ud.EditK,...
0507       'String',num2str(PIDPARAMETERS(1)));
0508    set(ud.EditTi,...
0509       'String',num2str(PIDPARAMETERS(2)));
0510    set(ud.EditTd,...
0511       'String',num2str(PIDPARAMETERS(3)));
0512    set(ud.EditN,...
0513       'String',num2str(PIDPARAMETERS(4)));
0514    set(ud.Editb,...
0515       'String',num2str(PIDPARAMETERS(5)));
0516    INACTIVE = 0;
0517 end
0518 
0519 % Force plot to be drawn
0520 pause(0), drawnow
0521 % end LocalPIDSets
0522 
0523 
0524 %=============================================================================
0525 % LocalPIDInit
0526 % Local function to initialize the PID GUI animation.  If the animation
0527 % window already exists, it is brought to the front.  Otherwise, a new
0528 % figure window is created.
0529 %=============================================================================
0530 function LocalPIDInit(RefBlock)
0531 % The name of the reference is derived from the name of the
0532 % subsystem block that owns the PID animation S-function block.
0533 % This subsystem is the current system and is assumed to be the same
0534 % layer at which the reference block resides.
0535 sys = get_param(gcs,'Parent');
0536 
0537 global AUTOTUNE
0538 global AUTOMAN
0539 global PIDPARAMETERS
0540 global IDENTIFICATION_METHOD
0541 global TUNING_METHOD
0542 global TUNING_PARAM
0543 global TUNING_STRUCTURE
0544 global INACTIVE
0545 
0546 INACTIVE = 1;
0547 
0548 IDENTIFICATION_METHOD = 'STEP';
0549 TUNING_METHOD = 'KT';
0550 TUNING_PARAM = 1.4;
0551 TUNING_STRUCTURE  ='PID';
0552 
0553 AUTOTUNE = 0;
0554 AUTOMAN  = 1;
0555 
0556 TimeClock = 0;
0557 PVValue = 0;
0558 SPValue = str2num(get_param([sys '/' RefBlock],'Value'));
0559 CVValue = 0;
0560 
0561 % The animation figure handle is stored in the PID block's UserData.
0562 % If it exists, initialize all the fields
0563 Fig = get_param(gcbh,'UserData');
0564 if ishandle(Fig),
0565    FigUD = get(Fig,'UserData');
0566    
0567    % time field
0568    set(FigUD.TimeField,...
0569       'String',num2str(TimeClock));
0570    % process value & set point
0571    set(FigUD.PV,...
0572       'YData',[0 PVValue PVValue 0]);
0573    set(FigUD.PVField,...
0574       'String',num2str(PVValue));
0575    set(FigUD.RefMark,...
0576       'YData',[SPValue+0.25 SPValue SPValue-0.25]);
0577    set(FigUD.SlideSP,...
0578       'Value',0);
0579    set(FigUD.EditSP,...
0580       'String',num2str(PVValue));
0581    % control variable
0582    set(FigUD.CV,...
0583       'YData',[0 CVValue CVValue 0]);
0584    set(FigUD.EditCV,...
0585       'String',num2str(CVValue),...
0586       'Enable','off');
0587    set(FigUD.SlideCV,...
0588       'Value',CVValue,...
0589       'Enable','inactive');
0590    % auto/man selector
0591    set(FigUD.Man,...
0592       'Value',0);
0593    set(FigUD.Auto,...
0594       'Value',1);
0595    % PID parameters
0596    set(FigUD.EditK,...
0597       'String',num2str(PIDPARAMETERS(1)),...
0598       'Enable','on');
0599    set(FigUD.EditTi,...
0600       'String',num2str(PIDPARAMETERS(2)),...
0601       'Enable','on');
0602    set(FigUD.EditTd,...
0603       'String',num2str(PIDPARAMETERS(3)),...
0604       'Enable','on');
0605    set(FigUD.EditN,...
0606       'String',num2str(PIDPARAMETERS(4)),...
0607       'Enable','on');
0608    set(FigUD.Editb,...
0609       'String',num2str(PIDPARAMETERS(5)),...
0610       'Enable','on');
0611    % autotuning
0612    set(FigUD.Ident,...
0613       'Value',1,...
0614       'Enable','on');
0615    set(FigUD.Tuning,...
0616       'Value',2,...
0617       'Enable','on');
0618    set(FigUD.Structure,...
0619       'Value',1,...
0620       'Enable','on');
0621    set(FigUD.TunParText,...
0622       'String','Ms ');
0623    set(FigUD.TuningParam,...
0624       'Style','popupmenu',...
0625       'String',['1.4';'2.0'],...
0626       'Value',1,...
0627       'Enable','on',...
0628       'Visible','on');
0629    
0630    % bring it to the front
0631    figure(Fig);
0632    return
0633 end
0634 
0635 % the animation figure doesn't exist, create a new one and store its
0636 % handle in the animation block's UserData
0637 FigureName = 'PID Control Panel';
0638 
0639 % Figure
0640 FigH = 610;                % figure height
0641 FigW = 272;                % figure width
0642 Fig = figure(...
0643    'Units',              'pixel',...
0644    'Position',           [740 740-FigH FigW FigH],...
0645    'Name',               FigureName,...
0646    'NumberTitle',        'off',...
0647    'IntegerHandle',      'off',...
0648    'HandleVisibility',   'callback',...
0649    'Resize',             'off',...
0650    'MenuBar',            'none',...
0651    'DoubleBuffer',       'on',...
0652    'DeleteFcn',          'autogui([],[],[],''DeleteFigure'')',...
0653    'CloseRequestFcn',    'autogui([],[],[],''Close'');');
0654 
0655 % Setpoint slider
0656 SlideControlSP = uicontrol(...
0657    'Parent',             Fig,...
0658    'Style',              'slider',...
0659    'Units',              'pixel', ...
0660    'Position',           [25 FigH-325 22 300],...
0661    'Min',                -9,...
0662    'Max',                9,...
0663    'Value',              0,...
0664    'BackgroundColor',    [1 1 0],...
0665    'Callback',           'autogui([],[],[],''SliderSP'');');
0666 uicontrol(...
0667    'Parent',             Fig,...
0668    'Style',              'text',...
0669    'Units',              'pixel',...
0670    'Position',           [25 FigH-20 22 12], ...
0671    'HorizontalAlignment','center',...
0672    'String',             'SP',...
0673    'Backgroundcolor',    [0.8 0.8 0.8],...
0674    'Foregroundcolor',    [1 1 0],...
0675    'Fontweight',         'bold');
0676 
0677 % Process value
0678 AxesPV = axes(...
0679    'Parent',             Fig,...
0680    'Units',              'pixel',...
0681    'Position',           [75 FigH-325 22 300],...
0682    'CLim',               [1 64], ...
0683    'Xlim',               [-1 1],...
0684    'Ylim',               [-10 10],...
0685    'Visible',            'on',...
0686    'XTick',              [],...
0687    'XTickLabel',         [],...
0688    'FontSize',           8,...
0689    'Box',                'on');
0690 uicontrol(...
0691    'Parent',             Fig,...
0692    'Style',              'text',...
0693    'Units',              'pixel',...
0694    'Position',           [75 FigH-20 22 12], ...
0695    'HorizontalAlignment','center',...
0696    'String',             'PV',...
0697    'Backgroundcolor',    [0.8 0.8 0.8],...
0698    'Foregroundcolor',    [1 0 1],...
0699    'Fontweight',         'bold');
0700 PV = patch(...
0701    'Parent',             AxesPV,...
0702    'XData',              [-1 -1 1 1],...
0703    'YData',              [0 PVValue PVValue 0],...
0704    'FaceColor',          [1 0 1]);
0705 uicontrol(...
0706    'Parent',             Fig,...
0707    'Style',              'text',...
0708    'Units',              'pixel',...
0709    'Position',           [106 FigH-175 50 14], ...
0710    'Backgroundcolor',    [0.8 0.8 0.8],...
0711    'Foregroundcolor',    [1 0 1],...
0712    'HorizontalAlignment','center',...
0713    'Fontweight',         'bold',...
0714    'String',             'PV');
0715 PVField = uicontrol(...
0716    'Parent',             Fig,...
0717    'Style',              'text',...
0718    'Units',              'pixel',...
0719    'Position',           [106 FigH-191 50 14], ...
0720    'Backgroundcolor',    [1 1 1],...
0721    'Foregroundcolor',    [0 0 0],...
0722    'HorizontalAlignment','center',...
0723    'String',             num2str(PVValue));
0724 RefMark = patch(...
0725    'Parent',             AxesPV,...
0726    'XData',              [-1 -0 -1],...
0727    'YData',              [SPValue+0.25 SPValue SPValue-0.25],...
0728    'FaceColor',          [1 1 0]);
0729 uicontrol(...
0730    'Parent',             Fig,...
0731    'Style',              'text',...
0732    'Units',              'pixel',...
0733    'Position',           [106 FigH-100 50 14], ...
0734    'Backgroundcolor',    [0.8 0.8 0.8],...
0735    'Foregroundcolor',    [1 1 0],...
0736    'HorizontalAlignment','center',...
0737    'Fontweight',         'bold',...
0738    'String',             'SP');
0739 EditSP = uicontrol(...
0740    'Parent',             Fig,...
0741    'Style',              'edit',...
0742    'Units',              'pixel',...
0743    'Position',           [106 FigH-118 50 18], ...
0744    'HorizontalAlignment','center',...
0745    'String',             num2str(SPValue),...
0746    'Foregroundcolor',    [0 0 0],...
0747    'Backgroundcolor',    [1 1 1],...
0748    'Callback',           'autogui([],[],[],''EditSP'');');
0749 
0750 % Control variable
0751 AxesCV = axes(...
0752    'Parent',             Fig,...
0753    'Units',              'pixel',...
0754    'Position',           [175 FigH-325 22 300],...
0755    'CLim',               [1 64], ...
0756    'Xlim',               [-1 1],...
0757    'Ylim',               [-10 10],...
0758    'Visible',            'on',...
0759    'XTick',              [],...
0760    'XTickLabel',         [],...
0761    'FontSize',           8,...
0762    'Box',                'on');
0763 uicontrol(...
0764    'Parent',             Fig,...
0765    'Style',              'text',...
0766    'Units',              'pixel',...
0767    'Position',           [175 FigH-20 22 12], ...
0768    'HorizontalAlignment','center',...
0769    'String',             'CV',...
0770    'Backgroundcolor',    [0.8 0.8 0.8],...
0771    'Foregroundcolor',    [0 1 1],...
0772    'Fontweight',         'bold');
0773 CV = patch(...
0774    'Parent',             AxesCV,...
0775    'XData',              [-1 -1 1 1],...
0776    'YData',              [0 CVValue CVValue 0],...
0777    'FaceColor',          [0 1 1]);
0778 
0779 % Control variable - Manual
0780 SlideControlCV = uicontrol(...
0781    'Parent',             Fig,...
0782    'Style',              'slider',...
0783    'Units',              'pixel', ...
0784    'Position',           [225 FigH-325 22 300],...
0785    'Min',                -9,...
0786    'Max',                9,...
0787    'Value',              0,...
0788    'BackgroundColor',    [0 1 1],...
0789    'Callback',           'autogui([],[],[],''SliderCV'');',...
0790    'Enable',             'inactive');
0791 uicontrol(...
0792    'Parent',             Fig,...
0793    'Style',              'text',...
0794    'Units',              'pixel',...
0795    'Position',           [200 FigH-20 72 12], ...
0796    'HorizontalAlignment','center',...
0797    'String',             'CV - MAN',...
0798    'Backgroundcolor',    [0.8 0.8 0.8],...
0799    'Foregroundcolor',    [0 1 1],...
0800    'Fontweight',         'bold');
0801 uicontrol(...
0802    'Parent',             Fig,...
0803    'Style',              'text',...
0804    'Units',              'pixel',...
0805    'Position',           [106 FigH-250 50 14], ...
0806    'Backgroundcolor',    [0.8 0.8 0.8],...
0807    'Foregroundcolor',    [0 1 1],...
0808    'HorizontalAlignment','center',...
0809    'Fontweight',         'bold',...
0810    'String',             'CV');
0811 EditCV = uicontrol(...
0812    'Parent',             Fig,...
0813    'Style',              'edit',...
0814    'Units',              'pixel',...
0815    'Position',           [106 FigH-268 50 18], ...
0816    'HorizontalAlignment','center',...
0817    'String',             num2str(CVValue),...
0818    'Foregroundcolor',    [0 0 0],...
0819    'Backgroundcolor',    [1 1 1],...
0820    'Callback',           'autogui([],[],[],''EditCV'');',...
0821    'Enable',             'inactive');
0822 
0823 % time field
0824 uicontrol(...
0825    'Parent',             Fig,...
0826    'Style',              'text',...
0827    'Units',              'pixel',...
0828    'Position',           [100 FigH-348 36 12], ...
0829    'HorizontalAlignment','right',...
0830    'Backgroundcolor',    [0.8 0.8 0.8],...
0831    'Fontweight',         'bold',...
0832    'String',             'Time: ');
0833 TimeField = uicontrol(...
0834    'Parent',             Fig,...
0835    'Style',              'text',...
0836    'Units',              'pixel', ...
0837    'Position',           [136 FigH-348 36 12],...
0838    'HorizontalAlignment','left',...
0839    'Backgroundcolor',    [0.8 0.8 0.8],...
0840    'String',             num2str(TimeClock));
0841 
0842 % PID parameters
0843 uicontrol(...
0844    'Parent',             Fig,...
0845    'Style',              'text',...
0846    'Units',              'pixel',...
0847    'Position',           [12 FigH-371 140 14], ...
0848    'HorizontalAlignment','left',...
0849    'Fontweight',         'bold',...
0850    'Backgroundcolor',    [0.8 0.8 0.8],...
0851    'String',             'Parameters');
0852 uicontrol(...
0853    'Parent',             Fig,...
0854    'Style',              'frame',...
0855    'Units',              'pixel',...
0856    'Position',           [12 FigH-417 248 46]);
0857 uicontrol(...
0858    'Parent',             Fig,...
0859    'Style',              'text',...
0860    'Units',              'pixel',...
0861    'Position',           [16 FigH-393 20 14], ...
0862    'HorizontalAlignment','right',...
0863    'Fontweight',         'bold',...
0864    'String',             'K ');
0865 EditK = uicontrol(...
0866    'Parent',             Fig,...
0867    'Style',              'edit',...
0868    'Units',              'pixel',...
0869    'Position',           [36 FigH-393 60 18], ...
0870    'HorizontalAlignment','center',...
0871    'String',             '',...
0872    'Backgroundcolor',    [1 1 1],...
0873    'Callback',           'autogui([],[],[],''EditK'');');
0874 uicontrol(...
0875    'Parent',             Fig,...
0876    'Style',              'text',...
0877    'Units',              'pixel',...
0878    'Position',           [96 FigH-393 20 14], ...
0879    'HorizontalAlignment','right',...
0880    'Fontweight',         'bold',...
0881    'String',             'Ti ');
0882 EditTi = uicontrol(...
0883    'Parent',             Fig,...
0884    'Style',              'edit',...
0885    'Units',              'pixel',...
0886    'Position',           [116 FigH-393 60 18], ...
0887    'HorizontalAlignment','center',...
0888    'String',             '',...
0889    'Backgroundcolor',    [1 1 1],...
0890    'Callback',           'autogui([],[],[],''EditTi'');');
0891 uicontrol(...
0892    'Parent',             Fig,...
0893    'Style',              'text',...
0894    'Units',              'pixel',...
0895    'Position',           [176 FigH-393 20 14], ...
0896    'HorizontalAlignment','right',...
0897    'Fontweight',         'bold',...
0898    'String',             'Td ');
0899 EditTd = uicontrol(...
0900    'Parent',             Fig,...
0901    'Style',              'edit',...
0902    'Units',              'pixel',...
0903    'Position',           [196 FigH-393 60 18], ...
0904    'HorizontalAlignment','center',...
0905    'String',             '',...
0906    'Backgroundcolor',    [1 1 1],...
0907    'Callback',           'autogui([],[],[],''EditTd'');');
0908 uicontrol(...
0909    'Parent',             Fig,...
0910    'Style',              'text',...
0911    'Units',              'pixel',...
0912    'Position',           [16 FigH-413 20 14], ...
0913    'HorizontalAlignment','right',...
0914    'Fontweight',         'bold',...
0915    'String',             'N ');
0916 EditN = uicontrol(...
0917    'Parent',             Fig,...
0918    'Style',              'edit',...
0919    'Units',              'pixel',...
0920    'Position',           [36 FigH-413 60 18], ...
0921    'HorizontalAlignment','center',...
0922    'String',             '',...
0923    'Backgroundcolor',    [1 1 1],...
0924    'Callback',           'autogui([],[],[],''EditN'');');
0925 uicontrol(...
0926    'Parent',             Fig,...
0927    'Style',              'text',...
0928    'Units',              'pixel',...
0929    'Position',           [96 FigH-413 20 14], ...
0930    'HorizontalAlignment','right',...
0931    'Fontweight',         'bold',...
0932    'String',             'b ');
0933 Editb = uicontrol(...
0934    'Parent',             Fig,...
0935    'Style',              'edit',...
0936    'Units',              'pixel',...
0937    'Position',           [116 FigH-413 60 18], ...
0938    'HorizontalAlignment','center',...
0939    'String',             '',...
0940    'Backgroundcolor',    [1 1 1],...
0941    'Callback',           'autogui([],[],[],''Editb'');');
0942 uicontrol(...
0943    'Parent',             Fig,...
0944    'Style',              'text',...
0945    'Units',              'pixel',...
0946    'Position',           [176 FigH-413 20 14], ...
0947    'HorizontalAlignment','right',...
0948    'Fontweight',         'bold',...
0949    'String',             'c ');
0950 Editc = uicontrol(...
0951    'Parent',             Fig,...
0952    'Style',              'edit',...
0953    'Units',              'pixel',...
0954    'Position',           [196 FigH-413 60 18], ...
0955    'HorizontalAlignment','center',...
0956    'String',             '0',...
0957    'Backgroundcolor',    [1 1 1],...
0958    'Callback',           'autogui([],[],[],''Editc'');',...
0959    'Enable',             'off');
0960 
0961 % auto/man selector
0962 uicontrol(...
0963    'Parent',             Fig,...
0964    'Style',              'text',...
0965    'Units',              'pixel',...
0966    'Position',           [12 FigH-441 140 14], ...
0967    'HorizontalAlignment','left',...
0968    'Fontweight',         'bold',...
0969    'Backgroundcolor',    [0.8 0.8 0.8],...
0970    'String',             'Operating Mode');
0971 uicontrol(...
0972    'Parent',             Fig,...
0973    'Style',              'frame',...
0974    'Units',              'pixel',...
0975    'Position',           [12 FigH-467 248 24]);
0976 Man = uicontrol(...
0977    'Parent',             Fig,...
0978    'Style',              'radiobutton',...
0979    'Position',           [16 FigH-465 70 20],...
0980    'String',             'Manual', ...
0981    'Fontweight',         'bold',...
0982    'Value',              0,...
0983    'Callback',           'autogui([],[],[],''Man'');');
0984 Auto = uicontrol(...
0985    'Parent',             Fig,...
0986    'Style',              'radiobutton',...
0987    'Position',           [136 FigH-465 50 20],...
0988    'String',             'Auto', ...
0989    'Fontweight',         'bold',...
0990    'Value',              1,...
0991    'Callback',           'autogui([],[],[],''Auto'');');
0992 
0993 % autotuning
0994 uicontrol(...
0995    'Parent',             Fig,...
0996    'Style',              'text',...
0997    'Units',              'pixel',...
0998    'Position',           [12 FigH-491 140 14], ...
0999    'HorizontalAlignment','left',...
1000    'Fontweight',         'bold',...
1001    'Backgroundcolor',    [0.8 0.8 0.8],...
1002    'String',             'Autotuner');
1003 uicontrol(...
1004    'Parent',             Fig,...
1005    'Style',              'frame',...
1006    'Units',              'pixel',...
1007    'Position',           [12 FigH-604 248 112]);
1008 uicontrol(...
1009    'Parent',             Fig,...
1010    'Style',              'text',...
1011    'Units',              'pixel',...
1012    'Position',           [16 FigH-516 140 14], ...
1013    'HorizontalAlignment','left',...
1014    'Fontweight',         'bold',...
1015    'String',             'Identification method');
1016 IdentMethod = uicontrol(...
1017    'Parent',             Fig,...
1018    'Style',              'popupmenu',...
1019    'Position',           [156 FigH-516 100 18],...
1020    'String',             ['step ';'relay'],...
1021    'Backgroundcolor',    [1 1 1],...
1022    'Fontweight',         'bold',...
1023    'Value',              1,...
1024    'Callback',           'autogui([],[],[],''Identification'');');
1025 uicontrol(...
1026    'Parent',             Fig,...
1027    'Style',              'text',...
1028    'Units',              'pixel',...
1029    'Position',           [16 FigH-536 140 14], ...
1030    'HorizontalAlignment','left',...
1031    'Fontweight',         'bold',...
1032    'String',             'Tuning method');
1033 TuningMethod = uicontrol(...
1034    'Parent',             Fig,...
1035    'Style',              'popupmenu',...
1036    'Position',           [156 FigH-536 100 18],...
1037    'String',             ['IMC    ';'KT     ';'ZN (OL)';'ZN (CL)'], ...
1038    'Backgroundcolor',    [1 1 1],...
1039    'Fontweight',         'bold',...
1040    'Value',              2,...
1041    'Callback',           'autogui([],[],[],''Tuning'');');
1042 TuningParText = uicontrol(...
1043    'Parent',             Fig,...
1044    'Style',              'text',...
1045    'Units',              'pixel',...
1046    'Position',           [16 FigH-556 180 14], ...
1047    'HorizontalAlignment','right',...
1048    'Fontweight',         'bold',...
1049    'String',             'Ms ');
1050 TuningParam = uicontrol(...
1051    'Parent',             Fig,...
1052    'Style',              'popupmenu',...
1053    'Units',              'pixel',...
1054    'Position',           [196 FigH-556 60 18], ...
1055    'HorizontalAlignment','center',...
1056    'String',             ['1.4';'2.0'],...
1057    'Value',              1,...
1058    'Backgroundcolor',    [1 1 1],...
1059    'Callback',           'autogui([],[],[],''EditParam'');');
1060 uicontrol(...
1061    'Parent',             Fig,...
1062    'Style',              'text',...
1063    'Units',              'pixel',...
1064    'Position',           [16 FigH-576 140 14], ...
1065    'HorizontalAlignment','left',...
1066    'Fontweight',         'bold',...
1067    'String',             'Structure');
1068 RegStruct = uicontrol(...
1069    'Parent',             Fig,...
1070    'Style',              'popupmenu',...
1071    'Position',           [156 FigH-576 100 18],...
1072    'String',             ['PID ';'PI  ';'auto'], ...
1073    'Backgroundcolor',    [1 1 1],...
1074    'Fontweight',         'bold',...
1075    'Value',              1,...
1076    'Callback',           'autogui([],[],[],''Structure'');'); 
1077 uicontrol(...
1078    'Parent',             Fig,...
1079    'Style',              'pushbutton',...
1080    'Position',           [100 FigH-601 72 20],...
1081    'String',             'Autotune', ...
1082    'Fontweight',         'bold',...
1083    'Callback',           'autogui([],[],[],''Autotune'');');
1084 
1085 
1086 % all the HG objects are created, store them into the Figure's UserData
1087 % time field
1088 FigUD.TimeField    = TimeField;
1089 % process value & setpoint
1090 FigUD.PV           = PV;
1091 FigUD.SlideSP      = SlideControlSP;
1092 FigUD.RefMark      = RefMark;
1093 FigUD.EditSP       = EditSP;
1094 FigUD.PVField      = PVField;
1095 % control variable
1096 FigUD.CV           = CV;
1097 FigUD.SlideCV      = SlideControlCV;
1098 FigUD.EditCV       = EditCV;
1099 % radiobox button
1100 FigUD.Man          = Man;
1101 FigUD.Auto         = Auto;
1102 % edit field (PID parameters)
1103 FigUD.EditK        = EditK;
1104 FigUD.EditTi       = EditTi;
1105 FigUD.EditTd       = EditTd;
1106 FigUD.EditN        = EditN;
1107 FigUD.Editb        = Editb;
1108 % autotuning
1109 FigUD.Ident        = IdentMethod;
1110 FigUD.Tuning       = TuningMethod;
1111 FigUD.TunParText   = TuningParText;
1112 FigUD.TuningParam  = TuningParam;
1113 FigUD.Structure    = RegStruct;
1114 % Simulink Block Interaction
1115 FigUD.Block        = get_param(gcbh,'Handle');
1116 FigUD.RefBlock     = get_param([sys '/' RefBlock],'Handle');
1117 
1118 set(Fig,'UserData',FigUD);
1119 
1120 drawnow
1121 
1122 % store the figure handle in the animation block's UserData
1123 set_param(gcbh,'UserData',Fig);
1124 % end LocalPIDInit

Previous page  Function Reference bodePIDcompare Next page

Generated on Wed 17-Mar-2004 09:29:44 by m2html © 2003