Simscape™ run-time parameters and Simulink® tunable parameters both allow you to change the values of parameters on your development or target computer without model recompilation. However, they differ in these important ways:
You can change the value of a Simulink tunable parameter while a simulation is running. Simscape run-time parameters are run-time configurable. You cannot change the value of a run-time configurable parameter during simulation. You can only change the value of a run-time configurable parameter when a simulation is stopped.
Simulink tunable parameters are tunable by default. Simscape block parameters are compile-time configurable by default. To make a Simscape block parameter run-time configurable, you specify it as such.
Simulink tunable parameters are tunable-by-field. You can change a tunable parameter simply by changing the numeric value using the block dialog box parameter setting. Simscape run-time parameters are tunable-by-variable. To change the value of a Simscape run-time parameter, you:
Specify a variable for the parameter in the block dialog box setting.
Use input tools, such as the command prompt, callbacks, scripts, or MAT-files, to assign a value for the variable in the MATLAB® workspace.
Use input tools to change the value for the variable.
For code generation, you specify the Default
parameter behavior as Tunable
or Inlined
.
You cannot modify inlined parameters in generated code because the
compiler specifies them as constants. You can change the values of
tunable parameters in generated code because the compiler specifies
them as modifiable global variables or structure fields.
If you set the default behavior to Tunable
,
the compiler specifies all Simscape run-time parameters and Simulink tunable
parameters as modifiable entities in the generated code. However,
if you set the default behavior to Inlined
,
the compiler inlines only the Simscape run-time parameters. The Simulink tunable
parameters are still generated as modifiable entities in the code.
To change the value of a particular Simscape run-time parameter
in the generated code when the default behavior is inlined, you declare
that parameter as an exception to inlining.
The table shows the state, mode, and code section in which you can change a run-time parameter or run-time configurable parameter.
Machine | Simulink Simulation Mode | Simulation Status | Section of Generated Code That You Modify | Simscape Run-Time Parameter Is Modifiable | Simulink Tunable Parameter Is Modifiable |
---|---|---|---|---|---|
Development | Normal | SimulationStatus is stopped | Not Applicable (NA) | Yes | Yes |
Development | Normal | SimulationStatus is running | NA | No | Yes |
Development or Target | Normal, Accelerator, Rapid Accelerator, SIL, PIL, or External | SimulationStatus is stopped | NA | Yes | Yes |
Development or Target | Normal, Accelerator, Rapid Accelerator, SIL, PIL, or External | SimulationStatus is running | NA | No | Yes |
Target | Normal, SIL, PIL, or External | SimulationStatus is stopped | Setup-function | Yes | Yes |
Target | Normal, SIL, PIL, or External | SimulationStatus is running |
| No | Yes |
Between normal mode simulations, as long as your changes do not affect the structure of the model, you can forgo recompiling by using fast restart when you change Simscape run-time and Simulink tunable parameters.