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 by using the block parameter dialog box, Dashboard blocks, and MATLAB® language. You can create tunable global parameters by using MATLAB variables as value expressions.
In Connected IO mode or accelerator mode, Simulink transfers the new values to the model that is being simulated. In Run in Kernel mode, Simulink transfers the new values to the real-time application that is running in the kernel mode process.
Procedures to consider when working with tunable parameters include:
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 Run in Kernel Mode
In Run in Kernel 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 Hold Updates and Update All Parameters
By using Hold Updates, 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
. To open this model,
in the MATLAB Command Window, type:
openExample('sldrtex_model')
Open model
sldrtex_model
.In the Simulink Editor, on the Desktop Real-Time tab, click Run in Real Time.
On the Desktop Real-Time tab, click Prepare > Hold Updates. The editor remains in Hold Updates mode until you click Hold Updates again.
To set parameter values, you can set values either by clicking each block or by using the Model Data Editor in the base workspace.
On the Desktop Real-Time tab, Prepare > Signal Table.
In the Model Data Editor, click the Parameters tab. Modify parameters values in the Model Data Editor in the base workspace.
On the Desktop Real-Time tab, click Prepare > Update All Parameters.
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. This example uses model
sldrtex_model
. To open this model, in the MATLAB Command Window, type:
openExample('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
- Tune Block Parameters by Using the Block Dialog Box
- Tune Block Parameters with Data Navigation
- Sweep MATLAB Variables with MATLAB Scripting
- Water Tank Model with Dashboard
- Default parameter behavior (Simulink Coder)
- Tune and Experiment with Block Parameter Values
- Share and Reuse Block Parameter Values by Creating Variables
- How Generated Code Stores Internal Signal, State, and Parameter Data (Simulink Coder)
- Preserve Variables in Generated Code (Simulink Coder)
- Troubleshoot Missing Desktop Real-Time Tab