【Stateflow】Chart初始化时访问data store memory警告

应用Stateflow的时候,涉及到Data Store Memory作为全局变量的时候的一个错误,记录下来。

1. 问题描述

变量xxx是用Data Store Memory在外层定义的全局变量,Stateflow状态图在初始默认转移中的转移动作为对其赋值:
在这里插入图片描述
编译运行后,报错如下:

This chart has ‘Execute At Initialization’ property set to true. Since the chart is awakened during initialization, accessing data store memory ‘xxx’ is not allowed as it may not have been computed by the up-stream blocks connected to the chart input.

意思是说:
由于设定了“Chart在初始化的时候就执行”,此时“xxx”全局变量可能不能被访问。

对于全局变量,经常写程序的应该了解,在提供方便的同事,也是bug易发、不受控的风险点。所以MATLAB对其做很详细的诊断。在本例中,因为默认转移是第一步执行的语句,很有可能此时全局变量没有定义,所以会诊断报错。

2. 解决办法

将Chart属性中的“Execute(enter) Chart At Initialization”选项关闭
在这里插入图片描述
选中上述选项的含义: 指定图在时间 0 处初始化其状态配置,而不是在输入事件第一次发生时初始化其状态配置,且在初始化时执行默认转移路径。

3. 问题解析

本例本质上是涉及到了初始化时图的执行。
默认情况下,图在首次唤醒时,它会执行默认转移路径。此时,图可以访问输入、写入输出和广播事件。
如果希望图从已知配置开始执行,可以启用 Execute (enter) Chart At Initialization 图属性。此时图在时间 t = 0 之前进行默认转移,此选项使 Stateflow 图的初始化与 Simulink的初始化同时进行。因此,图的默认转移路径会在模型初始化阶段执行。

By default, the first time a chart wakes up, it executes the default transition paths. At this time, the chart can access inputs, write to outputs, and broadcast events.
If you want your chart to begin executing from a known configuration, you can enable the Execute (enter) Chart At Initialization chart property. When you turn on this option, the state configuration of a chart initializes at time 0 instead of the first occurrence of an input event. The default transition paths of the chart execute during the model initialization phase at time 0, corresponding to the mdlInitializeConditions() (Simulink) phase for S-functions.

4. 借鉴

由于初始化阶段的瞬态性质,请不要在图的默认转移路径中执行以下这些会在初始化阶段执行的动作及其相关联的状态 entry 动作。请遵循以下指导原则:

  • 不要访问图输入数据,因为连接到图输入端口的模块可能尚未初始化其输出。
  • 不要从其他图中调用导出的图形函数,因为这些图可能尚未初始化。
  • 不要广播函数调用输出事件,因为触发子系统可能尚未初始化。

可以在 Configuration Parameters 对话框的 Diagnostics > Stateflow 窗格中控制对图输入数据进行无效访问的诊断操作级别。
Execute at initialization is ignored in Stateflow charts that do not contain states.

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CrazyRabbit0823

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值