Page 58 - The Unofficial Guide to Lego Mindstorms Robots
P. 58
47
Use your own values for the thresholds of the light sensor watcher. The values shown in Figure 3-3 are calibrated to my
p articular light sensor and may not work with yours.
The timer is used in case Trusty happens to turn the wrong way. Suppose, for example, that he runs off the right side of the
black line twice in a row. The first time, he would turn left to find the line again. The second time, however, he would turn
right, aw ay from the line. The timer is used to limit this behavior. If Trusty is turning and the timer goes off, then Trusty
au tomatically turns back the other way. Figure 3-4 shows the timer watcher, which calls the same toggle subroutine if the
robot is still off the line.
You might be wondering why the timer counts for one half second. Why not three quarters of a second, or a full second?
Remember that the timer keeps Trusty from turning around completely.
The timer value is based on observation—if Trusty is turning toward the line, he will find it within a half second. If he is
turning away fr om the line, he can be pretty sure he's missed it after a half second. A line-follower with a different mechanical
d esign might need a different timer value.
Figure 3-4.
Details of Trusty's software
Figure 3 -4 also shows the toggle subroutine itself. All it do es is examine the value of the counter. If it's 0, then the robot is
set to turn left and the counter value is changed to 1. The nex t time toggle is called, the robot turns right and the counter
value is reset to 0. It's useful to have toggle as a subroutine because it is called from two places in Trusty's program.