%% hinfstruct Tuning of a Control System in Simulink
% 
%% Open the model

% Copyright 2015 The MathWorks, Inc.

open('rct_diskdrive');
%% Create slTuner interface
ST0 = slTuner('rct_diskdrive',{'C','F'});
%% Specify custom parametrization of F
a = realp('a',1);    % filter coefficient
setBlockParam(ST0,'F',tf(a,[1 a]));
%% Extract tunable model from slTuner interface
T0 = getIOTransfer(ST0,{'r','n'},{'y','e'});
%% Define and append weighting functions
wc = 1000;  
s = tf('s');
LS = (1+0.001*s/wc)/(0.001+s/wc);

T0 = blkdiag(1,LS) * T0 * blkdiag(1,1/LS);
%% Tune the model
[T,gamma,info] = hinfstruct(T0); 
%% Propagate tuned parameter values to new slTuner
ST = copy(ST0);
setBlockValue(ST,T);
%% Examine Closed-loop response
Try = getIOTransfer(ST,'r','y');
step(Try)
%% Write parameter values to model
writeBlockValue(ST)