Vered Gafni, 20051 The Design Language of Statecharts.

40
Vered Gafni, 1 The Design Language of Statecharts

Transcript of Vered Gafni, 20051 The Design Language of Statecharts.

Page 1: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 1

The Design Language of Statecharts

Page 2: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 2

Simple Statechart

Finite State

Machine R

S

T

a

d

b

cR, S, T – States

a, b, c, d - Events

Arrows - State transitions

(source-less arrow denotes an initial state).

Page 3: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 3

   Transition Events

Syntax

S1 S2event[condition]/action,...

Page 4: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 4

Events

{a, b, c, .... } atomic events:

a or b a occurs or b occurs

a and b a occurs and b occurs

not(a) a does not occur

tm(a,t) t time-units after the occurrence of a

tr( C ) condition C becomes true

fs( C ) condition C becomes false

en(S) state S is entered

ex(S) state S is exited

Page 5: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 5

Conditions

A, B,.... atomic conditions:

A or B A is true or B is true

A and B A is true and B is true

not(A) A is false

in(S) True while the system is in state S

X=Y, X<Y,…. Boolean relations

Page 6: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 6

Actions

a,b,… atomic actions

tr!(C) make condition C True

fs!(C) make condition C False

wr!(V) write variable V

rd!(V) read variable V

atomic actions also considered event generation

Page 7: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 7

Example of Compound Transition

LowTmp

HighTmp

tr(tmp>(cmd+2))/furnace-off

tr(tmp<(cmd-2))/furnace-on

/furnace-on

Page 8: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 8

Transition Connectors

S

T Q

C [B][A]

a

S T

Q

ba

[A]

Page 9: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 9

L

Hvalve

Water-level sensor

ControllerValve command

ValveClosed

ValveOpen

C

[WaterLevel<H/OpenCmd]

[WaterLevel>=H]/CloseCmd

tr(WaterLeve)<=L)/OpenCmd

tr(WaterLevel>=H)/CloseCmd

Page 10: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 10

Sub-States: Sequential Refinement

• S is a super-state w.r.t {S1, S2, S3 }• Super-state transitions (priority)• History entrance (H* -deep history)

S

S1

S2

S3

a

d

b

c

T

m

nH

Page 11: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 11

Example of Sequential Refinement

Equivalence

up to priorities

done[B]/fs!(B)

A

Failure

done[A]\fs!(A)

B

C

fail/tr!(A)fail/tr!(B)

fail/tr!(C)

done[C]/fs!(C)

/fs!(A),fs!(B),fs!(C)

A

Failure

doneB

C fail

H

Page 12: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 12

Sub-states:Parallel Refinement

Events

broadcasting

S3.A

S1 S2

S3

S

S2.A

S1.A

S1.B

S1.C

S2.B

S3.B

a

b\m

c\tr!(C)

m

tm(m,3sec)

tr(C)

f

Page 13: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 13

דוגמא - בקר שיוט רכב Automatic Cruise Control

on off

ACC

Car Motion ProcessSpeed Throttle

resumebutton

gas/brakespedals

masterswitch

commandlever

Engine

I

MD

RPM Gear

Page 14: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 14

Automatic Cruise Control

ACC

Disabled

Enabled

Inactive

Active

engine-onengine-off

Operating

Suspended

start-acc

stop-acc

abort

resume

Page 15: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 15

Operating

CommandMonitor

SpeedControl

GearControl

Page 16: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 16

Maintain

Increase

Decrease

increase decreasemaintain

CommandMonitor/set_speed_cmd

tm(ns,1)/inc_cmd

tm(ns,1)/dec_cmd

Page 17: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 17

SpecialNormallow

drive

2 1tr(rpm<=3K) tr(rpm<=1K)/low

tr(rpm>1k)tr(rpm>3K)/driveDrive

[rpm<=1K]/low[rpm>3K]

[rpm<=3K and rpm>1K]

C

CommandMonitor

Page 18: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 18

Railroad Crossing Control

Controllertrain-in train-out

go,stop close,

open

Page 19: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 19

Crossing Control: Sequential Design

Page 20: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 20

Crossing Control: Parallel Design

Page 21: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 21

Using Timeout

• Delay• Periodic activation• deadline

Page 22: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 22

Timeout as Delay

• To activate the furnace open the oil valve, and after 3 seconds operate ignition

Idle

Ignition_

delay

Furnace

_Active

Activate/Open_oil_valve

tm(Activate,3sec)/Ignite

Page 23: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 23

Timeout for Periodic Activation

• Execute control loop at 10Hz rate

RTC

/tick

tm(tick,100mls)/tick

WaitTick

Control

Loop

tick

done

Page 24: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 24

Timeout as Deadline

• Whenever train enters XR, gate should be closed within 10 seconds; otherwise an alarm will be activated

WaitTrainTin/CloseGate

tm(en(Closing),10sec)/Alarm Closed

ClosingGateClosed

FailClosing

Page 25: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 25

Synchronization Techniques I

R

S

P

A

B

T

a

b

c/;f f

Page 26: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 26

Synchronization Techniques II

R

S

P

A

B

b

fc/tr!(K)

Q

g

a

C

[K]

U [not(K)]

Page 27: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 27

Synchronization Techniques III

V

n/tr!(K)m

WU

X

A

B

b

C

[K]

D

r[not(K)]

C

/fs!(K)

a

p

Page 28: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 28

Transition Functions

[K] true[K] where ‘true’ is an event that occurs at every time instant

A Ba/ x=F(); G(x)

C

[K]

Page 29: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 29

MagnumA Real-Time Design Tool

Provides for representation of 3 system views:

• What:

- the activities the system should do, and inter-activities data flow

• When:

- the timing and synchronization of activities activation and data transfer

• Where:

- in what subsystem the each activity should be implemented

Page 30: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 30

Page 31: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 31

Basic Components

A

A1

A2

A3

C

A2_1

A2_2

E1E2

E3

CC

u

v wq

e

f

h

r

x

s

Page 32: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 32

Page 33: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 33

Page 34: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 34

Page 35: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 35

Page 36: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 36

Page 37: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 37

Page 38: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 38

Page 39: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 39

Page 40: Vered Gafni, 20051 The Design Language of Statecharts.

Vered Gafni, 2005 40