Change parameters in Simscape model executable

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.

 Respuesta aceptada

Urmila Rajpurohith
Urmila Rajpurohith el 13 de En. de 2020

0 votos

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 comentario

Antonin Berthelot
Antonin Berthelot el 15 de En. de 2020
Editada: Antonin Berthelot el 15 de En. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Community Treasure Hunt

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

Start Hunting!

Translated by