0001 function [sys,x0,str,ts] = envgui(t,x,u,flag,NoiseBlock,LoadDistBlock)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 switch flag,
0027
0028
0029 case 0,
0030 [sys,x0,str,ts] = mdlInitializeSizes(NoiseBlock,LoadDistBlock);
0031
0032 case 2,
0033 sys = mdlUpdate(t,x,u);
0034
0035 case { 1, 3, 4, 9 },
0036 sys = [];
0037
0038 case 'DeleteBlock',
0039 LocalDeleteBlock
0040
0041 case 'DeleteFigure',
0042 LocalDeleteFigure
0043
0044 case 'Close',
0045 LocalClose
0046
0047 case 'Noise',
0048 LocalNoise
0049
0050 case 'NoiseParam',
0051 LocalNoiseParam
0052
0053 case 'Dist',
0054 LocalDist
0055
0056 case 'DistParam',
0057 LocalDistParam
0058
0059 case 'StepPID',
0060 LocalStepPID
0061
0062 case 'BodePID',
0063 LocalBodePID
0064
0065 case 'Hlp',
0066 LocalHlp
0067
0068 otherwise
0069 error(['Unhandled flag = ',num2str(flag)]);
0070 end
0071
0072
0073
0074
0075
0076
0077 function [sys,x0,str,ts] = mdlInitializeSizes(NoiseBlock,LoadDistBlock)
0078
0079 set_param(get_param([get_param(gcs,'Parent') '/' NoiseBlock],'Handle'),...
0080 'Variance','0');
0081 set_param(get_param([get_param(gcs,'Parent') '/' LoadDistBlock],'Handle'),...
0082 'Value','0');
0083
0084
0085 sizes = simsizes;
0086
0087 sizes.NumContStates = 0;
0088 sizes.NumDiscStates = 0;
0089 sizes.NumOutputs = 0;
0090 sizes.NumInputs = 0;
0091 sizes.DirFeedthrough = 0;
0092 sizes.NumSampleTimes = 1;
0093
0094 sys = simsizes(sizes);
0095
0096 x0 = [];
0097 str = [];
0098 ts = [0.1 0];
0099
0100 LocalEnvInit(NoiseBlock,LoadDistBlock);
0101
0102
0103
0104
0105
0106
0107
0108 function sys = mdlUpdate(t,x,u)
0109 fig = get_param(gcbh,'UserData');
0110 if ishandle(fig),
0111 if strcmp(get(fig,'Visible'),'on'),
0112 ud = get(fig,'UserData');
0113 LocalEnvSets(t,ud,u);
0114 end
0115 end
0116 sys = [];
0117
0118
0119
0120
0121
0122
0123
0124 function LocalDeleteBlock
0125 fig = get_param(gcbh,'UserData');
0126 if ishandle(fig),
0127 delete(fig);
0128 set_param(gcbh,'UserData',-1)
0129 end
0130
0131
0132
0133
0134
0135
0136
0137
0138 function LocalClose
0139 delete(gcbf)
0140
0141
0142
0143
0144
0145
0146
0147 function LocalDeleteFigure
0148 ud = get(gcbf,'UserData');
0149 set_param(ud.Block,'UserData',-1);
0150
0151
0152
0153
0154
0155
0156
0157
0158 function LocalNoise
0159 ud = get(gcbf,'UserData');
0160 if get(ud.Noise,'Value')
0161 set_param(ud.NoiseBlock,'Variance',get(ud.NoiseVar,'String'));
0162 else
0163 set_param(ud.NoiseBlock,'Variance',num2str(0));
0164 end
0165
0166
0167
0168
0169
0170
0171
0172 function LocalNoiseParam
0173 ud = get(gcbf,'UserData');
0174 if get(ud.Noise,'Value')
0175 set_param(ud.NoiseBlock,'Variance',get(ud.NoiseVar,'String'));
0176 end
0177
0178
0179
0180
0181
0182
0183
0184 function LocalDist
0185 ud = get(gcbf,'UserData');
0186 if get(ud.LoadDist,'Value')
0187 set_param(ud.LoadDistBlock,'Value',get(ud.LoadAmp,'String'));
0188 else
0189 set_param(ud.LoadDistBlock,'Value',num2str(0));
0190 end
0191
0192
0193
0194
0195
0196
0197
0198 function LocalDistParam
0199 ud = get(gcbf,'UserData');
0200 if get(ud.LoadDist,'Value')
0201 set_param(ud.LoadDistBlock,'Value',get(ud.LoadAmp,'String'));
0202 end
0203
0204
0205
0206
0207
0208
0209
0210
0211 function LocalStepPID
0212 global MODELRUNNING
0213 if ~MODELRUNNING
0214 try
0215 num = str2num(get_param('AutotunerPID/Plant/Transfer Fcn',...
0216 'Numerator'));
0217 den = str2num(get_param('AutotunerPID/Plant/Transfer Fcn',...
0218 'Denominator'));
0219 tau = str2num(get_param('AutotunerPID/Plant/Transport Delay',...
0220 'Delay'));
0221 catch
0222 msgbox('The step response can be computed only for linear models',...
0223 'AutotunerPID','error');
0224 return
0225 end
0226 stepPIDcompare(num,den,tau);
0227 else
0228 msgbox('The simulation must be STOPPED to perform the Comparative Analysis',...
0229 'AutotunerPID','warn');
0230 end
0231
0232
0233
0234
0235
0236
0237
0238
0239 function LocalBodePID
0240 global MODELRUNNING
0241 if ~MODELRUNNING
0242 try
0243 num = str2num(get_param('AutotunerPID/Plant/Transfer Fcn','Numerator'));
0244 den = str2num(get_param('AutotunerPID/Plant/Transfer Fcn','Denominator'));
0245 tau = str2num(get_param('AutotunerPID/Plant/Transport Delay','Delay'));
0246 catch
0247 msgbox('The Bode diagrams can be computed only for linear models',...
0248 'AutotunerPID','error');
0249 return
0250 end
0251 bodePIDcompare(num,den,tau);
0252 else
0253 msgbox('The simulation must be STOPPED to perform the Comparative Analysis',...
0254 'AutotunerPID','warn');
0255 end
0256
0257
0258
0259
0260
0261
0262
0263
0264 function LocalHlp
0265 web([strrep(which('envgui'),'envgui.m','') 'help/index.html'],'-browser')
0266
0267
0268
0269
0270
0271
0272
0273
0274 function LocalEnvSets(time,ud,u)
0275 global AUTOTUNE
0276 global ENVINACTIVE
0277
0278 if AUTOTUNE
0279 set(ud.Noise,'Enable','off');
0280 set(ud.NoiseVar,'Enable','off');
0281 set(ud.LoadDist,'Enable','off');
0282 set(ud.LoadAmp,'Enable','off');
0283 ENVINACTIVE = 1;
0284 elseif ~AUTOTUNE & ENVINACTIVE
0285
0286
0287 set(ud.Noise,'Enable','on');
0288 set(ud.NoiseVar,'Enable','on');
0289 set(ud.LoadDist,'Enable','on');
0290 set(ud.LoadAmp,'Enable','on');
0291 ENVINACTIVE = 0;
0292 end
0293
0294
0295 pause(0), drawnow
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305 function LocalEnvInit(NoiseBlock,LoadDistBlock)
0306
0307
0308
0309
0310 sys = get_param(gcs,'Parent');
0311
0312 global AUTOTUNE
0313 global AUTOMAN
0314 global INACTIVE
0315
0316
0317
0318
0319 Fig = get_param(gcbh,'UserData');
0320 if ishandle(Fig),
0321 FigUD = get(Fig,'UserData');
0322
0323 set(FigUD.Noise,...
0324 'Value',0,...
0325 'Enable','on');
0326 set(FigUD.NoiseVar,...
0327 'String','0.0001',...
0328 'Enable','on');
0329 set(FigUD.LoadDist,...
0330 'Value',0,...
0331 'Enable','on');
0332 set(FigUD.LoadAmp,...
0333 'String','1',...
0334 'Enable','on');
0335
0336
0337 figure(Fig);
0338 return
0339 end
0340
0341
0342
0343 FigureName = 'Environment Panel';
0344
0345
0346 FigH = 150;
0347 FigW = 272;
0348 Fig = figure(...
0349 'Units', 'pixel',...
0350 'Position', [100 300-FigH FigW FigH],...
0351 'Name', FigureName,...
0352 'NumberTitle', 'off',...
0353 'IntegerHandle', 'off',...
0354 'HandleVisibility', 'callback',...
0355 'Resize', 'off',...
0356 'MenuBar', 'none',...
0357 'DoubleBuffer', 'on',...
0358 'DeleteFcn', 'envgui([],[],[],''DeleteFigure'')',...
0359 'CloseRequestFcn', 'envgui([],[],[],''Close'');');
0360
0361
0362 uicontrol(...
0363 'Parent', Fig,...
0364 'Style', 'text',...
0365 'Units', 'pixel',...
0366 'Position', [12 FigH-19 140 14], ...
0367 'HorizontalAlignment','left',...
0368 'Fontweight', 'bold',...
0369 'Backgroundcolor', [0.8 0.8 0.8],...
0370 'String', 'Operating Conditions');
0371 uicontrol(...
0372 'Parent', Fig,...
0373 'Style', 'frame',...
0374 'Units', 'pixel',...
0375 'Position', [12 FigH-64 248 44]);
0376 Noise = uicontrol(...
0377 'Parent', Fig,...
0378 'Style', 'checkbox',...
0379 'Position', [16 FigH-42 140 18],...
0380 'String', 'Measurement noise',...
0381 'Fontweight', 'bold',...
0382 'Value', 0,...
0383 'Callback', 'envgui([],[],[],''Noise'');');
0384 uicontrol(...
0385 'Parent', Fig,...
0386 'Style', 'text',...
0387 'Units', 'pixel',...
0388 'Position', [156 FigH-40 40 14], ...
0389 'HorizontalAlignment','right',...
0390 'Fontweight', 'bold',...
0391 'String', 'var. ');
0392 NoiseVar = uicontrol(...
0393 'Parent', Fig,...
0394 'Style', 'edit',...
0395 'Units', 'pixel',...
0396 'Position', [196 FigH-42 60 18], ...
0397 'HorizontalAlignment','center',...
0398 'String', '0.0001',...
0399 'Backgroundcolor', [1 1 1],...
0400 'Callback', 'envgui([],[],[],''NoiseParam'');');
0401 LoadDist = uicontrol(...
0402 'Parent', Fig,...
0403 'Style', 'checkbox',...
0404 'Position', [16 FigH-62 150 18],...
0405 'String', 'Load disturbance',...
0406 'Fontweight', 'bold',...
0407 'Value', 0,...
0408 'Callback', 'envgui([],[],[],''Dist'');');
0409 uicontrol(...
0410 'Parent', Fig,...
0411 'Style', 'text',...
0412 'Units', 'pixel',...
0413 'Position', [166 FigH-60 30 14], ...
0414 'HorizontalAlignment','right',...
0415 'Fontweight', 'bold',...
0416 'String', 'amp. ');
0417 LoadAmp = uicontrol(...
0418 'Parent', Fig,...
0419 'Style', 'edit',...
0420 'Units', 'pixel',...
0421 'Position', [196 FigH-60 60 18], ...
0422 'HorizontalAlignment','center',...
0423 'String', '1',...
0424 'Backgroundcolor', [1 1 1],...
0425 'Callback', 'envgui([],[],[],''DistParam'');');
0426
0427
0428 uicontrol(...
0429 'Parent', Fig,...
0430 'Style', 'text',...
0431 'Units', 'pixel',...
0432 'Position', [12 FigH-88 240 14], ...
0433 'HorizontalAlignment','left',...
0434 'Fontweight', 'bold',...
0435 'FontSize', 8,...
0436 'Backgroundcolor', [0.8 0.8 0.8],...
0437 'String', 'Comparative Analysis');
0438 uicontrol(...
0439 'Parent', Fig,...
0440 'Style', 'frame',...
0441 'Units', 'pixel',...
0442 'Position', [12 FigH-118 248 28]);
0443 uicontrol(...
0444 'Parent', Fig,...
0445 'Style', 'pushbutton',...
0446 'Position', [22 FigH-114 72 20],...
0447 'String', 'Time', ...
0448 'Fontweight', 'bold',...
0449 'Callback', 'envgui([],[],[],''StepPID'');');
0450 uicontrol(...
0451 'Parent', Fig,...
0452 'Style', 'pushbutton',...
0453 'Position', [176 FigH-114 72 20],...
0454 'String', 'Frequency', ...
0455 'Fontweight', 'bold',...
0456 'Callback', 'envgui([],[],[],''BodePID'');');
0457
0458 uicontrol(...
0459 'Parent', Fig,...
0460 'Style', 'pushbutton',...
0461 'Position', [100 FigH-145 72 20],...
0462 'String', 'Help', ...
0463 'Fontweight', 'bold',...
0464 'Callback', 'envgui([],[],[],''Hlp'');');
0465
0466
0467
0468
0469
0470 FigUD.Noise = Noise;
0471 FigUD.NoiseVar = NoiseVar;
0472 FigUD.LoadDist = LoadDist;
0473 FigUD.LoadAmp = LoadAmp;
0474
0475 FigUD.Block = get_param(gcbh,'Handle');
0476 FigUD.NoiseBlock = get_param([sys '/' NoiseBlock],'Handle');
0477 FigUD.LoadDistBlock= get_param([sys '/' LoadDistBlock],'Handle');
0478
0479 set(Fig,'UserData',FigUD);
0480
0481 drawnow
0482
0483
0484 set_param(gcbh,'UserData',Fig);
0485