Calibrating Light Sensors
One of the frustrations that beginners face in programming the light sensors is that the exact measurements from the light sensor changes depending on the environment. For example, you may develop a program one afternoon to make the robot stop at a black line, by stopping when the light sensor reading is less than '45'. However, when you run it later that night when the room is darker, the robot stops way before the black line is reached. And when you run it on a sunny morning, the robot cruises on past the black line. The same thing might happen when you program at home in your basement and then take it to a tournament in a well-lit auditorium.
What is happening here? When we program the NXT, we use a scale of 0 (darkest) to 100 (brightest) to describe output of the light sensor, but that number is really a percentage. The physical light sensor gives the robot brick a number from 0 to 1023. In a very brightly lit room, the darkest reading may be 478 (47%) and the brightest reading may be 891 (87%). In a very dimly lit room, the darkest reading may be 194 (19%) and the brightest reading might be 445 (43%). You can verify this by viewing the light sensor output on your NXT robot screen under different conditions. So if we use those raw percentage readings and set our threshold 45%, we may end up with a program that doesn't work in some environments.
Fortunately, NXT has a solution to this problem called "Calibration". Calibrating the robot to a particle environment means that from then on, 0% will represent the darkest reading found in that environment (usually black), and 100% will represent the brightest reading in that environment (usually white). Once you calibrate the robot, "0" will really mean 'black' and "100" will really mean "white". By creating such a wide range between white and black, you can safely set your threshold to "50" in your programs and not worry about it anymore.
The robot can be calibrated manually, but it is often convenient for FLL competitions to have a short program to calibrate your light sensor. I've attached the example "Calibrate.rbt" to this post. Basically, it just asks you to place the light sensor over a solid black region and take a reading, then place the light sensor over a solid white region to take a reading.
You can run this program at the table before the round begins and the calibration settings will hold for all of your subsequent programs, until you clear the settings or turn the robot off. My understanding is that in most FLL competitions, the judges do permit you to run a calibration routine before the round begins.
One other thing to note: although the calibration routine says it is for a light sensor in port 3, it will also set the calibration for any other light sensors you plug into other ports.
Good luck, and thanks to Meri & NASA for providing this great forum
Attachment: 1284065380_Calibrate.rbt (Size: 782 Kb | Hits: 878)