0% found this document useful (0 votes)
483 views36 pages

Example: Model Train Controller.: © 2005 ECNU SEI Principles of Embedded Computing System Design 1

model train controller

Uploaded by

UrsGuru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
483 views36 pages

Example: Model Train Controller.: © 2005 ECNU SEI Principles of Embedded Computing System Design 1

model train controller

Uploaded by

UrsGuru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

Introduction

 Example: model train controller.

© 2005 ECNU SEI Principles of Embedded Computing System Design 1


Purposes of example

 Follow a design through several levels of


abstraction.
 Gain experience with UML.

© 2005 ECNU SEI Principles of Embedded Computing System Design 2


Model train setup (P.21)

rcvr motor

power
supply
console

header address command ECC

© 2005 ECNU SEI Principles of Embedded Computing System Design 3


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.

© 2005 ECNU SEI Principles of Embedded Computing System Design 4


Requirements form
name model train controller
purpose control speed of <= 8 model trains
inputs throttle, inertia, emergency stop,
train #
outputs train control signals
functions set engine speed w. inertia;
emergency stop
performance can update train speed at least 10
times/sec
manufacturing cost$50
power 10w wall powered
physical console comfortable for 2 hands; < 2
size/weight lbs.

© 2005 ECNU SEI Principles of Embedded Computing System Design 5


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.

© 2005 ECNU SEI Principles of Embedded Computing System Design 6


Basic system commands

command name parameters

set-speed speed
(positive/negative)
set-inertia inertia-value (non-
negative)
estop none

© 2005 ECNU SEI Principles of Embedded Computing System Design 7


Typical control sequence (P.23)

:console :train_rcvr
set-inertia
set-speed

set-speed
estop

set-speed

© 2005 ECNU SEI Principles of Embedded Computing System Design 8


Message classes

command

set-speed set-inertia estop


value: unsigned-
value: integer
integer

© 2005 ECNU SEI Principles of Embedded Computing System Design 9


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.

© 2005 ECNU SEI Principles of Embedded Computing System Design 10


Subsystem collaboration
diagram (P.24)

Shows relationship between console and


receiver (ignores role of track):

1..n: command

:console :receiver

© 2005 ECNU SEI Principles of Embedded Computing System Design 11


System structure modeling

 Some classes define non-computer


components.
 Denote by *name.
 Choose important systems at this point to
show basic relationships.

© 2005 ECNU SEI Principles of Embedded Computing System Design 12


Major subsystem roles (P.24)

 Console:
 read state of front panel;
 format messages;
 transmit messages.
 Train:
 receive message;
 interpret message;
 control the train.

© 2005 ECNU SEI Principles of Embedded Computing System Design 13


Console system classes

console
1 1
1 1 1
1
panel formatter transmitter

1 1
1 1
Knobs* sender*

© 2005 ECNU SEI Principles of Embedded Computing System Design 14


Console class roles

 panel: describes analog knobs and


interface hardware.
 formatter: turns knob settings into bit
streams.
 transmitter: sends data on track.

© 2005 ECNU SEI Principles of Embedded Computing System Design 15


Train system classes
train set

1 1..t
1 1
train
1 1 motor
receiver interface
1 1
1 controller 1
1 1
detector* pulser*

© 2005 ECNU SEI Principles of Embedded Computing System Design 16


Train class roles

 receiver: digitizes signal from track.


 controller: interprets received commands
and makes control decisions.
 motor interface: generates signals
required by motor.

© 2005 ECNU SEI Principles of Embedded Computing System Design 17


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.

© 2005 ECNU SEI Principles of Embedded Computing System Design 18


Train speed control (P.26)

 Motor controlled by pulse width


modulation:

v duty
cycle +
V
t -

© 2005 ECNU SEI Principles of Embedded Computing System Design 19


Console physical object
classes

knobs* pulser*
train-knob: integer pulse-width: unsigned-
speed-knob: integer integer
inertia-knob: unsigned- direction: boolean
integer
emergency-stop: boolean
sender* detector*
set-knobs()
send-bit() read-bit() : integer

© 2005 ECNU SEI Principles of Embedded Computing System Design 20


Panel and motor interface
classes

panel motor-interface

speed: integer
train-number() : integer
speed() : integer
inertia() : integer
estop() : boolean
new-settings()

© 2005 ECNU SEI Principles of Embedded Computing System Design 21


Class descriptions

 panel class defines the controls.


 new-settings() behavior reads the controls.
 motor-interface class defines the motor
speed held as state.

© 2005 ECNU SEI Principles of Embedded Computing System Design 22


Transmitter and receiver
classes (P.27)

transmitter receiver
current: command
send-speed(adrs: integer, new: boolean
speed: integer)
send-inertia(adrs: integer, read-cmd()
val: integer) new-cmd() : boolean
set-estop(adrs: integer) rcv-type(msg-type:
command)
rcv-speed(val: integer)
rcv-inertia(val:integer)

© 2005 ECNU SEI Principles of Embedded Computing System Design 23


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

© 2005 ECNU SEI Principles of Embedded Computing System Design 24


Formatter class

formatter
current-train: integer
current-speed[ntrains]: integer
current-inertia[ntrains]:
unsigned-integer
current-estop[ntrains]: boolean
send-command()
panel-active() : boolean
operate()

© 2005 ECNU SEI Principles of Embedded Computing System Design 25


Formatter class description

 Formatter class holds state for each train,


setting for current train.
 The operate() operation performs the
basic formatting task.

© 2005 ECNU SEI Principles of Embedded Computing System Design 26


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.

© 2005 ECNU SEI Principles of Embedded Computing System Design 27


Control input sequence
diagram (P.28)
:knobs :panel :formatter :transmitter
change in read panel
change in change in speed/

control panel settings panel-active


train number inertia/estop

settings send-command
read
panel
panelsettings send-speed,
change in send-inertia.
train number read panel send-estop
panel settings

set-knobs new-settings

© 2005 ECNU SEI Principles of Embedded Computing System Design 28


Formatter operate behavior

update-panel()
new train number
panel-active()
idle
other send-command()

© 2005 ECNU SEI Principles of Embedded Computing System Design 29


Panel-active behavior (P.29)

T current-train = train-knob
panel*:read-train() update-screen
changed = true
F

T
panel*:read-speed() current-speed = throttle
changed = true
F
... ...
© 2005 ECNU SEI Principles of Embedded Computing System Design 30
Controller class

controller
current-train: integer
current-speed[ntrains]: integer
current-direction[ntrains]: boolean
current-inertia[ntrains]:
unsigned-integer

operate()
issue-command()

© 2005 ECNU SEI Principles of Embedded Computing System Design 31


Setting the speed

 Don’t want to change speed


instantaneously.
 Controller should change speed gradually
by sending several commands.

© 2005 ECNU SEI Principles of Embedded Computing System Design 32


Sequence diagram for set-
speed command (P.30)
:receiver :controller :motor-interface :pulser*
new-cmd
cmd-type
rcv-speed set-speed
set-pulse
set-pulse
set-pulse

set-pulse
set-pulse

© 2005 ECNU SEI Principles of Embedded Computing System Design 33


Controller operate behavior
wait for a
command
from receiver
receive-command()

issue-command()

© 2005 ECNU SEI Principles of Embedded Computing System Design 34


Refined command classes
command
type: 3-bits
address: 3-bits
parity: 1-bit

set-speed set-inertia estop


type=010 type=001
type=000
value: 7-bits value: 3-bits

© 2005 ECNU SEI Principles of Embedded Computing System Design 35


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.

© 2005 ECNU SEI Principles of Embedded Computing System Design 36

You might also like