Commit 84c4f96b authored by Leigh Stoller's avatar Leigh Stoller

Add checks to make sure that a robot destination does not overlap a

current robot location (or its destination if the other robot is
moving or being dragged to a new location).

Oh, I should mention that to make the calculation easier, I am
treating robots as rectangles not circles. This is not ideal, but I
was not sure how to calculate overlap of two circles in a reasonably
efficient manner. I'm sure a high school student can tell me though.
parent 19815d69
......@@ -433,7 +433,7 @@ public class RoboTrack extends JApplet {
int rx2 = robbie.drag_x + ((DOT_RAD/2) + OBSTACLE_BUFFER);
int ry2 = robbie.drag_y + ((DOT_RAD/2) + OBSTACLE_BUFFER);
//System.out.println("CheckCollision: " + rx1 + "," +
//System.out.println("CheckforObstacles: " + rx1 + "," +
// ry1 + "," + rx2 + "," + ry2);
/*
......@@ -520,6 +520,78 @@ public class RoboTrack extends JApplet {
return false;
}
/*
* Check for collisions with other robots. We check all the
* robots that are dragging, and popup a dialog box if we find
* one. The user then has to fix it.
*
* XXX I am treating the robot as a square! Easier to calculate.
*/
public boolean CheckforCollisions() {
Enumeration robot_enum = robots.elements();
while (robot_enum.hasMoreElements()) {
Robot robbie = (Robot)robot_enum.nextElement();
if (!robbie.dragging)
continue;
int rx1 = robbie.drag_x - ((DOT_RAD/2) + OBSTACLE_BUFFER);
int ry1 = robbie.drag_y - ((DOT_RAD/2) + OBSTACLE_BUFFER);
int rx2 = robbie.drag_x + ((DOT_RAD/2) + OBSTACLE_BUFFER);
int ry2 = robbie.drag_y + ((DOT_RAD/2) + OBSTACLE_BUFFER);
//System.out.println("CheckCollision: " + rx1 + "," +
// ry1 + "," + rx2 + "," + ry2);
/*
* Check for overlap of this robot with each other robot.
* If the other robot is also moving or being dragged, then
* check its current/target destination, not its current
* location.
*/
for (int index = 0; index < robotmap.size(); index++) {
Robot mary = (Robot) robotmap.elementAt(index);
int ox1, oy1, ox2, oy2;
if (robbie == mary)
continue;
if (mary.gotdest) {
ox1 = ox2 = mary.dx;
oy1 = oy2 = mary.dy;
}
else if (mary.dragging) {
ox1 = ox2 = mary.drag_x;
oy1 = oy2 = mary.drag_y;
}
else {
ox1 = ox2 = mary.x;
oy1 = oy2 = mary.y;
}
ox1 -= (DOT_RAD/2);
oy1 -= (DOT_RAD/2);
ox2 += (DOT_RAD/2);
oy2 += (DOT_RAD/2);
//System.out.println(" " + ox1 + "," +
// oy1 + "," + ox2 + "," + oy2);
if (! (oy2 < ry1 ||
ry2 < oy1 ||
ox2 < rx1 ||
rx2 < ox1)) {
MyDialog("Collision",
robbie.pname + " is going to run into " +
mary.pname);
return true;
}
}
}
return false;
}
/*
* Draw a robot, which is either the real one, a destination one,
* or a shadow one being dragged around.
......@@ -1194,7 +1266,8 @@ public class RoboTrack extends JApplet {
* Check for collisions before submitting.
*/
if (! map.CheckforObstacles() &&
! map.CheckOutOfBounds())
! map.CheckforCollisions() &&
! map.CheckOutOfBounds())
SendInDestinations();
}
repaint();
......
......@@ -125,7 +125,10 @@ echo "<br>
orientation column in the table.
<li> A robot destination must not overlap an obstacle (shaded area,
blue border), and it must be fully within the field of view of at
least one camera (orange boxes).
least one camera (orange boxes).
<li> A robot destination must not overlap with another robot (its final
destination). Because of the sensors on the robots, the closest a
robot can come to anything else is 23cm.
</ul>
<blockquote><blockquote>\n";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment