Main Content

Transition Between Operating Modes

一个过渡represents the passage of a reactive system from one operating mode to another. In a Stateflow®chart, a transition is a line with an arrowhead that typically connects two states. The资源transitio过渡的状态n begins and thedestinationtransitio过渡的状态n ends.

You can also create a transition path with more than one transition segment by using connective junctions. For example, you can create a transition path from a single source to multiple destinations or from multiple sources to a single destination. In this case, any intermediate transitions have a connective junction as a source or destination. For more information, see结合过渡和连接以创建分支路径

一个默认过渡is a special type of transition that has no source. In charts or states with exclusive (OR) decomposition and at least two substates, there must be a default transition path that is not guarded by a condition or triggered by an event. In the absence of history junctions, default transitions indicate the first substate to become active when the chart or superstate becomes active. For more information, seeUse Default Transitions to Specify Initial Substate Activityfor details.

For example, the states in this chart represent the operating modes of an air controller system with two fans. The transitions between the statesPowerOnandPowerOffrepresent the change of mode as the air controller system turns on and off. The default transition to the statePowerOff表示在模拟开始时图表醒来时系统关闭。同样,在美国FAN1andFAN2,在每个风扇打开和关闭时,取代之间的过渡表示模式的变化,默认过渡表明当超级巨星时,风扇已关闭PowerOnbecomes active. For more information on this example, seeModel Synchronous Subsystems by Using Parallelism

Chart that contains a hierarchy of exclusive and parallel states that represent the operating modes of an air controller system.

The parent of a transition is the lowest level state or chart that contains the source and destination of the transition. For instance, in the previous example,FAN1is the parent state of the transitions between the substatesfan1.onandFAN1.Off。相似地,FAN2is the parent state of the transitions between the substatesFAN2.OnandFAN2.Off。相反,国家之间过渡的父母PowerOnandPowerOff是图表本身。

创建过渡

You can add a transition to a new or existing destination.

  1. 指向源状态或交界处的边界。指针变为十字路口。

  2. Click and drag away from the destination. The Stateflow Editor provides graphical cues that allow you to add a junction or a state.

    带有图形提示的新过渡,用于添加交界处或状态。

  3. 选择新过渡的目的地:

    • 要在过渡结束时添加新状态,请单击矩形提示。

    • To add a new junction at the end of the transition, click the circular cue.

    • 要将过渡连接到现有状态或交界处,请将指针拖到所需的目的地。

  4. 输入过渡的标签,然后单击过渡。标签指定使过渡有效的条件和触发器以及在模拟过程中过渡执​​行的任何操作。有关更多信息,请参阅在过渡中定义动作

一个fter you create a transition, you can use the Stateflow Editor to change the shape, source, destination, or label of the transition:

  • 要重塑过渡,请单击并拖动过渡的中点。

  • 要更改源或目的地,请单击并拖动过渡的端点。

  • To edit the transition label, click the label text near the character position you want to edit. If your transition has an empty label, first select the transition.

  • 要移动过渡标签,请单击并拖动标签。

创建默认过渡

  1. 在对象调色板中,单击默认过渡图标

  2. On the chart canvas, click a side of the destination state or junction.

  3. Optionally, add a label for the default transition.

小费

The size of the endpoint of the default transition is proportional to the arrowhead size. See更改过渡箭头大小

在过渡中定义动作

过渡的标签指定事件或消息触发器以及使过渡有效的条件以及条件操作和过渡操作在模拟过程中执行的过渡操作。过渡标签具有这种通用格式:

trigger[condition]{condition_action}/{transition_action}

Each part of the label is optional and can appear on a separate line. For more information on how the chart uses labels to determine the validity of transitions, seeEvaluate Transitions

Event and Message Triggers

一个过渡label starts with the name of an event or message that triggers the transition. To specify multiple event or message triggers, use the logical OR (|) 操作员。

仅当图表接收指定事件的广播时,使用事件触发器的过渡才有效。使用消息触发器的过渡仅在消息队列中存在指定的消息时有效。有关更多信息,请参阅Synchronize Model Components by Broadcasting EventsandCommunicate with Stateflow Charts by Sending Messages

For example, in this chart, the transitions between statesPowerOffandPowerOnhave event triggers. These transitions are valid when the source state is active and the chart receives a broadcast of the input eventSWITCH

Transitions that are triggered by an event.

小费

You can use implicit events (such aschange,,,,enter, 或者exit)和时间逻辑操作员(例如,,,,,,,,before, 或者every) to trigger transitions. For more information, see通过使用隐式事件来控制图表行为andControl Chart Execution by Using Temporal Logic

Conditions

要在过渡标签中添加条件,请输入封闭在方括号中的布尔表达式([])。遵循以下指南以定义条件:

  • 条件表达必须是评估的布尔表达true(1) orfalse(0)。

  • 要结合多种布尔表达式,请使用逻辑和(&&) and OR (||)操作员。

  • To enter the condition expression on more than one line, use an ellipsis (...)。

  • 条件表达式可以调用图形功能ons, truth table functions, MATLAB®functions, or Simulink®functions that return a numeric value. However, the function must not modify any data values or cause the chart to change state.

  • Do not use assignment statements in condition expressions.

一个过渡with a condition is valid only when the specified expression is true. For example, in tis chart, the transitions between substatesOffandOn有比较图表输入值的条件tempto a threshold. These transitions are valid when the source state is active and the condition is true.

通过条件保护的过渡。

Condition Actions

The chart executes a condition action as soon as it determines that the transition is valid. To add a condition action, after the condition, enter one or more statements enclosed in braces ({})。To separate multiple statements, use a comma or a semicolon. Alternatively, you can enter each statement on a separate line. To enter a single statement on more than one line, use an ellipsis (...)。

If the transition is part of a transition path that consists of multiple segments, that chart executes the condition action before it evaluates any subsequent segments of the transition path. For example, this chart contains a transition path with two transition segments. When the chart receives a broadcast of the input eventSWITCH,无论第二个过渡段是否有效,图表都在第一个过渡段上执行条件操作。有关更多信息,请参阅通过使用条件动作来控制图表执行

Transition that contains a condition action.

Transition Actions

The chart executes a transition action when it determines that the entire transition path is valid. To add a transition action, after the condition action, enter a forward slash (/) followed by one or more statements enclosed in braces ({})。To separate multiple statements, use a comma or a semicolon. Alternatively, you can enter each statement on a separate line. To enter a single statement on more than one line, use an ellipsis (...)。

If the transition is part of a transition path that consists of multiple segments, that chart executes the transition action after it determines that there is a sequence of valid segments to a destination state or a terminal junction. For example, this chart contains a transition path with two transition segments. When the chart receives a broadcast of the input eventSWITCH,仅当第二个过渡段有效时,图表才能在第一个过渡段上执行过渡操作。有关更多信息,请参阅条件和过渡行动

Transition that contains a transition action.

Transition actions are not supported in standalone Stateflow charts in MATLAB.

小费

In charts that use C as the action language, you do not have to enclose transition actions in braces. In charts that use MATLAB as the action language, the syntax is automatically corrected if the braces are missing from the transition action. See一个uto Correction When Using MATLAB as the Action Language

更改过渡箭头大小

在过渡时调整箭头的大小:

  1. Right-click the transition.

  2. 选择一个rrowhead Size

  3. Choose an arrowhead size from the drop-down list.

另外,您可以同时调整多个过渡的箭头大小。

  1. 选择多个过渡。

  2. Right-click one of the selected transitions.

  3. 选择Format>一个rrowhead Size

  4. Choose an arrowhead size from the drop-down list.

Changing the arrowhead size on a transition also changes the arrowhead size of the other transitions with the same destination.

指定过渡的属性

The properties listed below enable you to specify how a transition interacts with the other components in your Stateflow chart. You can specify transition properties in theProperty Inspector,,,,the Model Explorer, or the Transition properties dialog box.

To use theProperty Inspector

  1. In theModeling标签,下Design Data, 选择Property Inspector

  2. In the Stateflow Editor, select the transition.

  3. In theProperty Inspector,编辑过渡属性。

To use the Model Explorer:

  1. In theModeling标签,下Design Data, 选择Model Explorer

  2. In the模型层次结构pane, select the parent state or chart for the transition.

  3. In theContentspane, select the transition.

  4. In the对话窗格,编辑过渡属性。

使用“过渡属性”对话框:

  1. 在状态流编辑器中,右键单击过渡。

  2. 选择Properties

  3. In the properties dialog box, edit the transition properties.

You can also specify transition properties programmatically by usingstateflow.transitionobjects. For more information about the Stateflow programmatic interface, seeOverview of the Stateflow API

Source

Source of the transition. This property is read-only and is not available in theProperty Inspector。当您单击源超链接时,状态流编辑器将过渡源带到前景。

Destination

Destination of the transition. This property is read-only and is not available in theProperty Inspector。When you click the destination hyperlink, the Stateflow Editor brings the transition destination to the foreground.

Parent

过渡的父母。此属性仅阅读,在Property Inspector。当您单击父超链接时,状态流编辑器将父级带到前景。

Execution order

Execution order for the transition. For more information, seeTransition Evaluation Order

Treat as variant transition

Whether the transition is a variant transition. For more information, see使用变体过渡生成代码

标签

The label for the transition. This property is not available in theProperty Inspector。有关更多信息,请参阅在过渡中定义动作

Description

Description of the transition.

Document link

Link to online documentation for the transition. You can enter a web URL address or a MATLAB command that displays documentation as an HTML file or as text in the MATLAB Command Window. When you click theDocument link超链接,状态流评估链接并显示文档。

也可以看看

Objects

Tools

Related Topics