Tunable parameters in Simulink code generation

4 次查看(过去 30 天)
I am making an S-Function with mask parameters and want to generate C code for this block. All S-Function parameters should be tunable. Currently I declared the parameters as tunable via ssSetSFcnParamTunable(S, PARAM_P0_IDX, SS_PRM_TUNABLE); and ssRegAllTunableParamsAsRunTimeParams. I also verified that the parameters show up in the model.rtw file. However, in code generation the parameters are still inlined (i.e., I see 1.0f instead of myDataStruct.myParam).
I tried the sfcndemo_runtime example and see the same behavior. Only when the mask parameters are declared in the base workspace, they become tunable. The S-Function I am making will be used in a library block and I expect there to be multiple instances of this block. Therefore declaring the workspace variables automatically will be error-prone. The generated code will not be functional when (some) parameters are inlined, and I don't want to make the user responsible for declaring these workspace variables.
Is there a way to get tunable parameters in the generated code without declaring corresponding variables in the base workspace?

回答(1 个)

Akshat Dalal
Akshat Dalal 2024-10-7
Hi,
You can declare the variales in Model Workspace of the library block. This way, it will be distinct for each instance of the block. You can have a look the following docuementation for more information: https://www.mathworks.com/help/rtw/ug/configure-data-accessibility-for-rapid-prototyping.html

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by