pathPlanning.c 18 KB
Newer Older
1 2
/*
 * Copyright (c) 2005 University of Utah and the Flux Group.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * 
 * {{{EMULAB-LICENSE
 * 
 * This file is part of the Emulab network testbed software.
 * 
 * This file is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 * 
 * This file is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this file.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * }}}
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
 */

#include "config.h"

#include <math.h>
#include <float.h>
#include <assert.h>

#include "log.h"
#include "rmcd.h"
#include "rclip.h"
#include "obstacles.h"
#include "pilotConnection.h"
#include "pathPlanning.h"

#define PP_TOL 0.2

struct path_planning_data pp_data;

/**
 * Classify a position relative to an obstacle.
 *
 * @param rpoint The point to classify.
 * @param oc The obstacle to compare the point against.
 * @return The classification of the point.
 */
static pp_point_type_t pp_point_identify(struct robot_position *rpoint,
					 struct obstacle_config *oc);

/**
 * Compute the next corner point to go to.
 *
 * @param pp The plan to operate on.  The pp_obstacle field should hold the
 * obstacle whose corners should be considered.  On a successful return, the
 * pp_waypoint field will hold the chosen corner point.
 * @return True if a reachable point was found.
 */
static int pp_next_cornerpoint(struct path_plan *pp);

/**
 * @param pt1 The first position.
 * @param pt2 The second position.
 * @return The distance between the two points.
 */
static float pp_point_distance(struct robot_position *pt1,
			       struct robot_position *pt2);

/**
 * Check that a point is in the camera bounds and not in an obstacle.
 *
 * @param x The X coordinate of the point.
 * @param y The Y coordinate of the point.
 * @return True if the point is valid, false otherwise.
 */
static int pp_point_in_bounds(float x, float y)
{
    int lpc, retval = 0;
    struct rc_line rl;

    for (lpc = 0; lpc < pp_data.ppd_bounds_len; lpc++) {
	struct box *b = &pp_data.ppd_bounds[lpc];
	
	if (x >= b->x && y >= b->y &&
	    x < (b->x + b->width) &&
	    y < (b->y + b->height)) {
	    retval = 1;
	    break;
	}
    }

    if (retval) {
	rl.x0 = rl.x1 = x;
	rl.y0 = rl.y1 = y;
	if (ob_find_intersect(&rl, NULL) != NULL)
	    retval = 0;
    }
    
    return retval;
}

/**
 * Check that a point is not only in bounds, but also reachable by the robot.
 * A point is not reachable if it is out of bounds or if the robot would have
 * to travel through the center of the obstacle to reach it.
 *
 * @param pp A plan with the pp_actual_pos and pp_obstacle fields initialized.
 * The pp_obstacle field should contain the obstacle that must be navigated
 * around.
 * @param rp The point to check.
 * @return True if the point is reachable, false otherwise.
 */
static int pp_point_reachable(struct path_plan *pp, struct robot_position *rp)
{
    int retval = 0;

    assert(pp != NULL);
    assert(rp != NULL);

    if (pp_point_in_bounds(rp->x, rp->y)) {
	struct obstacle_config oc;
	struct rc_line rl;

	rl.x0 = pp->pp_actual_pos.x;
	rl.y0 = pp->pp_actual_pos.y;
	rl.x1 = rp->x;
	rl.y1 = rp->y;
	oc = pp->pp_obstacle;
	if (rc_compute_code(rl.x0, rl.y0, &oc) == 0) {
	    float xlen, ylen;

	    /*
	     * The point is inside the obstacle, shrink the size of the
	     * obstacle so the point is on the outside.
	     */
	    xlen = min(fabs(rl.x0 - pp->pp_obstacle.xmin),
		       fabs(rl.x0 - pp->pp_obstacle.xmax));
	    ylen = min(fabs(rl.y0 - pp->pp_obstacle.ymin),
		       fabs(rl.y0 - pp->pp_obstacle.ymax));
	    if (xlen < ylen) {
		if (fabs(rl.x0 - pp->pp_obstacle.xmin) <
		    fabs(rl.x0 - pp->pp_obstacle.xmax)) {
		    oc.xmin = rl.x0 + 0.01;
		    oc.xmax = pp->pp_obstacle.xmax;
		}
		else {
		    oc.xmin = pp->pp_obstacle.xmin;
		    oc.xmax = rl.x0 - 0.01;
		}
	    }
	    else {
		if (fabs(rl.y0 - pp->pp_obstacle.ymin) <
		    fabs(rl.y0 - pp->pp_obstacle.ymax)) {
		    oc.ymin = rl.y0 + 0.01;
		    oc.ymax = pp->pp_obstacle.ymax;
		}
		else {
		    oc.ymin = pp->pp_obstacle.ymin;
		    oc.ymax = rl.y0 - 0.01;
		}
	    }
	}
	
	if (debug > 1) {
165 166
	    info("reachable %.2f %.2f - %.2f %.2f %.2f %.2f\n",
		 rp->x, rp->y, oc.xmin, oc.ymin, oc.xmax, oc.ymax);
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
	}

	/*
	 * Check if the path to the point is completely outside the obstacle
	 * or intersects just at one of the corners.
	 */
	if ((rc_clip_line(&rl, &oc) == 0) ||
	    ((rl.x0 == rl.x1) && (rl.y0 == rl.y1))) {
	    retval = 1;
	}
    }

    return retval;
}

pp_plot_code_t pp_plot_waypoint(struct path_plan *pp)
{
    struct lnMinList dextra, sextra, intersections;
    float distance, cross, theta;
    pp_plot_code_t retval;
187
    int in_ob = 0;
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
    
    assert(pp != NULL);

    if (debug > 0) {
	info(" plot %.2f %.2f -> %.2f %.2f\n",
	     pp->pp_actual_pos.x, pp->pp_actual_pos.y,
	     pp->pp_goal_pos.x, pp->pp_goal_pos.y);
    }
    
    lnNewList(&dextra);
    lnNewList(&sextra);
    lnNewList(&intersections);
    
    retval = PPC_NO_WAYPOINT; /* if nothing else */
    
    /*
     * We have to iterate over one or more waypoints, so we start with the
     * Initial waypoint is the goal point.
     */
    pp->pp_waypoint = pp->pp_goal_pos;
    
    do {
	struct obstacle_node *on, *min_on = NULL;
211
	int goal_in_ob = 0, robot_ob = 0;
212 213 214 215 216 217 218 219 220 221 222 223 224
	float min_distance = FLT_MAX;

	/*
	 * The path doesn't cross enough of the obstacle box for us to worry
	 * about it so we dump it on the extra list so the intersect doesn't
	 * return it again.  XXX The number is partially a guess and
	 * empirically derived.
	 */
	cross = PP_MIN_OBSTACLE_CROSS;
	/*
	 * First we find all of the obstacles that intersect with this path
	 * and locate the minimum distance to an obstacle.
	 */
225 226
	if (debug)
	    info("wp %.2f %.2f\n", pp->pp_waypoint.x, pp->pp_waypoint.y);
227 228 229 230
	while ((on = ob_find_intersect2(&pp->pp_actual_pos,
					&pp->pp_waypoint,
					&distance,
					&cross)) != NULL) {
231 232 233 234 235 236 237
#if 0
	    info("intr %d %.2f %.2f\n",
		 on->on_natural.id,
		 distance,
		 cross);
#endif
	    
238 239
	    if (on->on_type == OBT_ROBOT)
		robot_ob = 1;
240 241 242 243 244 245 246 247 248 249

	    switch (pp_point_identify(&pp->pp_actual_pos, &on->on_expanded)) {
	    case PPT_INTERNAL:
	    case PPT_CORNERPOINT:
	    case PPT_OUTOFBOUNDS:
		in_ob = 1;
		break;
	    default:
		break;
	    }
250 251 252 253 254 255

	    if (rc_compute_code(pp->pp_goal_pos.x,
				pp->pp_goal_pos.y,
				&on->on_expanded) == 0) {
		goal_in_ob = 1;
	    }
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
	    
	    lnRemove(&on->on_link);
	    /* Record the intersection and */
	    lnAddTail(&intersections, &on->on_link);
	    /* ... check if this is the closest obstacle. */
	    if (distance < min_distance) {
		min_distance = distance;
		min_on = on;
	    }
	    
	    cross = PP_MIN_OBSTACLE_CROSS;
	}
	
	/* Check if there was an actual intersection. */
	if (min_on != NULL) {
	    if (debug > 1)
		info("closest %d\n", min_on->on_natural.id);
	    
	    pp->pp_flags |= PPF_HAS_OBSTACLE;
	    lnRemove(&min_on->on_link); // from the intersections list
	    lnAddTail(min_on->on_type == OBT_STATIC ? &sextra : &dextra,
		      &min_on->on_link);
	    pp->pp_obstacle = min_on->on_expanded;

	    /*
	     * Find all obstacles that the path intersects with and overlap the
	     * closest one.  The rest of the obstacles will be dealt with after
	     * we get around the closest one.
	     */
	    while ((on = (struct obstacle_node *)
		    lnRemHead(&intersections)) != NULL) {
		if (rc_rect_intersects(&pp->pp_obstacle, &on->on_expanded)) {
		    if (debug > 1)
			info("merging %d\n", on->on_natural.id);
		    
		    ob_merge_obstacles(&pp->pp_obstacle, &on->on_expanded);
		}
		lnAddTail(on->on_type == OBT_STATIC ? &sextra : &dextra,
			  &on->on_link);
	    }
	    
297
	    if (goal_in_ob) {
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
		struct robot_position rp;
		struct rc_line rl;
		float r;
		
		mtp_polar(&pp->pp_goal_pos, &pp->pp_actual_pos, &r, &theta);
		if (robot_ob)
		    theta += M_PI_2;
		mtp_cartesian(&pp->pp_goal_pos, r + 1000.0, theta, &rp);
		rl.x0 = pp->pp_goal_pos.x;
		rl.y0 = pp->pp_goal_pos.y;
		rl.x1 = rp.x;
		rl.y1 = rp.y;
		rc_clip_line(&rl, &pp->pp_obstacle);
		pp->pp_waypoint.x = rl.x1;
		pp->pp_waypoint.y = rl.y1;
		if (pp_point_distance(&pp->pp_waypoint,
				      &pp->pp_actual_pos) > 0.075) {
		    if (pp_point_reachable(pp, &pp->pp_waypoint))
			retval = PPC_WAYPOINT;
		    else if (pp_next_cornerpoint(pp))
			retval = PPC_WAYPOINT;
		    else
			retval = PPC_BLOCKED;
		}
		else {
		    retval = PPC_GOAL_IN_OBSTACLE;
		}
	    }
	    else if (pp_next_cornerpoint(pp)) {
		retval = PPC_WAYPOINT;
	    }
	    else {
		retval = PPC_BLOCKED;
	    }
	}

334 335 336 337
	/* Restore the active obstacle list.  XXX Shouldn't do this here. */
	lnPrependList(&ob_data.od_active, &dextra); // dynamics first
	lnAppendList(&ob_data.od_active, &sextra); // statics last
	
338 339 340 341 342 343
	/* Check for obstacles on the path to our new waypoint. */
	cross = PP_MIN_OBSTACLE_CROSS;
    } while ((retval == PPC_WAYPOINT) &&
	     (ob_find_intersect2(&pp->pp_actual_pos,
				 &pp->pp_waypoint,
				 &distance,
344 345 346
				 &cross) != NULL) &&
	     !in_ob);
    
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
    /* And make sure it is still sane. */
    assert(ob_data_invariant());
    
    /* restrict final waypoint to MAX_DISTANCE */
    mtp_polar(&pp->pp_actual_pos,
	      (retval == PPC_WAYPOINT) ? &pp->pp_waypoint : &pp->pp_goal_pos,
	      &distance,
	      &theta);
    if (distance > pp_data.ppd_max_distance) {
	mtp_cartesian(&pp->pp_actual_pos,
		      pp_data.ppd_max_distance,
		      theta,
		      &pp->pp_waypoint);
	retval = PPC_WAYPOINT;
    }

    switch (retval) {
    case PPC_WAYPOINT:
	info("set waypoint(%s) %.2f %.2f\n",
	     pp->pp_robot->hostname,
	     pp->pp_waypoint.x,
	     pp->pp_waypoint.y);
	break;
    case PPC_NO_WAYPOINT:
	info("set waypoint(%s) NONE\n", pp->pp_robot->hostname);
	break;
    case PPC_BLOCKED:
	info("set waypoint(%s) BLOCKED\n", pp->pp_robot->hostname);
	break;
    case PPC_GOAL_IN_OBSTACLE:
	info("set waypoint(%s) GOAL_IN_OBSTACLE\n", pp->pp_robot->hostname);
	break;
    }
    
    return retval;
}

pp_point_type_t pp_point_identify(struct robot_position *rpoint,
                                  struct obstacle_config *oc)
{
    /* determine the point type of rpoint */
    
    pp_point_type_t retval;
    robot_position this_cp;

    assert(rpoint != NULL);
    assert(oc != NULL);

    if (rc_compute_code(rpoint->x, rpoint->y, oc) == 0)
	retval = PPT_INTERNAL;
    else
	retval = PPT_DETACHED;
    
    /* is this a corner point? Check each corner of this obstacle */
    if (PP_TOL > pp_point_distance(
	rpoint, rc_corner(RCF_TOP|RCF_LEFT, &this_cp, oc))) {
	retval = PPT_CORNERPOINT;
    }
    else if (PP_TOL > pp_point_distance(
	rpoint, rc_corner(RCF_TOP|RCF_RIGHT, &this_cp, oc))) {
	retval = PPT_CORNERPOINT;
    }
    else if (PP_TOL > pp_point_distance(
	rpoint, rc_corner(RCF_BOTTOM|RCF_RIGHT, &this_cp, oc))) {
	retval = PPT_CORNERPOINT;
    }
    else if (PP_TOL > pp_point_distance(
	rpoint, rc_corner(RCF_BOTTOM|RCF_LEFT, &this_cp, oc))) {
	retval = PPT_CORNERPOINT;
    }
    
    /* is this point in bounds? */
    if (!(pp_point_in_bounds(rpoint->x, rpoint->y))) {
	retval = PPT_OUTOFBOUNDS;
	if (debug > 1)
	    info("pp_point_identify says this point is out of bounds\n");
    }
    
    /* debugging output */
    if (PPT_CORNERPOINT == retval) {
	if (debug > 1)
	    info("pp_point_identify says this point is a corner point\n");
    }

    return retval;
}

int pp_next_cornerpoint(struct path_plan *pp)
{
    int retval = 0;

    float bl_dist, br_dist, tl_dist, tr_dist;
    float bl_distg, br_distg, tl_distg, tr_distg;
    float min_dist = 0;

    robot_position cp_bl; /* bottom left corner point */
    robot_position cp_tl; /* top left corner point */
    robot_position cp_br; /* bottom right corner point */
    robot_position cp_tr; /* top right corner point */

    assert(pp != NULL);
    
    /* corner points of this obstacle */
    /* SWAP ymin/ymax because of y coord system is AFU */
    cp_bl.x = pp->pp_obstacle.xmin;
    cp_bl.y = pp->pp_obstacle.ymax;
    
    cp_tl.x = pp->pp_obstacle.xmin;
    cp_tl.y = pp->pp_obstacle.ymin;
    
    cp_br.x = pp->pp_obstacle.xmax;
    cp_br.y = pp->pp_obstacle.ymax;
    
    cp_tr.x = pp->pp_obstacle.xmax;
    cp_tr.y = pp->pp_obstacle.ymin;
    
    /* get the distances to each CP from the IP, and FP */
    bl_dist = pp_point_distance(&pp->pp_actual_pos, &cp_bl);
    bl_distg = pp_point_distance(&pp->pp_goal_pos, &cp_bl);
    
    tl_dist = pp_point_distance(&pp->pp_actual_pos, &cp_tl);
    tl_distg = pp_point_distance(&pp->pp_goal_pos, &cp_tl);
    
    br_dist = pp_point_distance(&pp->pp_actual_pos, &cp_br);
    br_distg = pp_point_distance(&pp->pp_goal_pos, &cp_br);
    
    tr_dist = pp_point_distance(&pp->pp_actual_pos, &cp_tr);
    tr_distg = pp_point_distance(&pp->pp_goal_pos, &cp_tr);
    
    switch (pp_point_identify(&pp->pp_actual_pos, &pp->pp_obstacle)) {
	
    case PPT_CORNERPOINT:
	/* actual point is already a corner point */
	/* proceed to the next CP nearest the FP */

	if (PP_TOL > bl_dist || PP_TOL > tr_dist) {
	    /* This is the bottom left or top right corner point */
	    /* the next corner point is BR or TL, find the closest */

	    if (debug > 1) {
		info("pp_next_corner_point: currently at bottom-left or "
		     "top-right, going to next corner point.\n");
	    }
	    
	    if (!pp_point_in_bounds(cp_br.x, cp_br.y) &&
		!pp_point_in_bounds(cp_tl.x, cp_tl.y)) {
		/* neither CP is in bounds -- CAN'T GO ANYWHERE */
		printf("pp_next_corner_point: No corner points are in bounds\n");
	    }
	    
	    if (pp_point_in_bounds(cp_br.x, cp_br.y) &&
		!pp_point_in_bounds(cp_tl.x, cp_tl.y)) {
		/* bottom right CP is in bounds, but top left is not */
		pp->pp_waypoint = cp_br; /* must go to bottom right */
		if (debug > 1)
		    info("pp_next_corner_point: must go to bottom right\n");
		retval = 1;
	    }
	    
	    if (!pp_point_in_bounds(cp_br.x, cp_br.y) &&
		pp_point_in_bounds(cp_tl.x, cp_tl.y)) {
		/* top left CP is in bounds, but bottom right is not */
		pp->pp_waypoint = cp_tl; /* must go to top left */
		if (debug > 1)
		    info("pp_next_corner_point: must go to top left\n");
		retval = 1;
	    }
	    
	    if (pp_point_in_bounds(cp_br.x, cp_br.y) &&
		pp_point_in_bounds(cp_tl.x, cp_tl.y)) {
		/* both CPs are in bounds
		 * go to the closest CP to the FP
		 */
		
		if (br_distg < tl_distg) {
		    /* bottom right is closer */
		    pp->pp_waypoint = cp_br;
		    if (debug > 1)
			info("pp_next_corner_point: going to bottom right\n");
		    retval = 1;
		}
		else {
		    /* top left is closer, or EQUAL */
		    pp->pp_waypoint = cp_tl;
		    if (debug > 1)
			info("pp_next_corner_point: going to top left\n");
		    retval = 1;
		}
	    }  
	}
	else {
	    /* This is the top left or bottom right corner point */
	    /* the next corner point is BL or TR, find the closest */

	    if (debug > 1) {
		info("pp_next_corner_point: currently at top left or bottom right, going to next corner point.\n");
	    }
	    
	    if (!pp_point_in_bounds(cp_bl.x, cp_bl.y) &&
		!pp_point_in_bounds(cp_tr.x, cp_tr.y)) {
		/* neither CP is in bounds -- CAN'T GO ANYWHERE */
		printf("pp_next_corner_point: No corner points are in bounds\n");
	    }
	    
	    if (pp_point_in_bounds(cp_bl.x, cp_bl.y) &&
		!pp_point_in_bounds(cp_tr.x, cp_tr.y)) {
		/* bottom left CP is in bounds, but top right is not */
		pp->pp_waypoint = cp_bl; /* must go to bottom left */
		if (debug > 1)
		    info("pp_next_corner_point: must go to bottom left\n");
		retval = 1;
	    }
	    
	    if (!pp_point_in_bounds(cp_bl.x, cp_bl.y) &&
		pp_point_in_bounds(cp_tr.x, cp_tr.y)) {
		/* top right CP is in bounds, but bottom left is not */
		pp->pp_waypoint = cp_tr; /* must go to top right */
		if (debug > 1)
		    info("pp_next_corner_point: must go to top right\n");
		retval = 1;
	    }
	    
	    if (pp_point_in_bounds(cp_bl.x, cp_bl.y) &&
		pp_point_in_bounds(cp_tr.x, cp_tr.y)) {
		/* both CPs are in bounds
		 * go to the closest CP to the FP
		 */
		
		if (bl_distg < tr_distg) {
		    /* bottom left is closer */
		    pp->pp_waypoint = cp_bl;
		    if (debug > 1)
			info("pp_next_corner_point: going to bottom left\n");
		    retval = 1;
		}
		else {
		    /* top right is closer, or EQUAL */
		    pp->pp_waypoint = cp_tr;
		    if (debug > 1)
			info("pp_next_corner_point: going to top right\n");
		    retval = 1;
		}
	    }
	}
	break;

    case PPT_DETACHED:
    case PPT_INTERNAL:
    case PPT_OUTOFBOUNDS:
	/* actual point is detached from obstacle boundary */
	/* proceed to the CP nearest the IP */
	/* CHANGE HERE TO ADD OPTIMIZATION */

	if (debug > 1) {
	    info("pp_next_corner_point: not currently at a corner point, going to nearest corner point in bounds.\n");
	}

	bl_dist += bl_distg;
	tl_dist += tl_distg;
	br_dist += br_distg;
	tr_dist += tr_distg;

	if (pp_point_reachable(pp, &cp_bl)) {
	    min_dist = bl_dist;
	    pp->pp_waypoint = cp_bl;
	    retval = 1;
	} else if (pp_point_reachable(pp, &cp_br)) {
	    min_dist = br_dist;
	    pp->pp_waypoint = cp_br;
	    retval = 1;
	} else if (pp_point_reachable(pp, &cp_tl)) {
	    min_dist = tl_dist;
	    pp->pp_waypoint = cp_tl;
	    retval = 1;
	} else if (pp_point_reachable(pp, &cp_tr)) {
	    min_dist = tr_dist;
	    pp->pp_waypoint = cp_tr;
	    retval = 1;
	} else {
	    /* no corner points are in bounds!! */
	    info("pp_next_corner_point: All corner points for this obstacle are out of bounds!\n");
	}
	
	/* find the minimum
	 * (don't need to look at bottom left
	 */
	
	if (br_dist < min_dist && pp_point_reachable(pp, &cp_br)) {
	    min_dist = br_dist;
	    pp->pp_waypoint = cp_br;
	}
	
	if (tl_dist < min_dist && pp_point_reachable(pp, &cp_tl)) {
	    min_dist = tl_dist;
	    pp->pp_waypoint = cp_tl;
	}
	
	if (tr_dist < min_dist && pp_point_reachable(pp, &cp_tr)) {
	    min_dist = tr_dist;
	    pp->pp_waypoint = cp_tr;
	}
	break;
    }

    return retval;
}

float pp_point_distance(struct robot_position *pt1,
			struct robot_position *pt2)
{
    assert(pt1 != NULL);
    assert(pt2 != NULL);
    
    /* simple radial distance between two points */
    return (hypotf(pt1->x - pt2->x, pt1->y - pt2->y));
}