MATLAB: How to modify or tune Simscape Tunable Parameters at simulation run-time

parametersrun timeSimscapesimulink codertunable

I am generating code and compiling an executable from my Simscape model, with the intent to change tunable parameters at run-time.
In the generated code, tunable parameters added to my model are not showing up as expected in the code using the 'grt' target. Likewise, my generated executable does not respond to my attempts to change the tunable parameter's value at run-time. Why might this be?

Best Answer

In Simscape the process to make parameters run-time tunable is a bit different from base Simulink.
By default, Simscape will compute parameter values at compile-time and not at run-time. This preference option can be changed from MATLAB Preferences.
1. Open the MATLAB Preferences Dialog.
2. Select Simscape from the left pane.
3. Select the "Show run-time parameter settings" option.
Now, tunable parameters in your Simscape blocks will have a dropdown next to their values to select either "run-time" or "compile-time". For tunability in Fast Restart or Rapid Acclerator, set the option to "run-time".
Refer to the following documentation pages for more information about Simscape Run-Time Parameters: