Can I create tunable parameters in C++ code generated by the Embedded Coder when "Default Parameter Behavior" is "Inlined" in MATLAB R2021b?

5 Ansichten (letzte 30 Tage)
I am using MATLAB R2021b. I have a Simulink model "myModel.slx" that I am generating a C++ class from using the Embedded Coder.
I store all my "Simulink.Parameter" objects in the model workspace of "myModel". I also have the "Default Parameter Behavior" ("DefaultParameterBehavior") setting set to "Inlined".
Because the default behavior is "Inlined", the values of my model parameters are inlined in the generated C++ class and are not stored in any variables. However, I want to be able to make my model workspace parameters tunable so they are a) stored in a variable and b) can be made into global/static variables that are shared among each instance of the C++ class. How can I accomplish this?

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 29 Jun. 2023
To make tunable parameters in generated C++ code when the "Default Parameter Behavior" is "Inlined", you must move the parameters to either the base workspace or a Simulink Data Dictionary so that you can set its storage class. To then make a parameter into a global variable, you must change the parameter's storage class in one of the following ways:
1) Change the storage class to a type that generates a global variable in the generated code. One way to do this is by using the storage class "ExportedGlobal". Parameters with the "ExportedGlobal" storage class are stored in global variables in the generated C++ code.
2) Change the storage class to "Model Default". Parameters with this storage class are stored in a static struct, so the struct will be shared among all instance of the same class. Please note this option is only available in models that do not reference other models.

Weitere Antworten (0)

Kategorien

Mehr zu Simulink Coder finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by