Change parameters in Simscape model executable

3 views (last 30 days)
I converted a Simscape model to C code and Matlab generated a .exe file as well. The idea is to deploy this model without giving access to the model content. The end-user will use Matlab to run this executable.
The executable runs and produces correct results, however I cannot figure out how to change the parameters used for the simulation.
Attached is a basic example where I would like to be able to change the value of the AC Voltage Source peak amplitude, which is currently given by a workspace variable.

Accepted Answer

Urmila Rajpurohith
Urmila Rajpurohith on 13 Jan 2020
you can follow below steps to change parameters in Simscape model executable
  • In Preference -> Simscape enable "Show runtime parameter settings".
  • Ensure that you have a Simulink parameter that defines the specified Run-time parameter you want to change.
  • Set the parameter to Run-time.
  • Ensure the Simulink parameter's storage class is "Model Default".
  • Enable "Generate Example main program" in Simulink Configuration Parameters under Code Generation > Templates > Custom Templates.
  • Enable "Generate C API for Parameters" in the Configuration Parameters under Code Generation > Interface > Data Exchange Interface.
  • Generate code for the model.
You will have to edit the example main file to set the value for the parameter you want to change, but a function should be produced that looks like "rtDataAddrMap". Inside the main function before "rt_OneStep()" is called, handle the value for the tune-able parameter.
  1 Comment
Antonin Berthelot
Antonin Berthelot on 15 Jan 2020
Edited: Antonin Berthelot on 15 Jan 2020
Thank you for your answer!
In the end, some of the parameters I wanted to change were compile-time only unfortunaly. I'm afraid I will have to wait for a Matlab update before being able to generate C code for this specific Simscape model.
However, Matlab support suggested a workaround that allows me to deploy the Simscape model without giving access to the content:
1) Group all Simscape blocks in a Subsystem
3) Generate ssc code from the subsystem.
4) Protect the ssc code.
5) Build a Simscape block from it.

Sign in to comment.

More Answers (0)

Categories

Find more on Run-Time Parameters in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!