We are using sonar as the primary method of obstacle detection. The sonar is mounted at the top of the robot.

When the sonar works properly, our robot wanders around the libra complex without too many problems.

If we have bad batteries in the sonar, or the batteries run out, our robot wanders into walls.

Our wandering algorithm works on three basic conditions:

• If the robot is unexpectedly too close to an object, there is an emergency behavior (back away slowly).
• Otherwise, if the robot encounters an object, it will decide on a different direction to move in (turn).
• Otherwise, the robot will continue normally (go straight or look for interesting things).
The turning behavior and emergency behavior have two states - a normal state and an alternate state for when the normal state doesn't work. In the turning behavior, the alternate state is used to straighten the robot to move along the corridor if it is repeatedly running into a wall. In the emergency behavior, the robot turns in small increments looking for an escape route in case it is cornered.

At present, the wandering algorithm does not actively look for openings to go into or use any non-random method to determine which way to turn, but it is structured so as to make these things easy to implement.

Our wandering code can be found here. As we described above, the robot's wandering behavior has been broken up into several subcategories:

Top Level

• If there is an object that is too close to the robot in front, it backs away slowly.
• Otherwise, if there is an object that is "close" to the robot in front, it executes decision behavior (aligning with the wall).
• Otherwise, it executes normal behavior.
Normal Behavior
• Try to align with the left wall.
• If we can't align with the left wall, try to find the left wall.
• If we can't find the left wall, panic and go back to the main loop.
• Go forward until we see a wall ahead.
• Go slowly forward until we are within close range of the wall.
• If at any point the sonar acts up massively, we might not be following a real wall. Go back to the main loop (this will cause us to realign with the left wall, in case you were off-center).
To Find a Left Wall
• Check to make sure we are not too close to a front wall.
• If we are, exit. We'll have to turn instead of finding the wall.
• Move forward a bit.
• Look left.
• If there is a wall within hall width, we've found the left wall and we're done.
• Otherwise, look to the right to see if we might be too close to the right wall (hall width is not very precise).
• If we are, turn a bit left.
• If we moved forward more than 50 times without finding a wall, we are probably lost. Panic and exit.
• Go back up to checking to make sure we aren't too close to the front wall.
To Align To The Left Wall
• Check to make sure we are not too close to the left wall. If we are, move away from it.
• Check to make sure we are not too far from the left wall. If we are, move closer to it. (If this fails, we will just try to align from far away, because we are probably massively off alignment)
• Move forward. See how much the distance from the wall changes.
• If it did not change much, we are aligned properly.
• Otherwise, realign to left or right as appropriate and try again.
• If at any time the wall disappears, exit back to the main loop.
Notes:
• Sonar and servo values are hard-coded.
• Sonar averages several tries (currently 3).
• Sonar double-checks any value above a reasonable threshold.
• Sonar error- tolerance level is hard-coded.
• We don't play sounds. Yet. I think I know how to do it, though. We just need a command line sound playing program.