Page 60 - The Unofficial Guide to Lego Mindstorms Robots
P. 60
49
Figure 3-5 shows a hypothetical graph of the light sensor value, along wi th the times when the dark and bright commands will
be executed. Nothing happens until the sensor value enters either th e dark or bright value ranges.
Figure 3-5.
The sensor watcher
Remember that the RCX ru ns some tasks at the same time. If the dark commands and bright commands both take a while to
e xecute, it's possible they may overlap. If the light sensor reading gets into the bright range and abruptly drops back into the
dark range, the dark commands will start running while the bright commands are still in progress. You should be aware of this
possibility and structure your code to deal with it. In Trusty's program, the dark and bright commands both execute quickly s o
th ey won't overlap.
A mbient Light
You have to be careful with the light sensor; its value depends on all the light it receives. This includes the reflected light from
the red light that's part of the sensor as well as room light and sunlight.∗ In a line-following robot like Trusty, you really want
to measure only the reflected light. In this case, it's in your interests to block out the room lighting, sunlight, light from your
kid brother's flashlight, and anything else distracting. The light level that's present in a certain place is called the ambient light.
In a robot like Trusty, you might try surround the light sensor with dark bricks to block out the ambient light. This can improve
the accuracy of your sensor measurements. In this particular case, I didn't think it was necessary, but you might like to give it a
whirl.
∗ The light sensor is even sensitive to the infrared light that is produced from the IR port.