Simulink Custom Storage Class "Importeddefine"

조회 수: 12 (최근 30일)
Andreas
Andreas 2011년 1월 28일
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 Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by