How can I reload my real-time application with the parameters from a previous run with Simulink Real-Time?
6 views (last 30 days)
Show older comments
MathWorks Support Team
on 5 Jul 2023
Edited: MathWorks Support Team
on 7 Nov 2024
I use Simulink Real-Time (SLRT) to run my model in real-time on a Speedgoat computer. However, each time the model is re-started or re-loaded, the parameter values that I have applied during the previous run are lost. Instead, the parameters are reset to the original values from when the model was built.
Is there a way to reload the parameters used in the previous run?
Accepted Answer
MathWorks Support Team
on 7 Nov 2024
Edited: MathWorks Support Team
on 7 Nov 2024
In Simulink Real-Time R2021a and later releases, there is a feature that automatically saves a parameter set file named 'autoSaveOnStop' on the target when stopping the real-time application. Additionally, you can save other parameter files at any chosen time from a loaded or running application using the saveParamSet function.
To restore the auto-saved parameter set (or any saved parameter set) from the previous run, use the loadParamSet command after loading the application. Here's an example:
% load real-time application that has been run at least once
mdlName = 'slrt_ex_osc_outport';
tg = slrealtime('TargetPC1');
load(tg,mdlName);
% load tuned parameter values from previous run of real-time application
% that were auto saved when the application was stopped
loadParamSet(tg,'autoSaveOnStop');
In R2024a and later releases, the 'setDefaultParamSet' function can be used after the first run to select the 'autoSaveOnStop' parameter set as default for all future runs. Then 'saveOnStop' will override the parameter set each time with the latest values:
% load real-time application that has been run at least once mdlName = 'slrt_ex_osc_outport';tg = slrealtime('TargetPC1');load(tg,mdlName);% load tuned parameter values from previous run of real-time application% that were auto saved when the application was stoppedsetDefaultParamSet(tg,mdlName,'autoSaveOnStop');
You can also import any saved parameter sets from the target to the MATLAB development computer with importParamSet, allowing you to edit the parameters as a ParameterSet object. After editing, you can re-export them using exportParamSet.
Since R2024b, there is a new ParameterSetButton that facilitates the management of parameter sets on the target, as well as setting and clearing the default parameter set for SLRT app users.
For more detailed information on using parameter sets, please refer to the documentation:
Save and Reload Parameters by Using the MATLAB Language
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!