nxtprograms.com

Fun Projects for your LEGO® MINDSTORMS® NXT!

Home     Projects     Help     Contacts

Line Follower
Building: Intermediate
Program: Intermediate

Building and Programming Instructions


1

Note: Be sure to get the NXT brick facing the right way.  Note which side the USB port is on.


2

Note: Be sure the NXT brick is facing the right way.  It will only fit correctly this way.

 


3

The gray "skis" (which are on the front on the robot) allow the robot to slide from side to side so that it can turn accurately.


4


5

The light sensor is placed between the front "skis" and near the place where the skis contact the surface, so that the skis will push down lightly and smooth out any large wrinkles in the mat under the light sensor, to help it get a consistent reading.


6

The dark gray angled beams in the back will normally hover just above the surface, but they are there to provide stability in case the robot tries to tip backward (for example, when pressing the NXT buttons). 
See the tip on weight balance.


7


8


9

Use the shortest wire to connect the light sensor to port 3 on the NXT.  If you temporarily remove the two cross beams on the bottom of the robot, you can route the wire neatly under the robot as shown.


10

Use two wires to connect the left motor (the light sensor is near the front of the robot) to port B on the NXT and the right motor to port C on the NXT. 


 

Building Tip: Weight Balance

When building a robot that depends on sliding on something (the gray front "skis" in this project) to turn, it is important to consider the weight balance of the robot.  You want to have most of the robot's weight over the drive wheels, and just enough weight over the sliding part to keep the robot stable and avoid tipping over.  If too much weight is over the sliding part, the robot will struggle to turn, might get caught up and stall, or the drive wheels might start slipping.

This Line Follower robot is designed to have almost all of its weight over the drive wheels.  Using a small scale in the experiment shown below, we find that the robot weights a total of 622 grams, with 560 grams over the back wheels.  This means that the robot has 90% (560/622) of the weight over the wheels and only 10% of the weight over the front skis.  This is good for line following at slow speeds, but note that it could cause the robot to pop a wheelie if a lot of power was suddenly given to both wheels going forward (see the Dragster).

The robot's total weight is 622 grams 560 grams (90%) of the weight is over the wheels

 


Line Follower Programming

Two programs are provided for use with your Line Follower.

The program Line Follow uses a simple "zigzag" method of line following where the robot is constantly turning back and forth as it sees either side of the color boundary. 

The program Smooth Follow uses a somewhat more complex 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.  See the program comments for details.

Both programs start with instructions for the user to follow a procedure to calibrate the light sensor to the actual colors and lighting conditions that will be used.  Light sensor calibration is essential for accurate line following.  See the program comments for details.  If you use line following in your own programs, you could start with a similar procedure at the beginning of the program, or run the calibration steps as a separate program ahead of time.

 


How to Use the Line Follower

The gray skis and the light sensor are on the front end of the robot.  The NXT display should be right side up for reading when you are behind the robot.

At the start of both line following programs, the user is asked to place the robot over white and then black and press the orange button after each, in order to calibrate the light sensor to the actual light and dark colors that will be used for the line following.  This is important because the actual brightness seen by the light sensor will depend on many things, including the colors of the surface, how shiny the surface is, the exact height of the light sensor off of the surface, and the amount of other ("ambient") light in the room.

Step 1 of the light sensor calibration wants the sensor to be over all white. Step 2 of the light sensor calibration wants the sensor to be over all black. When following, the robot will try to align itself centered over the boundary between white and black (not centered over the black line), with black to the robot's left.

 

Challenges
  • The large black oval on the NXT Test Pad is interrupted by the "Start" on one end.  What do you think will happen to the robot when it gets there?  Does it depend on which direction around the track it is going?  Does the same thing happen every time?

  • Both of the line following programs provided use the motors at only about half power, in order to stay in control and not miss the turns in the test track.  If it goes too fast, the robot may "zig" or "zag" too far and go all the way to the other side of the black line and get confused.  Thinking about how the program works, can you explain why this confuses it?  What will happen afterwards?

  • The Smooth Follow program breaks the driving and steering into five different conditions, depending on how far away from the color boundary the robot thinks it is.  By adjusting what is done in each of these cases, can you get the robot to follow the line smoother or faster?  Try timing it once around the oval then see if you can improve on this time.

  • The standard NXT kit comes with only one light sensor, but if you have two light sensors, then it is possible to make a line following strategy that is faster, smoother, and 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 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 at the same time, and you will also want to calibrate both sensors at the beginning.

 

Home     Projects     Help     Contacts

 

Copyright © 2007-2008 by Dave Parker.  All rights reserved. 
All project designs, images, and programs are protected by copyright.  Please see the usage policy.