Simulink Custom Storage Class "Importeddefine"

7 次查看(过去 30 天)
I have a headerfile (params.h) with some defines (#define test_param 22) and want to use/import this in a Simulink model (ERTW). I add a Simulink.Parameter and assign "ImportedDefine (Custom)" as Storage Class and add "params.h" to the "Custom attributes -> Header file". How can I use this "test_param" in the model (it does not work with a constant / gain block) ?
  2 个评论
Kaustubha Govind
Kaustubha Govind 2011-1-28
Hi Andreas,
Do you see an error when you use the parameter with a gain block? Could you post the error?
~K
Andreas
Andreas 2011-1-31
I named the Simulink.Parameter "test_param" and put this string in the field "gain" of the gain block. If I assign no value to "test_param" I get the error "Invalid setting in 'mymodel/Gain' for parameter 'Gain'". If I assign a value to "test_param" the model uses this value (without an error) but does not import the value from the #define in the specified header file.
Also same behaviour with a constant block.

请先登录,再进行评论。

回答(1 个)

MarkB
MarkB 2011-1-31
Basically, Simulink itself doesn't use header files, but compilers do. Thus, in this case the "Simulink.Parameter"'s job is essentially to describe the content of the header file for simulation. As a result, the ".Value" field that you use in your "Simulink.Parameter" object is the number that Simulink will use when you press the "play" button.
However, when you generate code, the data object will cause a "#include" statement to appear in the generated code, and the code will use (but not define or declare) the name "test_param", expecting the header file provide it.
Since the "Simulink.Parameter" is what is used for simulation, it is important to ensure that it accurately reflects what the header file will provide to the generated code (i.e. the numeric values should match).

类别

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