documenting control problems with statecharts charles wallace michigan technological university...
TRANSCRIPT
Documenting Control Problems with Statecharts
Charles Wallace
Michigan Technological University
•Operator: autonomous agent (possibly human)•Controlled domain: manipulated by operator•Operator issues series of asynchronous commands•Software responds by guiding controlled domain toward desired state,
•ignoring commands that are not sensible or not safe in given context
Challenge for control problems: How to document controlled domain?(more accurately our model of the controlled domain)
Simplifying assumptions:•finite number of discrete, readily distinguishable states•state changes in discrete, atomic steps
Control problems*
*M. Jackson. Problem Frames. Addison Wesley, 2000.
clear, intuitive documentation technique-but many problems not nicely expressible in FSA terms
One serious challenge: vast number of possible statesOften possible to collapse states into equivalence classes
Monday
Tuesday
Wednesday
Thursday
Friday Saturday
Sunday
Weekday Weekend
Finite-state automata (FSAs)
Different states with some similar properties:can't capture their similarities in FSA terms
q1 q2 qn......
r
a aa n distinct a-transitions needed
Shortcomings of FSAs
Parallel composition of machines leads to state space explosion
q1 q2 q3a a r1 r2 r3
b b
q1r1 q2r1 q3r1
a a
q1r2 q2r2 q3r2
a a
q1r3 q2r3 q3r3
a a
b b b
b b b
Shortcomings of FSAs
Venn diagrams: good at representing set-theoretic properties(inclusion/exclusion, intersection, union,...)
A B
Graph diagrams: good at representing general relations
Higraphs: advantages of both- "blobs" can intersect, contain blobs, etc.- plus, blobs can be connected with arcs
A solution: Statecharts*
*D. Harel. On visual formalisms. Comm. ACM 31(5), 1988, 514--530.
Q
q1 q2 qn...... r
a
Statecharts can capture depth (common substructure)
The a-transition from Q defines the default behavior for q1..qn
The state qi overrides this behaviorq1 is specified as the default initial state for Q, via the arrow- thus, the a-transition from r leads to q1
qi ......
s
a
a
Statecharts can capture orthogonality (parallel composition)
Q||R
q1 q2 q3 r1 r2 r3a a b b
Q||R is partitioned into states Q and RStates in Q||R are essentially pairs (qi,ri)(if you’re in Q||R, you’re in both Q and R)
Q R
Q||R
q1 q2 q3 r1 r2 r3a/b a/c b c
From state (q1,r1), the a-transition in Q triggers a b-event,leading to state (q2,r2)
Note: this is different from Mealy or Moore automata ---in those formalisms, output only affects environment
Statecharts can capturebroadcast communication
State change in one substate can "trigger" state change in another
When entering a superstate, which substate(s) should be entered?Options:•Transition directly to substate•Resort to default initial state•Use of history pseudostate,
which remembers “most recently visited” substate
Shallow history state remembers one level of nestingfor deeper levels, defaults used
Deep history state remembers all levels of nesting
History pseudostates:allow “memory” within nested states
H*
H
History pseudostates: example
q11 q12
c
c
q1
q21 q22
c
c
q2
b b
Q
H*
r11 r12
c
c
r1
r21 r22
c
c
r2
b b
R
H
a
a
last visited state in R = r22 “shallow” history state H leads to r21
last visited state in Q = q22 “deep” history state H* leads to q22
Harel’s digital watch example
User input: four buttons “a”, “b”, “c”, “d”
Modes: time, alarm, hourly chime, stopwatch- User navigates using “a”
Date display: accessible from time mode via “d”
Time, alarm update: accessible via “c”, exit via “b”
Watch reverts to time display after two minutes
unless it’s in stopwatch mode
t-min min
update
chour sec
date day
c
c
c
c
time
date
alarm
chimestopwatch
t-min minc
up-alarm
hourc
c
b
c
d
d
a
a
a
a
cc b
2-min[not in(stopwatch)]
displays
reg onb
lap offd[in(on)] d b
zero
b b
d[in(off)]
stopwatch
disp run
H*
time
chimea
a
Focus on stopwatch state (NB: Earlier, this was a “black box”)Once started, stopwatch is either running/stopped,
and either in regular or “lap mode”If user navigates out of stopwatch and back,
watch resumes previous substates