Can I create tunable parameters in C++ code generated by the Embedded Coder when "Default Parameter Behavior" is "Inlined" in MATLAB R2021b?
4 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2023 年 6 月 29 日
回答済み: MathWorks Support Team
2023 年 7 月 5 日
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?
採用された回答
MathWorks Support Team
2023 年 6 月 29 日
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 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!