子系统参数始终映射到 Matlab/Simulink Embedded Coder 生成的代码中的全局变量

发布于 2025-01-14 21:14:16 字数 1158 浏览 4 评论 0原文

对于简单的测试设置,我们希望从 Simulink 子系统生成 C 代码,该子系统在其块掩码中定义了多个配置参数。环境应能够修改这些参数和输入信号,并评估子系统代码表示的多个实例的输出信号。

预期结果

代码生成预计会在生成的代码,可以由环境实例化和初始化(参数、输入),并作为指针传递给生成的函数。函数应该只依赖于这些传递的参数。

然而,即使经过几个小时的调查,生成器仍然将配置参数放入一个全局变量中,该全局变量由生成的函数直接访问,这使得特定于实例的配置变得不可能。

尝试

只有以下模型设置在最新版本R2022a上被证明是有用的:

  • Optimization.Default参数行为 = 可调整
  • 代码生成< /代码>:
    • 代码接口.代码接口封装 = 可复用函数
    • 将根级 I/O 传递为 = 结构参考

结果

生成后的 子系统X的代码,所有结构的声明都可用;模型 M,输入 U 和输出 Y 通过引用函数传递,例如:

void X_step (RT_MODEL_X_T *const X_M, ExtU_X_T *X_U, ExtY_X_T *X_Y) {
  ... 
  ... X_P.X_someParam ...
  }

但是,参数结构仍然作为全局变量X_P。相反,参数结构也应该作为指针显式传递或作为模型结构的一部分传递,以便它可以用作X_P->someParam

有什么办法可以实现这种行为吗?

历史

几年前,在 2013b 版本中,这已经顺利运行: 模型结构包含一个名为 ModelData 的子结构,该子结构又包含 字段P_X_T defaultParam。这些参数作为模型结构的一部分传递给函数,因此可以特定于实例。这可以通过一些标准设置(没有存储类或其他复杂的配置)开箱即用。这个功能是被删除了还是只是被隐藏了?

For a simple test setup, we want to generate C code from a Simulink subsystem, which has several configuration parameters defined in its block mask. The environment shall be able to modify these parameters and the input signals, and to evaluate the output signals for several instances of the subsystem's code representation.

Expected Outcome

The code generation is expected to provide structure declarations for model, parameters, inputs, and outputs in the generated code, which can be instantiated and initialized (parameters, inputs) by the environment, and passed to the generated functions as pointers. Functions should only depend on these passed arguments.

However, even after several hours of investigation, the generator still puts the configuration parameters into one global variable, which is directly accessed by the generated functions, what makes instance-specific configuration impossible.

Attempts

Only the following Model Settings turned out as useful on the newest release R2022a:

  • Optimization.Default parameter behavior = Tunable
  • Code Generation:
    • Code Interface.Code Interface Packaging = Reusable function
    • Pass root level I/O as = Structure reference

Result

After generating code for subsystem X, declarations for all structures are available; model M, inputs U and outputs Y are passed by reference to the functions, for example:

void X_step (RT_MODEL_X_T *const X_M, ExtU_X_T *X_U, ExtY_X_T *X_Y) {
  ... 
  ... X_P.X_someParam ...
  }

However, the parameter structure is still accessed as a global variable X_P. Instead, the parameter structure should be also passed as a pointer either explicitly or as part of the model structure, so that it can be used as X_P->someParam.

Is there any way to achieve this behavior?

History

Years ago, in Release 2013b, this already worked smoothly:
The model structure contained a substructure called ModelData which in turn contained
the field P_X_T defaultParam. These parameters were passed to the functions as part of the model structure and thus could be made instance-specific. This worked out of the box with a few standard settings (no storage classes or other sophisticated configurations). Is this feature removed or just hidden?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文