Stateflow Chart Objects

All Stateflow objects are arranged in a hierarchy of objects. See Stateflow Hierarchy of Objects.

About Stateflow Objects

Stateflow charts consist of objects. Some of these objects are graphical, which you draw in a Stateflow chart. Others are nongraphical, which you reference textually in the chart.

The following sample chart displays some key graphical objects.

Stateflow Graphical Objects

States

A state describes a mode of an event-driven system. The activity or inactivity of the states dynamically changes based on events and conditions.

Every state has a parent. In a Stateflow chart consisting of a single state, that state's parent is the chart itself (also called the chart root). You can place states within other higher-level states. In the preceding figure, StateA1 is a child of StateA.

A state can have its activity history recorded in a history junction. History provides an efficient means of basing future activity on past activity. See History Junction.

States have labels that can specify actions executed in a sequence based upon action type. The action types are entry, during, exit, and on. See Actions.

Decomposition defines what a state can contain. You can use two types of states: exclusive (OR) and parallel (AND) states. Exclusive (OR) states are used to describe modes that are mutually exclusive. A chart or state that contains exclusive (OR) states has exclusive decomposition. The following transmission example has exclusive (OR) states.

An automatic transmission can be set to either neutral or engaged. In this example, either the neutral state or the engaged state is active at any one time. Both cannot be active at the same time.

A chart or state with parallel states has two or more states that can be active at the same time. A chart or state that contains parallel (AND) states has parallel decomposition.

Parallel (AND) states are displayed as dashed rectangles. The activity of each parallel state is essentially independent of other states. In the chart in Stateflow Graphical Objects, StateA2 has parallel (AND) state decomposition. Its states, StateA2a and StateA2b, are parallel (AND) states.

This Stateflow chart has parallel superstate decomposition.

In this example, the transmission, heating, and light systems are parallel subsystems in a car. They are active at the same time and are physically independent of each other. There are many other parallel components in a car, such as the braking and windshield wiper subsystems.

Transitions

A transition is a graphical object that, in most cases, links one object to another. One end of a transition is attached to a source object and the other end to a destination object. The source is where the transition begins and the destination is where the transition ends. A transition label describes the circumstances under which the system moves from one state to another. The occurrence of an event causes a transition to take place. In the chart in Stateflow Graphical Objects, the transition from StateA1 to StateA2 is labeled with the event transitionA1_A2 that triggers the transition to occur.

Consider again the automatic transmission system. clutch_engaged is the event required to trigger the transition from neutral to engaged.

Default Transitions

Default transitions specify which exclusive (OR) state is to be active when there is ambiguity between two or more exclusive (OR) states at the same level in the hierarchy.

For example, in the chart in Stateflow Graphical Objects, the default transition to StateA1 defines whether StateA1 or StateA2 should be active when State A becomes active. In this case, when StateA is active, by default StateA1 is also active.

In the following Lights subsystem, the default transition to the Lights.Off substate indicates that when the Lights superstate becomes active, the Off substate becomes active by default.

Events

Events drive the Stateflow chart execution but are nongraphical objects and are thus not represented directly in a Stateflow chart. You must define all events that affect the chart. The occurrence of an event causes the status of the states in the chart to be evaluated. The broadcast of an event can trigger a transition to occur or can trigger an action to be executed. Events are broadcast in a top-down manner starting from the event's parent in the hierarchy.

Events are created and modified using the Model Explorer, and they can exist at any level in the hierarchy. Events have properties such as a scope. The scope defines whether the event is

Data

Data objects are used to store numerical values for reference in the Stateflow chart. They are nongraphical objects and are thus not represented directly in a Stateflow chart.

You create and modify data objects for Stateflow charts in the Model Explorer. Data objects have a property called scope that defines whether the data object is

Conditions

A condition is a Boolean expression specifying that a transition occurs, given that the specified expression is true. In the component summary Stateflow chart, [condition1] represents a Boolean expression that must be true for the transition to occur.

In the automatic transmission system, the transition from first to second occurs if the transition condition [speed > threshold] is true.

History Junction

A history junction records the most recently active state of a chart or superstate.

If a superstate with exclusive (OR) decomposition has a history junction, the destination substate is defined to be the substate that was most recently visited. A history junction applies to the level of the hierarchy in which it appears, and it overrides any default transitions. In the component summary Stateflow chart, the history junction in StateA1 indicates that when a transition to StateA1 occurs, the substate that becomes active (StateA1a, StateA1b, or StateA1c) is based on which of those substates was most recently active.

In the automatic transmission system, history indicates that when clutch_engaged causes a transition from neutral to the engaged superstate, the substate that becomes active, either first or second, is based on which of those substates was most recently active.

Actions

Actions take place as part of Stateflow chart execution. The action can be executed either as part of a transition from one state to another or based on the activity status of a state.

Transitions ending in a state can have condition actions and transition actions, as shown in the following example:

In the chart in Stateflow Graphical Objects, the transition segment from StateA1b to the connective junction is labeled with the condition action func1() and the transition action func2(). The semantics of how and why actions take place are discussed throughout the examples listed in Semantic Examples.

States can have entry, during, exit, and on event_name actions. For example,

Action language defines the types of actions you can specify and their associated notations. An action can be a function call, the broadcast of an event, the assignment of a value to a variable, and so on.

A Stateflow chart supports both Mealy and Moore modeling paradigms for finite state machines. In the Mealy model, actions are associated with transitions, whereas in the Moore model, they are associated with states. For more information, see Building Mealy and Moore Charts.

A Stateflow chart supports state actions, transition actions, and condition actions. For more information, see the following:

Connective Junctions

Connective junctions are decision points in the system. A connective junction is a graphical object that simplifies Stateflow chart representations and facilitates generation of efficient code. Connective junctions provide alternative ways to represent desired system behavior. In the chart in Stateflow Chart Objects, the connective junction is used as a decision point for two transition segments that complete at StateA1c.

Transitions connected to junctions are called transition segments. Transitions, apart from default transitions, must go state to state. However, once the transition segments taken complete a state to state transition, the accumulation of the transition segments taken forms a complete transition.

The following example shows how connective junctions (displayed as small circles) are used to represent the flow of an if-else code structure shown in accompanying pseudocode.

This example executes as follows:

  1. If condition [c1] is true, condition action a1 is executed and the default transition to the top junction is taken.

  2. The Stateflow chart now considers which transition segment to take out of the top junction (it can take only one). Junctions with conditions have priority over junctions without conditions, so the transition with the condition [c2] is considered first.

  3. If condition [c2] is true, action a2 is executed and the transition segment to the bottom junction is taken. Because there are no outgoing transition segments from the bottom junction, the chart is finished executing.

  4. If condition [c2] is false, the empty transition segment on the right is taken (because it has no condition at all).

  5. If condition [c3] is true, condition action a3 is executed and the transition segment from the middle to the bottom junction is taken. Because there are no outgoing transition segments from the bottom junction, the chart is finished executing.

  6. If condition [c3] is false, execution is finished at the middle junction.

The above steps describe the execution of the example chart for connective junctions with Stateflow chart semantics. These semantics describe how objects in charts relate to each other during execution. See Stateflow Chart Semantics.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS