setBlockValue

Set value of tuned block parameterization in slTuner interface

Syntax

  • setBlockValue(st,blk_val_struc) example

Description

example

setBlockValue(st,blk,val) sets the current value of the parameterization of a tunable block in an slTuner interface.

The slTuner interface associates a parametric model with each Simulink® model listed in the TunedBlocks property of st. This parameterization expresses each tunable block as a Control Design Block or a tunable genss model. The parameterization specifies which parameters are tuned by commands such as systune.

You can use setBlockValue to initialize the tunable parameters of blocks parameterized by Control Design Blocks before tuning st with a tuning command such as systune or looptune.

example

setBlockValue(st,elem,val) sets the current value of a particular tunable element of a custom parameterization of a tunable block in an slTuner interface. If you use setBlockParam to assign a custom genss model parameterization of a tuned block, this syntax lets you set the value of a particular tunable element of the genss model.

example

setBlockValue(st,m) updates the current values of the tunable parameters in st to match the corresponding values of tunable parameters in the Generalized LTI Model model, m. Only parameters common to st and m are updated. Use this syntax to update st after obtaining m by tuning with commands such as systune, looptune, or hinfstruct.

example

setBlockValue(st,blk_val_struc) updates the value of multiple blocks using the structure, blk_val_struc. Only blocks common to st and blk_val_struc are updated. Use this syntax to update st after obtaining blk_val_struc by tuning with commands such as systune, looptune, or hinfstruct. blk_val_struc corresponds to the Blocks property value of the generalized state-space model returned by such commands.

Examples

expand all

Set Value of Tuned Block Parameterization

Create an slTuner interface for the scdcascade model, and set the value of the parametrization of one of the tuned blocks.

Create an slTuner interface.

open_system('scdcascade');
st = slTuner('scdcascade',{'C1','C2'});

Both C1 and C2 are PI controllers. Examine the default parameterization of C1.

getBlockParam(st,'C1')
  Parametric continuous-time PID controller "C1" with formula:

             1 
  Kp + Ki * ---
             s 

  and tunable parameters Kp, Ki.

Type "pid(ans)" to see the current value and "get(ans)" to see all properties.

The default parameterization is a PI controller with two tunable parameters, Kp and Ki.

Set the value of the parameterization of C1.

C = pid(4.2);

setBlockValue(st,'C1',C);

Examine the value of the parameterization of C1.

getBlockValue(st,'C1')
  Kp = 4.2
 
Name: C1
P-only controller.

Examine the parameterization of C1.

getBlockParam(st,'C1')
  Parametric continuous-time PID controller "C1" with formula:

             1 
  Kp + Ki * ---
             s 

  and tunable parameters Kp, Ki.

Type "pid(ans)" to see the current value and "get(ans)" to see all properties.

Observe that although the current block value is a P-only controller, the block parameterization continues to be a PI-controller.

Set Value of Tuned Block Parameterization Using Generalized State-Space Model

This example shows how to convert an slTuner interface for the Simulink model rct_diskdrive to a genss model. Perform this conversion to tune the model blocks using hinfstruct (requires Robust Control Toolbox™). After validating the tuning results, you can update the slTuner interface with the tuned parameters returned by hinfstruct. Then, you can use the slTuner interface to write the tuned parameter values to the Simulink model.

This example requires Robust Control Toolbox.

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.

a = realp('a',1);    % filter coefficient
setBlockParam(st,'F',tf(a,[1 a]));

Suppose you want to tune the closed-loop transfer function using hinfstruct, which operates only on genss models. Convert st to a genss model.

t0 = genss(st);
t0 = getIOTransfer(t0,{'r','n'},{'y','e'});

t0 contains the linearized closed-loop transfer function from the reference noise inputs, r and n, to the measurement and error outputs, y and e. The error output is needed for the loop-shaping weighting function.

Define the loop-shaping weighting functions and append them to t0.

wc = 1000;
s = tf('s');
ls = (1+0.001*s/wc)/(0.001+s/wc);

t0 = blkdiag(1,ls)*t0*blkdiag(1,1/ls);

t0 is a weighted closed-loop model of the control system of rct_diskdrive.

You can now use hinfstruct to tune the parameters of t0.

t = hinfstruct(t0);

After validating the tuning result, suppose you want to update the Simulink model with the tuned values.

setBlockValue(st,t);
writeBlockValue(st);

You can also use the command setBlockValue(st,t.Blocks) to update the block parameterization values in st.

Set Value of Single Tunable Element within Custom Parameterization

Create an slTuner interface for the scdcascade model. Set a custom parameterization of one of the tunable blocks.

open_system('scdcascade');
st = slTuner('scdcascade',{'C1','C2'});
C1CustParam = realp('Kp',1) + tf(1,[1 0]) * realp('Ki',1);
setBlockParam(st,'C1',C1CustParam);

These commands set the parameterization of the C1 controller block to a generalized state-space (genss) model containing two tunable parameters, 'Ki' and 'Kp'..

Initialize the value of Ki to 10, without changing the current value of 'Kp'

setBlockValue(st,'Ki',10);

Input Arguments

expand all

st — Interface for tuning control systems modeled in SimulinkslTuner interface

Interface for tuning control systems modeled in Simulink, specified as an slTuner interface.

blk — Blockstring

Block in the list of tuned blocks for st, specified as a string.

You can specify the full block path or any portion of the block path that uniquely identifies the block among the other tuned blocks of st.

For example, blk = 'scdcascade/C1' or blk = 'C1'.

elem — Tunable element of custom parameterizationstring

Tunable element of a custom parameterization of a tuned block, specified as a string. If you use setBlockParam to assign a custom genss model parameterization of a tuned block, elem can be any of the tunable elements of the genss parameterization. For example, suppose you set the parameterization of a tuned block in st to Kp + Ki* tf(1,[1 0]), where Kp and Ki are realp tunable parameters with names 'Kp' and 'Ki'. In that case you can set elem to 'Kp' or 'Ki' to set the current value of each parameter.

val — Block parameterization valuecontrol design block | numeric LTI model | numeric scalar or array

Parameterization value, specified as a control design block, a numeric LTI model, or a numeric value.

val can be any model or value that is compatible with the parameterization of the block or element whose value you are setting. For example, suppose you are setting the value of a block that is parameterized as an ltiblock.pid. You can specify val as one of the following models: ltiblock.pid, numeric pid, numeric tf model representing a PID controller. Alternatively, if you are setting the value of a scalar tunable parameter in a custom parameterization, val must be a scalar.

setBlockValue updates the value of the parameters of the tuned block based on the parameters of val. Using setBlockValue does not change the structure of the parameterization of the tuned block. To change the parameterization of blk, use setBlockParam. For example, you can use setBlockParam to change a block parameterization from ltiblock.pid to a three-pole ltiblock.tf model.

m — Tuned modelgeneralized LTI model

Tuned model that has some parameters in common with st, specified as a Generalized LTI Model.

blk_val_struc — Parameterization value of multiple blocksstructure

Parameterization value of multiple blocks, specified as a structure.

Was this topic helpful?