Vered Gafni, 20051 The Design Language of Statecharts.

Post on 14-Dec-2015

220 views 0 download

Tags:

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

Vered Gafni, 2005 1

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).

Vered Gafni, 2005 3

   Transition Events

Syntax

S1 S2event[condition]/action,...

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

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

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

Vered Gafni, 2005 7

Example of Compound Transition

LowTmp

HighTmp

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

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

/furnace-on

Vered Gafni, 2005 8

Transition Connectors

S

T Q

C [B][A]

a

S T

Q

ba

[A]

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

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

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

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

Vered Gafni, 2005 13

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

on off

ACC

Car Motion ProcessSpeed Throttle

resumebutton

gas/brakespedals

masterswitch

commandlever

Engine

I

MD

RPM Gear

Vered Gafni, 2005 14

Automatic Cruise Control

ACC

Disabled

Enabled

Inactive

Active

engine-onengine-off

Operating

Suspended

start-acc

stop-acc

abort

resume

Vered Gafni, 2005 15

Operating

CommandMonitor

SpeedControl

GearControl

Vered Gafni, 2005 16

Maintain

Increase

Decrease

increase decreasemaintain

CommandMonitor/set_speed_cmd

tm(ns,1)/inc_cmd

tm(ns,1)/dec_cmd

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

Vered Gafni, 2005 18

Railroad Crossing Control

Controllertrain-in train-out

go,stop close,

open

Vered Gafni, 2005 19

Crossing Control: Sequential Design

Vered Gafni, 2005 20

Crossing Control: Parallel Design

Vered Gafni, 2005 21

Using Timeout

• Delay• Periodic activation• deadline

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

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

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

Vered Gafni, 2005 25

Synchronization Techniques I

R

S

P

A

B

T

a

b

c/;f f

Vered Gafni, 2005 26

Synchronization Techniques II

R

S

P

A

B

b

fc/tr!(K)

Q

g

a

C

[K]

U [not(K)]

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

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]

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

Vered Gafni, 2005 30

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

Vered Gafni, 2005 32

Vered Gafni, 2005 33

Vered Gafni, 2005 34

Vered Gafni, 2005 35

Vered Gafni, 2005 36

Vered Gafni, 2005 37

Vered Gafni, 2005 38

Vered Gafni, 2005 39

Vered Gafni, 2005 40