Stateflow: What Is Stateflow Examples Extended Uses Semantics and Problems
Stateflow: What Is Stateflow Examples Extended Uses Semantics and Problems
Stateflow: What Is Stateflow Examples Extended Uses Semantics and Problems
What is Stateow?
A state machine design tool integrated within Simulink: Stateow produces Simulink blocks, fed with Simulink inputs and producing Simulink outputs, a Stateow block can execute Simulink blocks as actions,
Stateow Features
Several features are worth to be noticed: Stateow encompasses both Mealy and Moore machines: actions associated with both states and transitions, entry actions performed when entering a state, during actions, performed when remaining in the state, exit actions, performed when leaving the state, condition actions, performed before leaving the source state, transition actions, performed after leaving the source state but before entering the destination state.
1 0 1 2
1 0 1 0 5 10 15 20
Time offset: 0
Solution
2 1 0 1 2 1 0 1 0 5 10 15 20
Time offset: 0
edgeauto/autoedge
[x==1]/{y=1}
Pulse Generator
Scope autoedge
1
Scope
10
15
20
Pulse Generator
autoedge
Time offset: 0
Example:Monitoring Properties
Design a property observer that monitors the property: a signal doesnt change its value in two consecutive samples Typical bevaviour:
2 1 0 1 2 1
0 1 0 2 4 6 8 10
Time offset: 0
1 0 1 2 1
0 1 0 2 4 6 8 10
Time offset: 0
monitorauto/monitor
[x==0]/{y=0} onetrue [x==1] moretrue
failed
[x==0]/{y=1}
onefalse [x==0]
morefalse
[x==1]/{y=0}
Scope monitor
0
Scope1
10
monitor
Time offset: 0
More Examples
A very popular usage: Mode Automata A Stateow chart is used to trigger several controller modes A cooperative way of designing complex systems: teams begin to agree on shared variable names, then each team can independently design and validate its own mode.
FunctionCall Generator
function()
double
In1
Out1
double
Constant
up
Scope
f() function A A
double
1 Out1
up.mdl
1 In1
double
20
10
15
20
25
30
Time offset: 0
updown.mdl
up
FunctionCall Generator
function()
double
In1
Out1
double
Constant
down
Scope
f() function A A
double
1 Out1
down.mdl
1 In1
double
10
15
20
25
30
Time offset: 0
function() Out1
updown.mdl
up
down
FunctionCall Generator
function()
double
In1
Out1
double
Constant
up_down
Scope
f() function
1 z Unit Delay
upev downev
mode_control
function() In1 Out1
up 1 In1
In1
Switch
function() Out1
1 Out1
up down.mdl
down
[y<=5]/s=1
[y>=5]/s=0
. . . and tries it
10
15
20
25
30
Time offset: 0
It works. . .
Interest : Modular approach No redesign No complex wiring Drawbacks Unsafe features when activations are not exclusive
Semantics
Simple Stateow has a clear semantics. Semantic problems appear with parallel states : parallel simultaneous activities which interact and communicate. Several solutions: non determinism: seldom used because determinism is appealing, unique logical solution: (for instance Signal), unique constructive solution: (Esterel, SyncCharts), restriction to one-way interaction: interactions statically ordered ensuring uniqueness (Lustre/Scade, Simulink?), micro-step semantics: (StateCharts, Stateow)
Stateow Solution
Micro-step semantics: an interpretation algorithm based on several orderings (priorities) describes uniquely in which order actions take place. raises problems of cyclic behaviours which dont terminate. (What about Statecharts?)
back
sequentially for parallel states: graphical two dimension priority: states are searched from top to bottom and from left to right! This is an unsafe feature: rst, small variations in the drawing can result in different behaviours, parallelism is misleading (actually sequentiality). verify that the Stateow behaviour is independent of the ordering of parallel states.
Do not design your Stateow diagram based on the expected execution order of transitions. verify that there is at most one valid initial segment at a time outgoing an active state.
Transitions
A transition can be a complex ow graph made of segments joining connective junctions. Each segment can bear a complex label made of:
event [condition]{condition action}/transition action
Valid Transitions
Segments outgoing from a connective junctions are searched for validity according to several criteria, among which clock-wise, starting from a twelveo clock position. Cyclic ow diagrams are allowed leading to for and while diagrams (not available in Scade).
Valid Transitions
Segments outgoing from a connective junctions are searched for validity according to several criteria, among which clock-wise, starting from a twelveo clock position. Cyclic ow diagrams are allowed leading to for and while diagrams (not available in Scade). Cyclic diagrams can raise non-termination. Testing for validity of a transition implies executing condition actions found along the transition path (complex side effects).
When an active state has no valid output transition, its during action is performed and the state remains active.
Safety Checking
The majors points to check for safety: 1. check that the order into which parallel states are considered is irrelevant, 2. check that outgoing transitions from a state are exclusive, 3. check that when entering a super-state, there is always a valid default transition, 4. check the twelve oclock rule, 5. check the cyclic behaviour of connective junctions, 6. check the recursive behaviour due to event broadcasting. In all these aspects, guidelines are needed