Tunable Block Parameters and Tunable Global Parameters

To change the behavior of a model, you can tune Simulink® Desktop Real-Time™ block parameters, provided the parameters are tunable. You can change block parameters via the block parameter dialog box, Dashboard blocks, and MATLAB® language. You can create tunable global parameters by using MATLAB variables as value expressions.

In normal or accelerator mode, Simulink transfers the new values to the model that is being simulated. In external mode, Simulink transfers the new values to the real-time application that is running in the kernel mode process.

Tunable Parameters

Simulink Desktop Real-Time defines two kinds of tunable parameters: block parameters and global parameters.

Tunable Block Parameters

A block parameter is a constant expression that you reference in a Simulink block dialog box or by using the MATLAB API. Block parameters are tunable when you set the Default parameter behavior option to Tunable on the Optimization pane. When using the MATLAB API, you identify a block parameter by the parameter name and the block path in the model hierarchy.

Suppose that you set the Amplitude parameter of a Signal Generator block to a value of 5/2. You can change the amplitude of the signal generator during simulation by tuning parameter Amplitude in block Signal Generator.

Tunable Global Parameter

A tunable global parameter is a MATLAB variable that you reference in a Simulink block dialog box. You can tune a global parameter or object by using a block dialog box, Dashboard blocks, Property Inspector, Model Explorer, Model Data Editor, or MATLAB language. When using the MATLAB API, you identify a tunable global parameter by the variable name only.

Suppose that you assign to the Amplitude parameter the variable A with the value 4.57. You can change the amplitude of the signal generator during simulation by tuning the value of A in the MATLAB workspace and updating the simulation.

Inlined Parameters

To improve execution efficiency, open the Configuration Parameters dialog box and set the Default parameter behavior option to Inlined on the Code Generation > Optimization pane.

By default, you cannot tune inlined block parameters. However, you can create a tunable global variable by referencing a MATLAB variable or Simulink.Parameter object in the block dialog box. To make the variable or object tunable, apply a storage class other than Auto to it.

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

Tune Parameters by Using External Mode

In external mode, Simulink Desktop 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 parameter value in a block dialog box or replace the value with a MATLAB variable and tune the variable in the Command Window.

When you change a parameter value in a Simulink model and click OK, Simulink Desktop Real-Time transfers the data to the real-time application and changes the block parameter. You can change only the parameters that do not change the model structure. If you modify the structure, you must recompile the model.

If you change the value of a tunable global parameter, instruct Simulink to transfer the data from the MATLAB variable to the real-time application by either:

  • Pressing Ctrl+D.

  • In the Simulink Editor, on the Debug tab, clicking Update Model.

Tune Parameters by Using Batch Mode and Update All Parameters

By using Batch Mode, you can tune multiple parameters and apply all of the tuned parameters at once, instead of tuning one parameter at a time. This example uses model sldrtex_model (matlab: open_system(docpath(fullfile(docroot, 'toolbox', 'sldrt', 'examples', 'sldrtex_model')))).

  1. Open model sldrtex_model.

  2. In the Simulink Editor, on the Desktop Real-Time tab, click Run in Real Time.

  3. On the Desktop Real-Time tab, click Prepare > Batch Mode. The editor remains in batch mode until you click Batch Mode again.

    To set parameter values, you can set values either by clicking each block or by using the Model Data Editor.

  4. On the Desktop Real-Time tab, Prepare > Signal Table.

  5. In the Model Data Editor, click the Parameters tab. Modify parameters values in the Model Data Editor.

  6. On the Desktop Real-Time tab, click Prepare > Update All Parameters.

  7. To stop the simulation before it ends, on the Desktop Real-Time tab, click Stop.

Tune Parameters by Using the MATLAB Language

In Simulink Desktop Real-Time, you can use the MATLAB language command set_param to change the values of block parameters and tunable global parameters. The following code examples use the model sldrtex_model (matlab: open_system(docpath(fullfile(docroot, 'toolbox', 'sldrt', 'examples', 'sldrtex_model')))).

If you are using a literal block parameter value, you access the parameter by a nonempty block path and the parameter name. For example, to change the amplitude of the signal generator:

model = 'sldrtex_model';
sgname = [model '/Signal Generator'];
set_param(sgname, 'Amplitude', '4.57')

If you are replacing a block parameter with a tunable global parameter, you access the parameter by variable name. Suppose that you set Amplitude to the variable A. To change the amplitude of the signal generator:

A = 4.57
set_param('sldrtex_model','SimulationCommand','update')

Related Topics