Documentation

Tunable Block Parameters and Tunable Global Parameters

To change the behavior of a real-time application, you can tune Simulink® Real-Time™ tunable parameters. In Simulink external mode, you can change the parameters directly in the block or indirectly by using MATLAB® variables to create tunable global parameters. Simulink Real-Time Explorer and MATLAB language enable you to change parameter values and MATLAB variables as your real-time application is executing.

Note

Simulink Real-Time does not support parameters of multiword data types.

Tunable Parameters

Simulink Coder™ defines two kinds of parameters that can be modified during execution: tunable block parameters and tunable global parameters.

Tunable Block Parameters

A tunable block parameter is a literal expression that you reference in a Simulink block dialog box.

Suppose that you assign the value 5/2 to the Amplitude parameter of a Signal Generator block. Amplitude is a tunable parameter.

Tunable Global Parameter

A tunable global parameter is a variable in the MATLAB workspace that you reference in a Simulink block dialog box.

Suppose that you enter A in the Amplitude parameter of a Signal Generator block. Variable A is a tunable parameter.

You can tune the values of MATLAB variables that are grouped in a parameter structure. For example:

  1. Assign a parameter structure that contains the field Ampl to variable A.

  2. Enter A.Ampl in the Amplitude parameter of a Signal Generator block.

  3. Change the amplitude of the signal generator by tuning the value of A.Ampl in the MATLAB workspace during simulation.

Inlined Parameters

To optimize execution efficiency, you can change the Default parameter behavior option from Tunable to Inlined in the Signals and Parameters pane of the Optimization node.

You cannot tune inlined block parameters. You can define a tunable global parameter or Simulink.Parameter object, enter it in the parameter in the block dialog box, and tune the MATLAB variable or object.

For more information about inlined parameters, see Default parameter behavior (Simulink).

Tuning in External Mode

In external mode, Simulink Real-Time connects your Simulink model to your real-time application. The block diagram becomes a user interface for the real-time application.

You can change a block parameter value during execution in the block dialog box. When you click OK, Simulink transfers the new value to the real-time application.

You can also change a tunable global parameter during execution by assigning a new value to the MATLAB workspace. You must then explicitly command Simulink to transfer the data by pressing Ctrl+D or clicking Simulation > Update Diagram.

Tuning with Simulink Real-Time Explorer

During real-time execution, Simulink Real-Time Explorer becomes a user interface for the real-time application.

To access a block parameter value, navigate to the block in the Explorer model hierarchy. You can change the value in a text entry box in the parameter window. When you apply the new value, Simulink Real-Time transfers the new value to the real-time application.

You can access a tunable global parameter at the top level of the model hierarchy. Change it the same way as you would a tunable block parameter.

You can also use Simulink Real-Time Explorer instrument panels to tune block parameters and global parameters.

Tuning with MATLAB Language

To change the values of tunable block parameters and tunable global parameters during execution, use the Simulink Real-Time command setparam. The following code examples use the model xpcosc.

To change a block parameter value, use a nonempty block path and the parameter name. For example, to change the amplitude of the signal generator:

tg = slrt;
setparam(tg, 'Signal Generator', 'Amplitude', 4.57)

To change a tunable global parameter, use the variable name. For example, to change the amplitude of the signal generator via the parameter structure field A.Ampl:

tg = slrt; 
setparam(tg, 'A.Ampl', 4.57)

See Also

|

Related Topics

Was this topic helpful?