Main Content

getTunedValue

Get current value of tuned variable in slTuner interface

Description

getTunedValue lets you access the current value of a tuned variable within an slTuner interface.

An slTuner interface parameterizes each tuned block as a Control Design Block, or a generalized parametric model of type genmat or genss. This parameterization specifies the tuned variables for commands such as systune.

example

value = getTunedValue(st,var) returns the current value of the tuned variable, var, in the slTuner interface, st.

example

[value1,value2,...] = getTunedValue(st,var1,var2,...) returns the current values of multiple tuned variables.

example

S = getTunedValue(st) returns a structure containing the current values of all tuned variables in st.

Examples

collapse all

Create an slTuner interface for the scdcascade model.

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

Set a custom parameterization for one of the tunable blocks.

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.

Typically, you would use a tuning command such as systune to tune the values of the parameters in the custom parameterization.

After tuning, use getTunedValue to query the tuned value of Ki.

KiTuned = getTunedValue(st,'Ki')
KiTuned =

     1

To query the value of the tuned block as a whole, C1, use getBlockValue.

Create an slTuner interface for the scdcascade model.

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

Set a custom parameterization for one of the tunable blocks.

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 tunable parameters Kp and Ki.

Typically, you would use a tuning command such as systune to tune the values of the parameters in the custom parameterization.

After tuning, use getTunedValue to query the tuned values of both Kp and Ki.

[KiTuned,KpTuned] = getTunedValue(st,'Ki','Kp')
KiTuned =

     1


KpTuned =

     1

Create an slTuner interface for the scdcascade model.

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

Set a custom parameterization for tuned block C1.

C1CustParam = realp('Kp',1) + tf(1,[1 0]) * realp('Ki',1);
setBlockParam(st,'C1',C1CustParam);

Typically, you would use a tuning command such as systune to tune the values of the parameters in the custom parameterization.

After tuning, use getTunedValue to query the tuned values of the parameterizations of all the tuned blocks in st.

S = getTunedValue(st)
S = 

  struct with fields:

    C2: [1x1 pid]
    Ki: 1
    Kp: 1

The tuned values are returned in a structure that contains fields for:

  • The tuned block, C2, which is parameterized as a Control Design Block.

  • The tunable elements, Kp and Ki, within block C2, which is parameterized as a custom genss model.

Input Arguments

collapse all

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

Tuned variable within st, specified as a character vector or string. A tuned variable is any Control Design Block, such realp, tunableSS, or tunableGain, involved in the parameterization of a tuned Simulink block, either directly or through a generalized parametric model. To get a list of all tuned variables within st, use getTunedValue(st).

var can refer to the following:

  • For a block parameterized by a Control Design Block, the name of the block. For example, if the parameterization of the block is

    C = tunableSS('C')

    then set var = 'C'.

  • For a block parameterized by a genmat/genss model, M, the name of any Control Design Block listed in M.Blocks. For example, if the parameterization of the block is

    a = realp('a',1);
    C = tf(a,[1 a]);

    then set var = 'a'.

Output Arguments

collapse all

Current value of tuned variable in st, returned as a numeric scalar or array or a state-space model. When the tuning results have not been applied to the Simulink model using writeBlockValue, the value returned by getTunedValue can differ from the Simulink block value.

Note

Use writeBlockValue to align the block parameterization values with the actual block values in the Simulink model.

Current values of all tuned variables in st, returned as a structure. The names of the fields in S are the names of the tuned variables in st, and the field values are the corresponding numeric scalars or arrays.

You can use this structure to transfer the tuned variable values from one slTuner interface to another slTuner interface with the same tuned variables, as follows:

S = getTunedValue(st1);
setTunedValue(st2,S);

More About

collapse all

Tuned Blocks

Tuned blocks, used by the slTuner interface, identify blocks in a Simulink model whose parameters are to be tuned to satisfy tuning goals. You can tune most Simulink blocks that represent linear elements such as gains, transfer functions, or state-space models. (For the complete list of blocks that support tuning, see How Tuned Simulink Blocks Are Parameterized). You can also tune more complex blocks such as SubSystem or S-Function blocks by specifying an equivalent tunable linear model.

Use tuning commands such as systune to tune the parameters of tuned blocks.

You must specify tuned blocks (for example, C1 and C2) when you create an slTuner interface.

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

You can modify the list of tuned blocks using addBlock and removeBlock.

To interact with the tuned blocks use:

Tuned Variables

Within an slTuner interface, tuned variables are any Control Design Blocks involved in the parameterization of a tuned Simulink block, either directly or through a generalized parametric model. Tuned variables are the parameters manipulated by tuning commands such as systune.

For Simulink blocks parameterized by a generalized model or a tunable surface:

  • getBlockValue provides access to the overall value of the block parameterization. To access the values of the tuned variables within the block parameterization, use getTunedValue.

  • setBlockValue cannot be used to modify the block value. To modify the values of tuned variables within the block parameterization, use setTunedValue.

For Simulink blocks parameterized by a Control Design Block, the block itself is the tuned variable. To modify the block value, you can use either setBlockValue or setTunedValue. Similarly, you can retrieve the block value using either getBlockValue or getTunedValue.

Version History

Introduced in R2015b