140 likes | 264 Views
Documenting Control Problems with Statecharts. Charles Wallace Michigan Technological University wallace@mtu.edu. Control problems *. Operator: autonomous agent (possibly human) Controlled domain: manipulated by operator Operator issues series of asynchronous commands
E N D
Documenting Control Problems with Statecharts Charles Wallace Michigan Technological University wallace@mtu.edu
Control problems* • 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 *M. Jackson. Problem Frames. Addison Wesley, 2000.
Finite-state automata (FSAs) • clear, intuitive documentation technique • but many problems not nicely expressible in FSA terms • One serious challenge: vast number of possible states • Often possible to collapse states into equivalence classes Monday Wednesday Friday Saturday Sunday Tuesday Thursday Weekday Weekend
Shortcomings of FSAs Different states with some similar properties: can't capture their similarities in FSA terms ...... q1 q2 qn a a a n distinct a-transitions needed r
a a b b q1 q2 q3 r1 r2 r3 a a q1r1 q2r1 q3r1 b b b a a q1r2 q2r2 q3r2 b b b a a q1r3 q2r3 q3r3 Shortcomings of FSAs Parallel composition of machines leads to state space explosion
Venn diagrams: good at representing set-theoretic properties (inclusion/exclusion, intersection, union,...) A B Graph diagrams: good at representing general relations A solution: Statecharts* Higraphs: advantages of both - "blobs" can intersect, contain blobs, etc. - plus, blobs can be connected with arcs *D. Harel. On visual formalisms. Comm. ACM 31(5), 1988, 514--530.
Statecharts can capture depth (common substructure) a Q ...... ...... q1 q2 qi qn r a a s The a-transition from Q defines the default behavior for q1..qn The state qi overrides this behavior q1 is specified as the default initial state for Q, via the arrow - thus, the a-transition from r leads to q1
Statecharts can capture orthogonality (parallel composition) Q||R a a b b q1 q2 q3 r1 r2 r3 Q R Q||R is partitioned into states Q and R States in Q||R are essentially pairs (qi,ri) (if you’re in Q||R, you’re in both Q and R)
Statecharts can capturebroadcast communication State change in one substate can "trigger" state change in another Q||R a/b a/c b c q1 q2 q3 r1 r2 r3 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
History pseudostates:allow “memory” within nested states • 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 nesting • for deeper levels, defaults used • Deep history state remembers all levels of nesting H H*
History pseudostates: example a Q R q1 c r1 c q11 q12 r11 r12 H c c b b b b q2 c r2 c q21 q22 r21 r22 c H* c 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
update c displays t-min min c c hour sec b date c c d date day c d c time 2-min [not in(stopwatch)] a a alarm a c c b stopwatch chime hour t-min min a c c up-alarm
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 stopwatch time a zero H* d[in(off)] b b chime a reg on d[in(on)] d b b lap off disp run