Java Reference
In-Depth Information
and requests laser “L1” to scan the obstacles with the command:
The robot itself can provide services. For example, robot “R1” returns the
current position when the master submits the following command:
The interested reader might extend the robot's functionalities by imple-
menting more complex behaviours that combine the services of several
devices. For example, the robot might be able to follow the middle line of a
corridor autonomously maintaining the same distance from two parallel walls.
Class Robot represents the entire robot system as it encapsulates the robot's
components and offers a single point of access to the controller. It is in
charge of synchronizing the read and write operations on the robot's po-
sition and of dispatching the controller's commands to the appropriate
device. The structure of the robot system (type and position of each device)
would be conveniently defined in a configuration file that class Robot read at
the initialization phase. This functionality is not supported by the following
implementation and is left to the reader as an exercise.
public class Robot {
String name;
Position position; // absolute robot position
Environment environment; // reference to the environment
// representation used for simulating the interaction with
// the robot sensors
Platform platform; // reference to the platform device
ArrayList sensors # new ArrayList();
// list of installed sensors
public Robot(String name, double x, double y, double t,
Environment environment) {
this .name # name;
this .environment # environment;
position # new Position(x, y, Math.toRadians(t));
// configures the robot's devices. A better
// implementation would read this information from a
// configuration file
platform # new Platform("P1", this , environment);
sensors.add( new Laser("L1", this ,
new Position(20.0, 0.0, 0.0),
// The writeOut() method is invoked by the device when it
// has to communicate the result of a command's execution.
Search WWH ::

Custom Search