example: model train controller - auburn universitynelson/courses/elec5260_6260...purposes of...
TRANSCRIPT
![Page 1: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/1.jpg)
Purposes of example:Follow a design through several levels of abstraction.
Gain experience with UML.
Text: Section 1.4
Example: Model Train Controller
![Page 2: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/2.jpg)
Model train setup
console
powersupply
rcvr motor
ECCaddressheader command
![Page 3: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/3.jpg)
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
![Page 4: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/4.jpg)
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 wall poweredphysicalsize/weight
console comfortable for 2 hands; < 2lbs.
![Page 5: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/5.jpg)
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.
![Page 6: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/6.jpg)
Basic system commands
Command-name parameters
set-speed speed (positive/negative)
set-inertia inertia-value (non-negative)
estop none
![Page 7: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/7.jpg)
Typical control sequence
:console :train_rcvrset-inertiaset-speed
set-speed
set-speed
estop
Time Receiveralways
“listening”Console always
monitoringbuttons/knobs
![Page 8: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/8.jpg)
Message classescommand
set-inertiavalue: unsigned-
integer
set-speed
value: integer
estop
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.
base class
![Page 9: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/9.jpg)
Subsystem collaboration diagramShows relationship between console and receiver (ignores role of track): interaction via commands
:console :receiver
1..n: commandmessage typesequence
![Page 10: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/10.jpg)
System structure modeling Some classes define non-computer components.Denote by *name.
Choose important systems at this point to show basic roles and relationships.
Console: read state of front panel; format messages; transmit messages.
Train: receive message; interpret message; control the train.
Major subsystem roles
![Page 11: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/11.jpg)
Console system class diagramconsole
panel formatter transmitter
knobs* sender*
1
1
1
11 1
1 1 1 1
panel: describes analog knobs and interface hardware. formatter: turns knob settings into bit streams. transmitter: sends data on track.
* = physical object
![Page 12: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/12.jpg)
Train system class diagramtrain set
trainreceiver
controller
motorinterface
detector* pulser*
1 1..t 11
1 1
1 1
11
1 1
receiver: digitizes signal from track. controller: interprets received commands and makes
control decisions. motor interface: generates signals required by motor.
![Page 13: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/13.jpg)
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.
![Page 14: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/14.jpg)
Train system analog physical object classes
knobs*train-knob: integerspeed-knob: integerinertia-knob: unsigned-
integeremergency-stop: boolean
pulser*
pulse-width: unsigned-integer
direction: boolean
sender*
send-bit()
detector*
read-bit() : integer
set_knobs()
Motor controlled by pulse width modulation:
V+
-
duty cycle
![Page 15: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/15.jpg)
Panel and motor interface classes
panel
train-number() : integerspeed() : integerinertia() : integerestop() : booleannew-settings()
motor-interfacespeed: integerinertia: integer
panel class defines the controls. new-settings() function reads the controls.
motor-interface class defines the motor speed/inertia, held as state.
![Page 16: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/16.jpg)
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 17: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/17.jpg)
Transmitter and receiver classes
transmitter
send-speed(adrs: integer,speed: integer)
send-inertia(adrs: integer,val: integer)
send-estop(adrs: integer)
receiver
current: commandnew: boolean
read-cmd()new-cmd() : booleanrcv-type(msg-type:
command)rcv-speed(val: integer)rcv-inertia(val:integer)
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).
![Page 18: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/18.jpg)
Formatter class
formatter
current-train: integercurrent-speed[ntrains]: integercurrent-inertia[ntrains]:
unsigned-integercurrent-estop[ntrains]: boolean
send-command()panel-active() : booleanoperate()
Formatter class holds state for each train, setting for current train.
The operate() operation performs the basic formatting task.
![Page 19: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/19.jpg)
Control input sequence diagram
:knobs* :panel :formatter :transmitter
chan
ge in
spee
d/in
ertia
/est
opch
ange
intra
in n
umbe
r
change incontrolsettings
read panel
panel settings panel-active
send-commandsend-speed,send-inertia.send-estop
read panel
panel settings
read panelpanel settings
change intrainnumber
set-knobsnew-settings
:sender*
![Page 20: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/20.jpg)
Formatter operate() behavior (in the formatter class)
idle
update-panel()
send-command()
panel-active() new train number
other
![Page 21: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/21.jpg)
Formatter panel-active() behavior (in the formatter class)
panel*:read-train()current-train = train-knob
update-screenchanged = true
T
panel*:read-speed() current-speed = throttlechanged = true
T
F
...F
...
current-train != train-knob
current-speed != throttle
![Page 22: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/22.jpg)
Train controller class
controller
current-train: integercurrent-speed[ntrains]: integercurrent-direction[ntrains]: booleancurrent-inertia[ntrains]:
unsigned-integer
operate()issue-command()
![Page 23: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/23.jpg)
Setting the speed Don’t want to change speed instantaneously. Controller should change speed gradually by sending
several commands.
![Page 24: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/24.jpg)
Controller operate behavior
issue-command()receive-command()
wait for acommand
from receiver
![Page 25: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/25.jpg)
Sequence diagram for set-speed cmd.
:receiver :controller :motor-interface :pulser*new-cmdcmd-typercv-speed set-speed set-pulse
set-pulse
set-pulse
set-pulse
set-pulse
:detector*
![Page 26: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/26.jpg)
Refined command classes
command
type: 3-bitsaddress: 3-bitsparity: 1-bit
set-inertiatype=001value: 3-bits
set-speedtype=010value: 7-bits
estop
type=000
![Page 27: Example: Model Train Controller - Auburn Universitynelson/courses/elec5260_6260...Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML](https://reader036.vdocuments.us/reader036/viewer/2022062603/5f74eceba17eae3e8a12f176/html5/thumbnails/27.jpg)
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.