To get hands-on experience using Stateflow® software, you will build a Stateflow chart in incremental steps that follow the basic workflow described in Model Reactive Systems in Stateflow.
You will build a Stateflow chart that maintains air temperature at 120 degrees in a physical plant. The Stateflow controller operates two fans. The first fan turns on if the air temperature rises above 120 degrees and the second fan provides additional cooling if the air temperature rises above 150 degrees. When completed, your Stateflow chart should look something like this:
As you can see from the title bar, the chart is called Air Controller and is part of a
Simulink® model called
sf_aircontrol. When you build this chart,
you will learn how to work with the following elements of state-transition
Exclusive (OR) states. States that represent mutually exclusive modes of operation. No two exclusive (OR) states can ever be active or execute at the same time. Exclusive (OR) states are represented graphically by a solid rectangle:
The Air Controller chart contains six exclusive (OR) states:
Parallel (AND) states. States that represent independent modes of operation. Two or more parallel (AND) states at the same hierarchical level can be active concurrently, although they execute in a serial fashion. Parallel (AND) states are represented graphically by a dashed rectangle with a number indicating execution order:
The Air Controller chart contains three parallel (AND) states:
Transitions. Graphical objects that link one state to another and specify a direction of flow. Transitions are represented by unidirectional arrows:
The Air Controller chart contains six transitions, from
Default transitions. Graphical objects that 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. Default transitions are represented by arrows with a closed tail:
The Air Controller chart contains default transitions:
At the chart level, the default transition indicates that the state
PowerOff is activated (wakes up) first when the chart is
FAN2 states, the default
transitions specify that the fans be powered off when the states are
The Air Controller chart contains two types of state actions:
en) action in the
PowerOff state. Entry actions are executed when the state
is entered (becomes active).
du) action in the
SpeedValue state. During actions are executed for a state
while it is active and no valid transition to another state is available.
Conditions. Boolean expressions that allow a transition to occur when the expression is true.
Conditions appear as labels for the transition, enclosed in square brackets
The Air Controller chart provides conditions on the transitions between
FAN1.Off, and between
FAN2.Off, based on the air
temperature of the physical plant at each time step.
Waking up a Stateflow chart
Causing transitions to occur from one state to another (optionally in conjunction with a condition)
The Air Controller chart contains two edge-triggered events:
CLOCK wakes up the Stateflow chart at each rising or falling edge of a square wave
SWITCH allows transitions to occur between
PowerOn at each rising or
falling edge of a pulse signal.