The DARK2 and POWER constants are determined using #defines; this means it's easy to fiddle with their values, and our program is easy to read.
The second task takes care of things when the light sensor leaves the black line. Whenever the robot leaves the line, the toggle() subroutine is called. toggle() starts the robot turning. Then
we wait a little while; if the robot is still not on the black line, we call toggle() again to turn back the other way:
task lightWatcher() {
while (true) {
if (SENSOR_2 > LIGHT2) {
toggle();
Wait(TIMEOUT);
if (SENSOR_2 > LIGHT2) {
toggle();
Wait(TIMEOUT ∗ 2);
}
}
}
}
The toggle() subroutine performs two important functions. First, it makes Trusty turn, based on the value of the state variable. Second, it updates the value of state; if it was RIGHT, it
Need help?
Do you have a question about the MINDSTORMS Robots and is the answer not in the manual?
Questions and answers