【Stateflow入门】任务10.图表层次结构

Chart Hierarchy(图表层次结构)

Introduction

Using hierarchy allows you to group states with common properties or functionality and to avoid redundancy in your Stateflow chart. Consider the operation of a traffic light. Traffic lights typically have a normal operating mode—where the light cycles between red, yellow and green—and a fault mode, in which the light changes to blinking red. You previously modeled a system similar to this. It contained a Normal state and a Fault state, with some rules for when to transition between the two states.
(使用层次结构可以将具有通用财产或功能的状态分组,并避免状态流图中的冗余。考虑一下红绿灯的操作。红绿灯通常有一个正常运行模式,在该模式下,灯在红色、黄色和绿色之间循环,而在故障模式下,指示灯变为闪烁的红色。您之前对类似的系统进行了建模。它包含一个正常状态和一个故障状态,以及何时在这两个状态之间转换的一些规则。)
在这里插入图片描述
To implement a traffic light with fault detection, the behavior of the light in each mode needs to be defined. In the lesson on temporal logic, you already modeled a traffic light in normal operation. It had three states: Stop, PrepareToStop, and Go. Using hierarchy, these three states become substates of the Normal superstate.
(为了实现具有故障检测的红绿灯,需要定义每个模式下的灯的行为。在关于时间逻辑的课程中,您已经对正常操作中的红绿灯进行了建模。它有三种状态:Stop、PrepareToStop和Go。使用层次结构,这三个状态成为Normal超级状态的子状态。)
在这里插入图片描述
A blinking light requires two states: BlinkOn and BlinkOff. These can be created as substates of Fault.
(闪烁的灯需要两种状态:BlinkOn和BlinkOff。这些可以创建为Fault(故障)的子状态。)
在这里插入图片描述
With this structure, the transitions between the Normal and Fault states occur regardless of which substate is active. Note that the example above contains a default transition at each level of hierarchy. This is required for all hierarchical Stateflow charts.
(使用这种结构,无论哪个子状态处于活动状态,都会发生正常状态和故障状态之间的转换。请注意,上面的示例在层次结构的每个级别都包含一个默认转换。这对于所有分层状态流程图都是必需的。)

Click Next below to implement this hierarchical traffic light.
(单击下面的“下一步”以实现此分级红绿灯。)

Practice(实践)

The states for normal operation have been placed in the chart for you. To create hierarchy, a state must fully encompass one or more other states. (Use the left mouse button to click and drag the boundary of a state to resize it.)
(正常运行的状态已为您放置在图表中。要创建层次结构,一个状态必须完全包含一个或多个其他状态。(使用鼠标左键单击并拖动状态的边界以调整其大小。))
在这里插入图片描述
在这里插入图片描述

Task1(任务1)

Create a new state, Normal, and make it a superstate of Stop, PrepareToStop and Go. Be sure to fully encompass all states and transitions.
(创建一个新状态,Normal,并使其成为StopPrepareToStopGo的超级状态。请确保完全包含所有状态和转换。)

Add a default transition to the Normal state.
(将默认转换添加到Normal状态。)
在这里插入图片描述

Task2(任务2)

It is often useful to model hierarchy from the top down: add the general functionality first, then fill in the details.
(从上到下对层次结构进行建模通常很有用:首先添加一般功能,然后填充细节。)

Add a new state, Fault, to the model, at the same level of hierarchy as Normal.
(在与Normal相同的层次结构级别上,向模型中添加一个新状态Fault。)

Create transitions with the following conditions.(创建具有以下条件的过渡。)

Normal → Fault [fault == 1]
Fault → Normal [fault == 0]

The Symbol fault has already been defined for you.
符号fault已经为您定义。
在这里插入图片描述

Task3(任务3)

During a fault, the yellow and green lamps are always off, irrespective of the state of the red lamp.
(在故障期间,无论红灯的状态如何,黄色和绿色指示灯始终熄灭。)

Add the following state entry actions to Fault.
(将以下状态entry操作添加到Fault。)

yellow = 0;
green = 0;

在这里插入图片描述

Task4(任务4)

Stateflow automatically adds a default transition to the first state added at a given level of hierarchy.
(Stateflow会自动将默认转换添加到在给定层次结构级别添加的第一个状态。)

Add a new state within the boundaries of the Fault state. It will be created as a sub state with a default transition.
(在Fault状态的边界内添加一个新状态。它将被创建为具有默认转换的子状态。)

Name this state BlinkOn.(将此状态命名为BlinkOn。)
在这里插入图片描述

Task5(任务5)

Add another substate, BlinkOff, inside the Fault state. Add the following state entry actions to control the lights.
(在Fault状态内添加另一个子状态BlinkOff。添加以下状态entry操作以控制灯光。)

BlinkOn red = 1;
BlinkOff red = 0;
在这里插入图片描述

Task6(任务6)

Add transition in both directions between BlinkOn and BlinkOff. Use the temporal operator after to pause for 1 second in each before transitioning.
(在“BlinkOn”和“BlinkOff”之间的两个方向上添加过渡。在after,在每次转换之前暂停1秒。)
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/J_WangJiang/article/details/129808509
10.