Why is the "Remove internal data zero initialization" option removed when the code generation interface is specified to a C++ class?

9 ビュー (過去 30 日間)
SB
SB 2023 年 3 月 2 日
コメント済み: SB 2023 年 3 月 9 日
I am attempting to code a simulink model using a C++ class as the code interface package. I have so far been able to generate the code, compile, and test it, however I have noticed some runtime issues.
I am using low pass filters in my model and noticed that early on in the program's execution the initial state of the internal delay blocks are not zero. Instead, they start with a random number associated with whatever was in memory at that time. I attempted to de-select the "Remove internal data zero initialization" option in the configuration parameters window to set their initial state to zero, however this option is greyed out.
Interestingly, if I change the initial state of the delay blocks to something non-zero, this creates initialization code which sets that value. This seems like an uneccessary limitation, as I cannot guarantee that the initial value of the variables is zero. Is there any work around to this which does not involve modifying the generated code?

回答 (1 件)

Jasvin
Jasvin 2023 年 3 月 9 日
編集済み: Jasvin 2023 年 3 月 9 日
Unfortunately, if the "Remove internal data zero initialization" option is greyed out in the Simulink configuration parameters window, it means that this option is not available for your current configuration. This may be because you are using a C++ class as the code interface package, as certain options may not be compatible with this type of setup.
And there doesn't seem to be any workaround for this other than modifying the generated code to either add an initialization step or explicitly initialize the delay block.
  1 件のコメント
SB
SB 2023 年 3 月 9 日
Thank you for your response. I am using a C++ class as the code interface package.
When I explicitly initialize the delay block to a non-zero value, that initialization becomes generated in the initialize() function. However, explicitly initializing the delay block to 0 becomes optimized out of the generated code. I am unsure how the latter is incompatible with a class interface.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSimulink Coder についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by