Java Reference
In-Depth Information
The centralized event-scheduling model presented in the previous chapter
is not well suited to the simulation of the robot system. The robot system is
highly decentralized: the devices are autonomous and their interactions are
very limited.
There is no need for event synchronization among the device activities.
The robot devices share only the data structures that represent the position
of the robot in the environment. The event-based model provides features to
model complex finite state machines, whereas a very simple finite state
machine can describe the behaviour of every robot device.
Thus, we choose to adopt the process-based model that consists of imple-
menting every robot device as a thread (see Sidebar 10.1 for a description of
Java threads). The definition of class Device needs to be extended to imple-
ment the run() method of the Runnable interface. This method is common to
every concrete device and implements the finite state machines depicted in
Figure 10.13. Class Device defines two abstract methods that every subclass
must implement. Method executeCommand() initializes the device state in
order to execute a new command when the device is not running. Method
nextStep() performs a micro state transition that executes a new micro step.
This solution corresponds to the implementation of pattern Template
method described in Gamma et al . (1995). Figure 10.14 depicts the inter-
action diagram between class Device and class Laser . Method println(command)
specifies which command should be executed.
Platform
Device
wait()
println(command)
executeCommand()
return
repeat
wait(delay)
nextStep()
if running
return
if not running
Figure 10.14 The interaction diagram of the run() method
Search WWH ::




Custom Search