Here's a short and informative tutorial to creating a Line following robot using "Fuzzy Logic". This is a lot simpler than most PID control Line Followers, and still a lot smoother than simple Switch (left-right) Line Followers.
Last Tuesday I gave a workshop at a group of 15 7-9 year olds at the school Wittering.nl. The kids already participated in the FLL and won places for the country final on February the 6th. The asked if I could help them in doing more with sensors, in their FLL robot.
So we did a workshop in building and programing the 5 minute robot from NXTprograms.com. we also added an Ultrasonic sensor to detect the end of the line (actually the wall of the playing field) in the Smartmove mission.
It was great fun and all groups build and programmed a good working robot, with the new color sensor, some even adapted the smooth line follow program to an old style lightsensor.
I have updated the original NXT 1.0 Line Follower project at nxtprograms.com to improve the original programs a bit and include a new "proportional" line following program. I also included some separate light sensor calibration utility programs and some discussion of light sensor calibration, as calibration can be a somewhat confusing concept in practice (although it can simplify your programs and/or make your robot more flexible once you understand how to use it).
Comparing this to my new NXT 2.0 Line Follower, with essentially the same program, I notice that it doesn't perform as well. I think this is for two reasons: NXT 2.0 programs execute faster than 1.x, and my older 1.x robot design is inferior. In particular, I think the light sensor is too far ahead of the wheels. Making the wheel track (left-to-right) wider would probably also help. Give a try at making it better!
I have received a lot of questions and requests about line following over the last several months. Some requests are coming from the FLL direction and such, but also users of the NXT 2.0 retail kit are wondering how to do line following using the color sensor, which is somewhat harder and/or less obvious than with the (NXT 1) light sensor.
So I have posted this NXT 2.0 Line Follower project to show two ways to do this (there are many other approaches), a simple "Two State" line follower program, and a more complex "Proportional" line follower, which is smoother and faster. In addition, the Proportional version includes an automatic calibration sequence, where the robot automatically scans the line and surface to determine the minimum and maximum expected brighness values on its own. These programs will only work on NXT 2.0. I will follow up with some info and programs for NXT 1.0 users later.
Although under good conditions you can make a simple line follower using the color sensor in "Color Sensor" mode (if it will read, say, black for the line and white for the floor), you are better off using the color sensor in "Light Sensor" mode, where you can get a numeric brightness value from the sensor, so both programs here use it this way. However, two complications arise out of using the color sensor in Light Sensor mode. First, "calibration" of the sensor (determining the minimum and maximum expected light values) is not supported by the NXT software. The Calibrate Sensors menu command as well as the Calibrate programming block only support the original (NXT 1) light sensor, not the color sensor in Light Sensor mode. So you need to do your own calibration. But then the other issue is that the "View" feature on the NXT brick menu (e.g. View Reflected Light) again only supports the old light sensor (the View Color choice will only show the color sensor in color sensor mode). So while doing your own calibration, you will also want to use your own program to do this.
To keep the simpler line following program as simple as possible, the "Two State" line follower program requires you to sample the light values and modify the program as necessary. As a tool to help with this and similar uses, I have posted an NXT 2.0 Light Meter project (you can use just the program if using it to calibrate another project such as the Line Follower). The Light Meter program also allows you to change the sensor option of red/green/blue/ambient, which makes it interesting for other experiments as well.
As a more advanced approach to the issue of calibration, the "Proportional" line follower also includes an automatic calibration sequence to eliminate the need to calibrate manually or modify the program based on the conditions.