在Stateflow中可以使用after函数进行计时,计数等操作。具体使用方法可以参考Stateflow的帮助文档:《Stateflow User Guide》。

1 事件计数

语法:

after(n,E)

n是一个正整数或计算结果为正整数值的表达式。E是事件(event)。

Returns true if the event E has occurred at least n times since the associated state became active. Otherwise, the operator returns false.

2 chart计数

语法:

after(n,tick)

n is a positive integer or an expression that evaluates to a positive integer value.

Returns true if the chart has woken up at least n times since the associated state became active. Otherwise, the operator returns false.

The implicit event tick is not supported when a Stateflow chart in a Simulink model has input events. For more information, see “Control Chart Behavior by Using Implicit Events” on page 11-23.

3 计时

语法:

after(n,sec)
after(n,msec)
after(n,usec)

n is a positive real number or an expression that evaluates to a positive real value.

Returns true if at least n units of time have elapsed since the associated state became active. Otherwise, the operator returns
false.

In charts in a Simulink model, specify time in seconds (sec), milliseconds (msec), or microseconds (usec).

In standalone charts in MATLAB, specify time in seconds (sec). The operator creates a MATLAB timer object that generates an implicit event to wake up the chart. MATLAB timer objects are limited to 1 millisecond precision. For more information, see “Events in Standalone Charts” on page 3-53.

案例1:

c的输出结果:

案例2:

c的输出结果:

 

 

 

 

备注:

  1. 仿真步长要小于计时时间的最小步长。
  2. Temporal conditions cannot be used in flow graphs.

参考文献:

《Stateflow User Guide》\rightarrowUse Actions in Charts\rightarrowControl Chart Execution by Using Temporal Logic

 

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐