Several species of insects use the sun to maintain a correct heading in an effort to navigate from place to place, even as they have to adjust their paths to avoid things like bug zappers and swatters. This first part of the project asks you to emulate -- at least at a coarse level -- this insect behavior by implementing two path-planning algorithms. Appropriately, the algorithms are named Bug1 and Bug2.
The algorithms
The idea behind both algorithms is that your
robot knows the direction in which it should head towards its goal, but it does
not know anything about the obstacles that lie between its current position and
that goal. The basic idea is to start heading toward the goal (since the correct
direction is known) and see whether any obstacles present themselves. We will
call the line between the robot's initial position and the goal the
S-line.
This problem is to implement these two "Bug" algorithms using the wall-following code you wrote in the second half of Lab Project A as a starting point. As with that assignment, you can assume that the obstacles will consist of walls meeting at right angles (an indoor application). The S-line need not, however, be parallel or perpendicular to the obstacles' walls. In implementing these algorithms, there are a number of choices to make, e.g., which direction to start heading around an encountered obstacle. It doesn't matter which direction you choose, as long as you stay consistent. Another choice that comes up in Bug1 is which direction to return to the perimeter point closest to the goal. In that case, it is preferable to return along the shorter path, (though either way is acceptable for this assignment).
Maps, Initial Points, and Destination Points
To test your
algorithms, there are two world maps available in /cs/cs154/as/B. For
the first map (bugmapA), the goal point is (2750,4200); for the second map
(bugmapB) it's (0,4700). For all of the test runs, the default starting point
will be used, i.e., the position the robot takes after the zr() call.
Both of these provided maps may be more complicated than you want to use on a
first run to debug your algorithms -- feel free to try it out on your own maps,
also.
Write-Up
In your write-up of this part of the assignment, be
sure to include the following
General Algorithms
Both algorithms, bug1 and bug2, is very similar and they are based on the wall-following altorithm that I have done for previous homework, and also, bug2 is based on the algorithm bug1.
bug1 algorithm: the bug will calculate an angle to the end point and toward to the end point to using the angle. If the bug hit the obstacle, the bug will remember this position and wall-follow entire obatacle. While the bug wall-following, the bug will calculate the shortest path the the end position. When the bug has returned the position at which it originally hit the obstacle, the bug will return the position where the length to the end position is shortes using wall-following behavior. When it reaches the shortest-length position, the bug will calculate the angle to the end position and toword to the end positon again.
bug2 algorithm: bug2 algorithm does exactly what this homework required.
Link to Sources
Problem that I encountered
Line #430 & #444 (similar code)
while(addUp(9, 13) < (ADD_UP_MAX - 1)) { vm(tv, 0, 0); }
while it is turing, it is
not checking shortest length and angle(s-line).
Even
though, I added up checking statements within these while loops, it is not quite
finding shortest or s-line and sometimes
it massed up whole program so I decided to get rid of them.
if ((addUp(5, 9) < ADD_UP_MAX - 5) && followAngle) turnTo(RIGHT, RIGHT_ANGLE * 2);
Examples
Both algorithms works quite well on any maps as following
Bug1
|
|
End Point (x, y) |
Picture |
|
|
(2750, 4200) Picture 1 Hitting to bottom of obstacle from left to right bugmapA |
|
(2750, 4200) Picture 2 bugmapA |
|
(2750, 4200) Picture 3 End bugmapA |
|
|
|
(-1500, 2000) Hitting to bottom of obstacle from right to left bugmapA |
|
|
|
(0, 4700) Hitting bottom of obstacle with right angle bugmapA |
|
|
|
(-1500, 2000) Hitting to right of obstacle |
|
(-1500, -2000) Hitting to right of obstacle |
|
|
|
(2750, 4200) Hitting to left of obstacle |
|
(1500, -2000) Hitting to left of obstacle |
|
|
|
(1500, -2000) Hitting to top of obstacle |
|
(-1500, 2000) Hitting to top of obstacle |
|
|
|
(2750, 4200) Picture 1 bugmapB |
|
(2750, 4200) Picture 2 End bugmapB |
|
|
|
(0, 4700) Picture 1 bugmapB |
|
|
|
(0, 4700) Picture 1 bugmapB |
|
(0, 4700) Picture 1 End bugmapB |
|
|
Bug2
End Point (x, y) |
Picture |
|
|
(2750, 4200) bugmapA |
|
(-1500, 2000) bugmapA |
|
(0, 4700) bugmapA |
|
|
|
(2750, 4200) bugmapB |
|
(0, 4700) Picture 1 bugmapB |
|
(0, 4700) Picture 2 (Final shot) bugmapB
|
|
|
|
(0, 4700) bugmapB with opposite |
|
|
|
|
|
|
|
This part of the assignment will be made into a third Nomad simulator assignment... .