© 2005 ecnu seiprinciples of embedded computing system design1 introduction zexample: model train...

36
© 2005 ECNU SEI Principles of Embedded Computing System Design 1 Introduction Example: model train controller.

Upload: prosper-benson

Post on 28-Dec-2015

248 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 1

Introduction

Example: model train controller.

Page 2: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 2

Purposes of example

Follow a design through several levels of abstraction.

Gain experience with UML.

Page 3: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 3

Model train setup (P.21)

console

powersupply

rcvr motor

ECCaddressheader command

Page 4: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 4

Requirements (P.22)

Console can control 8 trains on 1 track.

Throttle has at least 63 levels.Inertia control adjusts responsiveness

with at least 8 levels.Emergency stop button.Error detection scheme on messages.

Page 5: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 5

Requirements form

name model train controllerpurpose control speed of <= 8 model trainsinputs throttle, inertia, emergency stop,

train #outputs train control signalsfunctions set engine speed w. inertia;

emergency stopperformance can update train speed at least 10

times/secmanufacturing cost$50power 10w wall poweredphysicalsize/weight

console comfortable for 2 hands; < 2lbs.

Page 6: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 6

Conceptual specification (P.22)

Before we create a detailed specification, we will make an initial, simplified specification. Gives us practice in specification and

UML. Good idea in general to identify

potential problems before investing too much effort in detail.

Page 7: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 7

Basic system commands

command name parameters

set-speed speed(positive/negative)

set-inertia inertia-value (non-negative)

estop none

Page 8: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 8

Typical control sequence (P.23)

:console :train_rcvrset-inertiaset-speed

set-speed

set-speed

estop

Page 9: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 9

Message classes

command

set-inertia

value: unsigned-integer

set-speed

value: integer

estop

Page 10: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 10

Roles of message classes

Implemented message classes derived from message class. Attributes and operations will be filled in

for detailed specification.Implemented message classes

specify message type by their class. May have to add type as parameter to

data structure in implementation.

Page 11: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 11

Subsystem collaboration diagram (P.24)

Shows relationship between console and receiver (ignores role of track):

:console :receiver

1..n: command

Page 12: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 12

System structure modeling

Some classes define non-computer components. Denote by *name.

Choose important systems at this point to show basic relationships.

Page 13: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 13

Major subsystem roles (P.24)

Console: read state of front panel; format messages; transmit messages.

Train: receive message; interpret message; control the train.

Page 14: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 14

Console system classes

console

panel formatter transmitter

Knobs* sender*

1

1

1

11 1

1 1 1 1

Page 15: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 15

Console class roles

panel: describes analog knobs and interface hardware.

formatter: turns knob settings into bit streams.

transmitter: sends data on track.

Page 16: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 16

Train system classes

train set

train

receiver

controller

motorinterface

detector* pulser*

1 1..t 1

1

1 1

1 1

1

1

1 1

Page 17: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 17

Train class roles

receiver: digitizes signal from track.controller: interprets received

commands and makes control decisions.

motor interface: generates signals required by motor.

Page 18: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 18

Detailed specification (P.25)

We can now fill in the details of the conceptual specification: more classes; behaviors.

Sketching out the spec first helps us understand the basic relationships in the system.

Page 19: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 19

Train speed control (P.26)

Motor controlled by pulse width modulation:

V

+

-

dutycycle

v

t

Page 20: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 20

Console physical object classes

knobs*

train-knob: integerspeed-knob: integerinertia-knob: unsigned-

integeremergency-stop: boolean

set-knobs()

pulser*

pulse-width: unsigned-integer

direction: boolean

sender*

send-bit()

detector*

read-bit() : integer

Page 21: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 21

Panel and motor interface classes

panel

train-number() : integerspeed() : integerinertia() : integerestop() : booleannew-settings()

motor-interface

speed: integer

Page 22: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 22

Class descriptions

panel class defines the controls. new-settings() behavior reads the

controls.motor-interface class defines the

motor speed held as state.

Page 23: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 23

Transmitter and receiver classes (P.27)

transmitter

send-speed(adrs: integer, speed: integer)send-inertia(adrs: integer, val: integer)set-estop(adrs: integer)

receiver

current: commandnew: boolean

read-cmd()new-cmd() : booleanrcv-type(msg-type:

command)rcv-speed(val: integer)rcv-inertia(val:integer)

Page 24: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 24

Transmitter and receiver classes descriptions

transmitter class has one behavior for each type of message sent.

receiver function provides methods to: detect a new message; determine its type; read its parameters (estop has no

parameters).

Page 25: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 25

Formatter class

formatter

current-train: integercurrent-speed[ntrains]: integercurrent-inertia[ntrains]: unsigned-integercurrent-estop[ntrains]: boolean

send-command()panel-active() : booleanoperate()

Page 26: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 26

Formatter class description

Formatter class holds state for each train, setting for current train.

The operate() operation performs the basic formatting task.

Page 27: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 27

Control input cases

Use a soft panel to show current panel settings for each train.

Changing train number: must change soft panel settings to

reflect current train’s speed, etc.Controlling throttle/inertia/estop:

read panel, check for changes, perform command.

Page 28: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 28

Control input sequence diagram (P.28)

:knobs :panel :formatter :transmitter

chan

ge in

spe

ed/

iner

tia/

esto

pch

ange

intr

ain

num

ber

change incontrolsettings

read panelpanel settings panel-active

send-command

send-speed,send-inertia.send-estop

read panelpanel settings

read panelpanel settings

change intrain number

set-knobs new-settings

Page 29: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 29

Formatter operate behavior

idle

update-panel()

send-command()

panel-active()new train number

other

Page 30: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 30

Panel-active behavior (P.29)

panel*:read-train()current-train = train-knob

update-screenchanged = true

T

panel*:read-speed() current-speed = throttlechanged = true

T

F

...

F

...

Page 31: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 31

Controller class

controller

current-train: integercurrent-speed[ntrains]: integercurrent-direction[ntrains]: booleancurrent-inertia[ntrains]: unsigned-integer

operate()issue-command()

Page 32: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 32

Setting the speed

Don’t want to change speed instantaneously.

Controller should change speed gradually by sending several commands.

Page 33: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 33

Sequence diagram for set-speed command (P.30)

:receiver :controller :motor-interface :pulser*

new-cmd

cmd-type

rcv-speed set-speedset-pulse

set-pulse

set-pulse

set-pulse

set-pulse

Page 34: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 34

Controller operate behavior

issue-command()

receive-command()

wait for acommand

from receiver

Page 35: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 35

Refined command classes

command

type: 3-bitsaddress: 3-bitsparity: 1-bit

set-inertia

type=001value: 3-bits

set-speed

type=010value: 7-bits

estop

type=000

Page 36: © 2005 ECNU SEIPrinciples of Embedded Computing System Design1 Introduction zExample: model train controller

© 2005 ECNU SEI Principles of Embedded Computing System Design 36

Summary

Separate specification and programming. Small mistakes are easier to fix in the spec. Big mistakes in programming cost a lot of

time.You can’t completely separate

specification and architecture. Make a few tasteful assumptions.