Can I create tunable parameters in C++ code generated by the Embedded Coder when "Default Parameter Behavior" is "Inlined" in MATLAB R2021b?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 29 Juin 2023
Réponse apportée : MathWorks Support Team
le 5 Juil 2023
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?
Réponse acceptée
MathWorks Support Team
le 29 Juin 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.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Simulink Coder dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!