Java Reference
In-Depth Information
char grid[][] # new char [width/cellDim][height/cellDim];
public OccupancyMap() {
// initializes the occupancy map
for ( int i # 0; i < width/cellDim; i !! )
for ( int j # 0; j < height/cellDim; j !! )
grid[i][j] # 'n';
// the cell has not been explored yet
this .repaint(); // repaints the window
}
// draws the map
public void paintComponent(Graphics g) { }
// updates the map with the laser measures
public void drawLaserScan( double position[],
double measures[]) {
}
}
Class Device implements the slave side mechanisms of the pipe communi-
cation between the robot and the controller. Each concrete device invokes
the writeOut() method to send a response to the controller. The controller
initializes the communication with the robot by invoking the setOutput()
method of class Robot , which initializes the output member of each device.
public abstract class Device implements Runnable{
...
// the reference to the output pipe
protected PrintWriter output # null ;
public void setOutput(PrintWriter o)
{ this .output # output; }
// concrete devices invoke writeOut()to send a response
// to the controller
protected synchronized void writeOut(String data) {
if (output ! # null )
output.println(data);
else
System.out.println
(this.name ! " output not initialized");
}
}
Class Controller implements the exploration strategy, plans the robot
activities and send commands to the robot's devices. For the sake of
simplicity, this implementation defines a hard-coded sequence of com-
mands that guarantee an obstacle-free path. In every new position the robot
acquires laser measures and updates the map.
package moro;
import java.util.*;
Search WWH ::




Custom Search