return null;
}
public Collection<WayPoint> findRoute(Pose start, Pose destination)
throws DestinationUnreachableException {
Pose pose = start;
// Continue until we return a route or throw DestinationUnReachableException
for(;;) {
// If the current pose if close enough to the destination, go straight there
if (pose.distanceTo(destination.getLocation()) < MAX_DISTANCE) {
add(new WayPoint(destination));
return this;
} else {
Pose testPose = null;
// Generate random poses and apply tests to them
for(int i=0;i<MAX_ITERATIONS;i++) {
testPose = generatePose();
// The new Pose must not be more than MAX_DISTANCE away from current pose
if (testPose.distanceTo(pose.getLocation()) > MAX_DISTANCE) continue;
// The new pose must be at least MIN_GAIN closer to the destination
if (pose.distanceTo(destination.getLocation()) -
testPose.distanceTo(destination.getLocation()) < MIN_GAIN)
continue;
// We must be able to get a valid set of range readings from the new pose
float heading = testPose.getHeading();
boolean validReadings = true;
for(RangeReading r: readings) {
testPose.setHeading(heading + r.getAngle());
float range = map.range(testPose);
if (range > MAX_RANGE) {
validReadings = false;
break;
}
}
if (!validReadings) continue;
//Check there are no obstacles in the way
testPose.setHeading(testPose.angleTo(pose.getLocation()));
if (map.range(testPose) < testPose.distanceTo(pose.getLocation()))
continue;
testPose.setHeading(heading); // Restore heading
break; // We have a new way point
}
if (testPose == null) throw new DestinationUnreachableException();
else {
add(new WayPoint(testPose));