| Using Stateflow | Search  Help Desk |
Designing the Carousel Stateflow Diagram
Overview
A Stateflow diagram is only as good as the up-front analysis and design work for the desired system behavior. Before you can create your Stateflow diagram, you need to interpret the verbal description of the system behavior and translate that description into Stateflow notation. For the purposes of this tutorial, some aspects of the operation are simplified.The Design Questions
Addressing these questions helps in creating a Stateflow diagram that is representative of the carousel system:What Are the States?
Begin by listing possible states in the carousel system. A good place to begin is by considering the physical components of the carousel. There are likely to be states associated in some way with some of the physical components.Audio
The audio components are a subset of the carousel system as a whole. If the audio system is enabled on the operator's console, music plays when the ride is in progress. In this tutorial, the substates of the audio component are not discussed in any detail.Video
The video components are a subset of the carousel system as a whole. If the video system is enabled on the operator's console, an image of a rotating platform is displayed on the operator's console. In this tutorial, the substates of the video component are not discussed in any detail.Ride
The platform movement is the ride. There is a state associated with the ride as a whole. In the simplest sense the ride is either in progress or not. There is one state, Ride, that consists of two substates,On, and Stopped.
Timer
A state for a timer is somewhat less obvious than the others. The duration of the ride is set by the operator. It is useful to define a separate state for the timer that will generate the event indicating when the ride is done. The timer is either counting or stopped. There are three states associated with the timer:Counting, Stopped, and Timer.
The Carousel System
The carousel system is either on or off. There are two states associated with the carousel at the system level:Power_on and Power_off.
What Is a State Decomposition?
The Stateflow diagram level of the hierarchy has exclusive (OR) decomposition and consists of two OR states:Power_on and Power_off.
The Power_on state has parallel (AND) decomposition and consists of these AND substates: Timer, Audio, Video, and Ride. When the Power_on state is active, the Timer, Audio, Video, and Ride states are active. They are essentially subsystems of the carousel system.
The Timer, Ride, Audio, and Video states have exclusive (OR) decomposition.
See "What Is a State Decomposition?" for more information.
What Are the State Labels?
Part of the process of defining each state is defining the state label. The state name is the part of the label that describes the state in some recognizable way. The state labels in the carousel consist of the name of the state. See the section titled "Labeling a State" for information on valid state labels.Will Junctions Simplify the Design?
The carousel system as described and designed does not have junctions. See the sections titled "Connective Junctions" and "History" for information on the use and notation for Connective and History junctions.What Are the Transitions?
In the carousel system, these are the transitions between OR states:Power_off
Power_on triggered by event Switch_on
Power_on
Power_off triggered by event Switch_off
Power_on.Ride.On
Power_on.Ride.Stopped triggered by any event when the condition [Speed > Max_speed] is true
Power_on.Ride.On
Power_on.Ride.Stopped triggered by event Emergency_stop
Power_on.Ride.On
Power_on.Ride.Stopped triggered by event Ride_done
Power_on.Ride.Stopped
Power_on.Ride.On triggered by event Start_button
Power_on.Timer.Stopped
Power_on.Timer.Counting triggered by event Start_button
Power_on.Timer.Counting
Power_on.Timer.Stopped triggered by any event when the condition [Time > Duration] is true. The event Ride_done is broadcast as a transition action.
Are There Default Transitions?
These are the default transitions in the example:Power_off substate is the default state to become active upon a transition to the carousel Stateflow diagram.
Power_on.Ride.Stopped substate is the default state to become active upon a transition to the Ride superstate.
Power_on.Timer.Stopped substate is the default state to become active upon a transition to the Timer superstate.
Are There Events?
These events are defined:Ride_done, Switch_on, Switch_off, Start_button, and Emergency_stop.
See the sections titled "Defining Events" for more information on events.
Is There Data?
The carousel system has these data objects:Time, Speed, Duration, and Max_speed.
See the section titled "Defining Data" for more information on data.