www.gusucode.com > slcontrol 案例源码程序 matlab代码 > slcontrol/SetValueOfTunedBlockParamUsingGenStateSpaceModelExample.m

    %% Set Value of Tuned Block Parameterization Using Generalized State-Space Model  
%%
% Convert an |slTuner| interface for the Simulink(R) model |rct_diskdrive| to 
% a |genss| model to tune the model blocks using |hinfstruct|. After tuning, 
% update the |slTuner| interface with the tuned parameters and write the 
% parameter values to the Simulink model for validation.
%
% Use of |hinfstruct| requires a Robust Control Toolbox license.
%% 
% Create an |slTuner| interface for |rct_diskdrive|. Add |C| and |F| as
% tuned blocks of the interface. 
open_system('rct_diskdrive');
st = slTuner('rct_diskdrive',{'C','F'});  

%% 
% The default parameterization of the transfer function block, |F|, is a
% transfer function with two free parameters. Because |F| is a low-pass
% filter, you must constrain its coefficients. To do so, specify a custom
% parameterization of |F| with filter coefficient |a|.
a = realp('a',1);
setBlockParam(st,'F',tf(a,[1 a]));  

%% 
% Convert |st| to a |genss| model.
m = getIOTransfer(st,{'r','n'},{'y','e'});

%%
% Typically, for tuning with |hinfstruct|, you append weighting functions
% to the |genss| model that depend on your design requirements. You then
% tune the augmented model. For more information, see
% <docid:robust_gs.btl4q23>.

%%
% For this example, instead of tuning the model, manually adjust the tuned 
% variable values.
m.Blocks.C.Kp.Value = 0.00085;
m.Blocks.C.Ki.Value = 0.01;
m.Blocks.a.Value = 5500;

%%
% After tuning, update the block parameterization values in |st|.
setTunedValue(st,m);

%%
% This is equivalent to |setBlockValue(st,m.Blocks)|. 

%%
% To validate the tuning result in Simulink, first update the Simulink
% model with the tuned values.
writeBlockValue(st);