0% found this document useful (0 votes)
20 views27 pages

Chapter1d Train UML Example

The document outlines the design and specifications for a model train controller that can manage up to 8 trains on a single track, featuring controls for speed, inertia, and emergency stop functions. It includes a detailed breakdown of system commands, class diagrams, and the relationships between various components such as the console, transmitter, and receiver. The document emphasizes the importance of separating specification from programming to facilitate easier corrections and improvements.

Uploaded by

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

Chapter1d Train UML Example

The document outlines the design and specifications for a model train controller that can manage up to 8 trains on a single track, featuring controls for speed, inertia, and emergency stop functions. It includes a detailed breakdown of system commands, class diagrams, and the relationships between various components such as the console, transmitter, and receiver. The document emphasizes the importance of separating specification from programming to facilitate easier corrections and improvements.

Uploaded by

mprabhu24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Example: Model Train Controller

Purposes of example:
Follow a design through several levels of abstraction.
Gain experience with UML.

Text: Section 1.4


Model train setup

rcvr motor

power
supply
console

header address command ECC


Requirements
 Console controls up to 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.
 Ignore erroneous messages
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 wall powered
physical console comfortable for 2 hands; < 2
size/weight lbs.
Conceptual specification
 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.
Basic system commands
Command-name parameters

set-speed speed (positive/negative)

set-inertia inertia-value (non-negative)

estop none
Typical control sequence
:console :train_rcvr
set-inertia
set-speed

Time set-speed Receiver


always
“listening”
estop
Console always
monitoring
buttons/knobs set-speed
Message classes
command base class

set-speed set-inertia estop


value: unsigned-
value: integer
integer

 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.
Subsystem collaboration diagram
Shows relationship between console and receiver
(ignores role of track): interaction via commands

sequence message type


1..n: command

:console :receiver
System structure modeling
 Some classes define non-computer components.
 Denote by *name.
 Choose important systems at this point to show basic
roles and relationships.

Major subsystem roles


 Console:  Train:
 read state of front panel;  receive message;
 format messages;  interpret message;
 transmit messages.  control the train.
Console system class diagram
console
1 1
1 1 1 1

panel formatter transmitter

1 1 1
1
knobs* * = physical object sender*

 panel: describes analog knobs and interface hardware.


 formatter: turns knob settings into bit streams.
 transmitter: sends data on track.
Train system class diagram
train set

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

 receiver: digitizes signal from track.


 controller: interprets received commands and makes
control decisions.
 motor interface: generates signals required by motor.
Detailed specification
 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.
Train system analog 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


Motor
controlled by duty cycle +
pulse width V
modulation: -
Panel and motor interface classes
 panel class defines the controls.
 new-settings() function reads the controls.
 motor-interface class defines the motor speed/inertia,
held as state.

panel motor-interface
speed: integer
train-number() : integer inertia: integer
speed() : integer
inertia() : integer
estop() : boolean
new-settings()
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.
Transmitter and receiver classes
 transmitter class has one method for each type of message sent.
 receiver class provides methods to:
 detect a new message;
 determine its type;
 read its parameters (estop has no parameters).
transmitter receiver
current: command
send-speed(adrs: integer, new: boolean
speed: integer)
send-inertia(adrs: integer, read-cmd()
val: integer) new-cmd() : boolean
send-estop(adrs: integer) rcv-type(msg-type:
command)
rcv-speed(val: integer)
rcv-inertia(val:integer)
Formatter class
 Formatter class holds state for each train, setting for current
train.
 The operate() operation performs the basic formatting task.

formatter
current-train: integer
current-speed[ntrains]: integer
current-inertia[ntrains]:
unsigned-integer
current-estop[ntrains]: boolean
send-command()
panel-active() : boolean
operate()
Control input sequence diagram:sender*
:knobs* :panel :formatter :transmitter
change in read panel
change in change in speed/

control
train number inertia/estop

settings panel settings panel-active


read panel
send-command
panel settings send-speed,
send-inertia.
change in read panel send-estop
train panel settings
number
new-settings
set-knobs
Formatter operate() behavior
(in the formatter class)

update-panel()

panel-active() new train number


idle
send-command()
other
Formatter panel-active() behavior
(in the formatter class)

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

T
panel*:read-speed() current-speed = throttle
changed = true
current-speed != throttle F
... ...
Train controller class

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

operate()
issue-command()
Setting the speed
 Don’t want to change speed instantaneously.
 Controller should change speed gradually by sending
several commands.
Controller operate behavior

wait for a
command
from receiver
receive-command()
issue-command()
Sequence diagram for set-speed cmd.
:detector*

:receiver :controller :motor-interface :pulser*


new-cmd
cmd-type
rcv-speed set-speed set-pulse
set-pulse
set-pulse

set-pulse

set-pulse
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
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.

You might also like