前页 后页

状态流建模

创建要呈现给Stateflow图的StateMachine图时,有很多选项。这些包括可以使用哪些元素和连接器,StateMachine的位置,可以在模型中定义代码的位置以及可以使用什么格式的代码。

国家机器安置

当创建要生成到Stateflow图的模型时,StateMachine图必须放置在SysML块下并具有子StateMachine元素,并且在该StateMachine元素下具有StateMachine图。

例如,在这种情况下,块“ Control”具有一个名为“ ControlStateMachine”的子StateMachine,该子StateMachine具有一个“ StateState”子图“ ControlStateMachine”:

注意,该块只能包含一个StateMachine图,而不能包含其他图。

定义代码

在StateMachine模型中有许多选项可用于放置脚本。这样做的关键考虑因素是-脚本的格式是什么,以及它可以放在哪里。

代码格式

When writing code any valid SysML code it will be translated to valid Stateflow code. The SysPhS specification defines the Modelica maths language as the 'standard' which is what Enterprise Architect accepts as code snippets in the StateMachine diagram, and translates these to the Matlab/Stateflow equivalent. For more details refer to section 10 of the OMG SysPhS specification.

代码放置

Stateflow在一个州内部并且符合UML规范,支持以下三个标准操作:

  • 条目
  • 出口
  • 做。
这些中的每一个都可以包含在“行为”下的国家操作中定义的代码。例如,以下是条目的代码段:

在转换上,使用代码的三个主要选择是:

  • 过渡卫队
  • 过渡效应
  • 触发。
例如,这是在Transition Guard中定义的条件语句:

使用块属性

For the code, the Block Properties such as constants and ports are able to be referenced within the script. In the case of the ports, the details being input into the Block are derived using the input port name and similarly values can be assigned to a variable of the same name as the  output port.

For example:

笔记

The following SysML State Machine features are not available in Stateflow:

  • Deep History state
  • History states that have a transition going out from it (ie an initial state) - and will be used on all default entries.
  • Fork/Join
  • Sync
  • Junction (only choice - junctions will be replaced with Choice where possible)
  • Entry/Exit points
  • References to other state machines. Stateflow can do child state machines but they can't be referenced again.
  • Only one State Machine per SysML Block.

学到更多