Products & Services Solutions Academia Support User Community Company

Learn more about Stateflow   

Stateflow Chart 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 chart with a single state, the parent of that state 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 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 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 appear as dashed rectangles. The activity of each parallel state is 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 has a label 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 active when ambiguity exists among 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 is 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. The occurrence of an event causes the chart to evaluate the status of states. An event broadcast can trigger a transition to occur or an action to execute. Event broadcasts occur in a top-down manner starting from the parent of the event in the chart hierarchy.

You create and modify events for Stateflow charts using the Model Explorer. Events have a property called scope that defines whether the event is:

Data

Data objects store numerical values for reference in the Stateflow chart but are nongraphical objects.

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 the substate that was most recently active. A history junction applies to the level of the hierarchy in which it appears, and it overrides any default transitions.

In the automatic transmission system, history indicates that when engaged becomes active, the substate that becomes active, first or second, is based on which substate was most recently active.

Actions

Actions take place as part of Stateflow chart execution. The action can execute 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 has a label with the condition action func1() and the transition action func2(). For discussions of how and why actions take place, see examples listed in Categories of Semantic Examples.

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

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 these sections:

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 acts as a decision point for two transition segments that complete at StateA1c.

Transitions connected to junctions are 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) 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 executes, and the default transition to the top junction occurs.

  2. The 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] evaluates first.

  3. If condition [c2] is true, action a2 executes and the transition to the bottom junction occurs. Because there are no outgoing transition segments from the bottom junction, chart execution is complete.

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

  5. If condition [c3] is true, condition action a3 executes and the transition from the middle to the bottom junction occurs. Because there are no outgoing transition segments from the bottom junction, chart execution is complete.

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

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

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