Passing Custom Command Line Arguments to a Compiled Simulink Model

4 visualizaciones (últimos 30 días)
Hello,
I'd like to pass command line arguments to a compiled GRT Simulink model. The idea is to overwrite pre defined variables used in the model, e.g. in a Constant block. So far I could not find any information on this.
Thank you in advance for your help!
Best,
Leon

Respuesta aceptada

R
R el 20 de Jun. de 2024
Passing command-line arguments to a compiled GRT Simulink model, with the objective of modifying predefined variables like those in a Constant block, presents a challenge as the compiled executable from a GRT target does not inherently possess the capability to parse command-line arguments as a traditional C or C++ program might.
This is primarily because the GRT target is tailored for real-time simulation and code generation, prioritizing the deterministic execution of Simulink models over accommodating general-purpose programming features such as argument parsing.
To adapt the generated code for such tasks, begin by identifying the function where model parameters are initialized. When utilizing code generated from a model, you typically interact with generated entry-point functions, such as step and initialize. For a comprehensive understanding of how generated code can interact with external environments, consider consulting the documentation at: https://www.mathworks.com/help/rtw/ug/how-generated-code-exchanges-data-with-an-environment.html
To make internal data, like a gain value, externally adjustable, it should be declared as a parameter object, such as Simulink.Parameter. Detailed guidance on this process can be found in the documentation section here.
To incorporate command-line argument parsing into your project, you'll need to manually integrate standard C code that can interpret the arguments (argc and argv) and subsequently adjust the model's parameters accordingly. This may require converting argument strings into their respective data types (e.g., using atoi or atof for integers or floats).
For further assistance on calling C or C++ library functions from MATLAB, you might find the following resources helpful:
  1. https://www.mathworks.com/help/matlab/call-c-library-functions.html
  2. https://www.mathworks.com/help/matlab/call-cpp-library-functions.html

Más respuestas (1)

Reid Spence
Reid Spence el 1 de Ag. de 2024
If your goal is standalone simulation on a desktop then Simulink Compiler might make your life easier. You can write the code in MATLAB to accept command line arguments for the generated EXE.
Otherwise what others have said is correct for ERT generated code, you will need to modify the generated code and main file. Simulink Compiler would save you some of this work.

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by