Sunteți pe pagina 1din 3

Line Follower Programming

The LineFollow2 program is a basic "Two State" line follower that uses a simple "zig-zag"
method of line following where the robot is constantly turning back and forth as it sees
either side of the color boundary. The robot is always either turning left or right (the two
states), so it is never actually straight, even when the line is straight. Before using this
program, you will want to calibrate the sensor (on the robot) for the lighting conditions of
the surface and line you are using. To get the best start for the line following, start the
robot with the sensor near the right edge of the line.
The LineFollow5 program uses a somewhat more complex "Five State" method of following
the line with the goal of going straighter and smoother (and therefore faster). When the
robot gets aligned with the color boundary that it is trying to follow, the robot will go
straight as far as it can and make small corrections left and right to try to stay on the
boundary without zigzagging as much. You will want to calibrate the sensor (on the robot)
for the lighting conditions of the surface and line you are using. To get the best start for the
line following, start the robot with the sensor near the right edge of the line.

Calibrating the Light Sensor for Line Following


Before line following using either the LineFollow2 or LineFollow5 program, you should
"calibrate" the light sensor to the actual conditions expected. With the sensor mounted on
the robot where it will be used, and the robot placed over the actual line it will be following,
a calibration process takes two light sensor readings, one directly over the line (minimum =
darkest), and one over the surface away from the line (maximum = brightest). The NXT
will then adjust the numbers reported by the light sensor so that the minimum value
expected will be reported as 0 and the maximum as 100. The results of light sensor
calibration are remembered until you calibrate again, even after the NXT is turned off (the
results are stored in a data file in the NXT's memory), so you only need to calibrate once
each time your conditions change. Then you can run your robot as many times as you want
without needing to calibrate before each run.
Calibration allows you to make make certain assumptions about the light readings to
simplify the program. In particular, the LineFollow2 program assumes that the edge of the
line, over which the sensor sees about half line and half surface, will report a brightness of
50. The LineFollow5 program assumes a midpoint of 50 and also assumes that the total
range of light readings will range from 0 to 100.
Using the method built in to the NXT programming software:
To use the method built into the NXT software, connect your NXT to your PC (with the NXT
cable or Bluetooth), then select the Tools -> Calibrate Sensors menu item, choose Light
Sensor, and choose the correct sensor port (port 3 is used by these line following programs)
and press the Calibrate button. At this point the software will download a program called
"Calibrate" to the NXT and run it. Place your robot over the surface to be used and use the
screen prompts to sample the two values.

Taking the Two Calibration Readings

Using the built-in NXT Calibrate program, you will use the on-screen prompts to sample two light readings,
with the robot on the actual surface to be used and the sensor in its actual position on the robot.

When prompted to sample


the "Min" or "Black" reading,
position the sensor so that
the red spot is centered over
the line and then press the
Enter button on the NXT.

When prompted to sample the


"Max" or "White" reading,
position the sensor so that
the red spot is completely
over the surface away from
the line and press the Enter
button on the NXT.

When line following, the robot will try to


align itself centered over
the boundarybetween white and black (not
centered over the black line), with black to
the robot's left. Here the brightness seen
by the sensor is halfway between the
black/min and white/max readings.

Challenge:
The standard NXT kit comes with only one light sensor, but if you have two light sensors,
then it is possible to make a different kind of line following strategy that is sometimes more
reliable than with one sensor. If you have two light sensors, try placing them on either side
of the line so that they both see white when the robot is centered over the line. Then an
example "Five State" strategy would be:

1.

When both sensors see white (e.g. > 75%), go straight.

2.

When the left sensor sees some black (e.g. 25-75%), make a slight left turn.

3.

When the left sensor sees all black (e.g. < 25%), make a hard left turn.

4.

When the right sensor sees some black, make a slight right turn.

5.

When the right sensor sees all black, make a hard right turn.

The programming will be trickier because you must test both sensors. Note that for
calibration, you only need to calibrate one sensor, and this same calibration will be used for
the other sensor as well.

S-ar putea să vă placă și