CSCI 108 Lab 6

Description

In this lab you will implement line following. 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 the robot

You will need one or two light sensors for this lab. (While either option can work, I found that the two-sensor implementation stays on track much better than the one-sensor implementation.) These 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

A simple algorithm for two light sensors

The path your robot needs to follow will not be a straight line. Even if it were a straight line, following it would be tricky. (Lab 4 probably convinced you of this.) You will need to constantly monitor the light sensor(s) and make adjustments to the motors to keep the robot on track.

If you have two sensors, for example, you can continuously compare their readings. If the right light sensor is detecting brighter light than the left, it means that the robot has moved off the black line to the right and an adjustment needs to be made to the left. If the left light sensor is detecting brighter light, the robot has moved off the line to the left; an adjustment needs to be made to the right.

Brightness and darkness are subjective

How can you measure brightness and darkness? What we humans see as "bright" or "dark" can vary from person to person. Similarly, you have discovered that your sensors don't all perceive light in exactly the same way. Some sensors will provide light readings in the entire range of 0 to 255; others will have a smaller range. So comparing their readings directly won't necessarily be helpful. In class we had to think about how to adjust for these different ranges, while normalizing sensor readings so that they always fell in the range 0-100. This week you might find it valuable to use the normalizing function we discussed in class. This will allow you to easily compare the relative light/darkness detected by each of your sensors.

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.

Bumper sensing

The bumper sensing component of your program should monitor the left and right touch sensors on the front of your robot. If either of these is pressed, the robot should stop, wait for some short amount of time (a couple of seconds), and then start to move again.

Testing the vehicles

I have created an oval track using black tape on a white surface. All robots should be tested on that track. In addition, with just a minor modification, 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.

Requirements

You will need to demonstrate your program to me.

Please also turn in your program, both on paper and electronically.

This lab must be completed by Monday, October 27 at 10:00 PM.