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.

 채택된 답변

Urmila Rajpurohith
Urmila Rajpurohith 2020년 1월 13일

0 개 추천

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

Antonin Berthelot
Antonin Berthelot 2020년 1월 15일
편집: Antonin Berthelot 2020년 1월 15일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Community Treasure Hunt

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

Start Hunting!

Translated by