Harvey Mudd College
Computer Science 154 - Robotics
Assignment H

Woody Hunt

David Ordal

Michael Dickerson


Code: wallfollow.c

Behavior-Based Control


The Rug Warrior has three bump sensors, two infrared emitters (left and right) and one sensor, shaft encoders for both motors, two photo sensors (left and right) and a microphone. The purpose of this lab is to program the Rug Warrior so that it has the behavior that it can roam the halls of a building using wall-following algorithms and so it can find its way back to where it came from when it is given a signal to turn around.


Part 1 - Testing the Waters

We started by hooking up the robot to a PC and downloading a few of the example programs to test the different sensors and motors. During our testing, we found a few things wrong with the robot that needed fixing.

First off, the infrared sensor was not seeing the same thing from both emitters. It seemed that the sensor was too sensitive and wasn’t working right. With a little bit more testing we found that the reason the sensor was behaving so mysteriously is that it was picking up the signal from the emitters before the signal left the robot. In other words the signal was going straight from the emitter to the sensor right next to it instead of leaving the robot, bouncing off something and then coming back to the sensor. We fixed this problem by cutting two pieces of cardboard, coloring them black and mounting them between the sensor and the emitters.

The next problem we found was that the robot wasn’t driving straight. This problem was fairly easily fixed by soldering variable resistors into each of the motor circuits. Then we could adjust the voltage that was being sent to each motor separately. We were able to use the variable resistors to tune the motors to operate under the same voltage so that the robot drives straight.


Part 2 - Wall Following

After we worked out all the kinks with the robots sensors and motors, we started writing the wall following algorithm. First we programmed the robot to respond to a loud sound. This let us start the program, unplug the cord and put the Rug Warrior on the ground before having it start to drive. Once on the ground, we could clap and have the robot start following the wall.

Here’s how our algorithm works: as long as the robot sees the wall on its right, it drives straight. While the wall is on its right, if it veers too close to the wall, it will pick this up and turn away, and if it veers too far away from the wall so that it no longer sees anything on its right, then it veers in to the right until it see the wall again.

When the robot sees objects on both the left and right (using infrared) this means that it is on the inside of a corner. It turns to the left until it only sees something on the right. This makes the robot turn left in the corner.

When the robot doesn’t see anything on either side (using infrared) this means that it is on the outside of a corner. First it drives straight for a second, so that it doesn’t turn too quickly in the corner of the wall. Then it turns to the right until it sees the wall on the right. This makes the robot turn right around the corner.

By following this behavior of driving straight and navigating corners, the robot can successfully drive and follow a wall. Just in case the robot doesn’t see an object and ran into it, we programmed the robot to use the bump sensors and if it bumps into anything during its journey, it moves away from that bump sensor and then it moves forward around whatever obstacle it ran into.


Part 3 - Returning Home

Once we got the robot to follow walls, we set it up to be able to notice a “landmark”, turn around and go back to where it came from and stop. The “landmark” that makes the robot turn around is a bright light. We used the photo sensors to detect the light. We also made the starting point of the robot a bright light so that it knows where to stop when it comes “home”.

So the full cycle of the robot is as follows: first we clap and the robot starts to follow the wall, keeping the wall on its right. When our friend sees a bright light, it spins until it sees the wall on its left. Then it uses the same wall following skills to navigate back in the opposite direction, keeping the wall on its left. When it sees the bright light where it started from, the robot stops because it is “home”.


Part 4 - Conclusion

We all had a lot of fun with the Rug Warrior. This was also all of our first time programming a robot so we had to overcome a learning curve before we were able to comfortably program this thing. Of course we ran into some difficulties, but nothing that we couldn’t handle.

This project was a definite success. We were able to get the robot to respond to light and sound and to follow walls fairly successfully. Overall, for our first robot programming experience I think everything went well. We all learned a lot, both about the hardware of the robot and how to write software to control it. We’re looking forward to the next assignment!