Computer Science 014
LEGO Robot Engineering

Williams College
Winter 2007


Lab 5: Line Following
Due: 10:00 AM, Thursday, January 11, 2007


Today, you will teach your robot how to follow a (possibly curved) line. Using only light sensors, your robot will follow a path marked out as a black line on a white surface. With minor modifications, it should also follow a light-colored line on a dark surface.

In addition, your robot will need to follow the path politely. If it bumps into anything along the way (another robot, for example), it should wait a bit, allowing the other robot to move out of the way.

Preparing Your Robot

You will need one or two light sensors for this lab. (While either option can work, robots using the two-sensor implementation usually stay on track much better than those using the one-sensor implementation.) The light sensors should be mounted on the front of your robot, centered and pointing down toward the ground. You can put them close together, or you may separate them a little bit (so that they straddle the line, for example).

Implementing Line Following

Implementing the Complete Program

As described above, your robot should do line following, but it should do so politely. That is, the robot should wait a bit if it bumps into another robot, allowing the other one to move out of the way.

A nice way to go about implementing this is to think of each of these two behaviors separately. First, write a function that implements the line following behavior. Then write another function that implements bumper sensing behavior. Once those work properly, you can make modifications so that they work together.

Testing and Demonstration

In lab, you will find an oval track using black tape on a white surface and a figure eight track using black tape on a white surface. All robots should be tested on these tracks. In addition, with just a minor modification to your program, your robot should be able to follow a light-colored line on a dark surface. Make the necessary changes to your program, and test the robot on the track set out on the carpet in the lab. Demonstrate each of these behaviors and submit a printout of your program.