Java Reference
In-Depth Information
public class
Platform
extends
Device {
public
Platform(String name, Robot robot, Environment env){
super(name, robot,
new
Position(0.0, 0.0, 0.0), env);
this
.addPoint(20, 20);
this
.addPoint(30, 10);
this
.addPoint(30, -10);
this
.addPoint(20, -20);
this
.addPoint(-20, -20);
this
.addPoint(-20, 20);
}
}
Class
Laser
inherits from the abstract class
Device
and implements the
read()
method that measures the distance from the laser to the nearest
obstacles around the robot. The inner class
Measure
records a laser measure-
ment in terms of distance from a point on an obstacle's boundary and of
current direction of the rotary tower.
package
moro;
import
java.awt.*;
import
java.awt.geom.*;
import
java.util.*;
public class
Laser
extends
Device{
class
Measure {
double
distance
#
0.0; // distance from an obstacle
double
direction
#
0.0;
// current direction of the rotary tower
}
ArrayList scanMeasures
#
new
ArrayList();
// list of measures
int
range
#
100; // maximum range in centimetres
public
Laser(String name, Robot robot,
Position local, Environment env) {
super
(name, robot, local, env);
this
.addPoint(0, 2);
this
.addPoint(100, 2);
this
.addPoint(100, -2);
this
.addPoint(0, -2);
}
// if first is true, returns the distance to the first
// obstacle encountered otherwise it returns the distance
// to the nearest obstacle
public double
read(
boolean
first) {
Point2D centre
#
new
Point2D.Double(localPos.getX(),
localPos.getY());
Point2D front
#
new
Point2D.Double(localPos.getX()
!
range * Math.cos(localPos.getT()),
localPos.getY()
!
range *Math.sin(localPos.getT()));
// reads the robot's position
robot.readPosition(robotPos);
// centre's coordinates according to the robot position