
Page 105
release();
// Turn around.
OnRev(OUT_C);
Wait(TURNAROUND_TIME);
}
Let's look at the simple parts first. The
grab()
and
release()
inline subroutines take care of the grabber arm. All they do is run the arm motor in one direction until the limit sensor is pressed.
Running the motor forward causes the arm to descend, the grabber to close, and the arm to lift again. Running the motor in reverse makes the arm descend, the grabber open, and the arm lift again.
The mechanics of the arm take care of everything, as I'll explain later in the chapter. All we have to do is wait for the arm to lift, which presses the switch when it's finished. You might have
noticed that the light sensor and the touch sensor are both attached to the same input. I'll talk about how this works later. For now, just be aware that it's necessary for
grab()
and
release()
to
move away from the touch sensor to use the light sensor.
The
calibrate()
subroutine examines the values coming from Minerva's light sensor. It computes an average value, which is stored in the variable
threshold
. The
retrieve()
subroutine uses this value to figure out if it's looking at an object that should be picked up. Specifically, it tests if the light sensor value is a little less than the original average:
until (SENSOR_3 < threshold - 3);
Calibrating the sensor in this way frees us from hard-coding a light sensor threshold value into Minerva's program. It also makes Minerva better able to deal with different lighting conditions.
The
retrieve()
subroutine is the heart of Minerva's program. It drives forward (by turning output C on) until it finds something dark to pick up. While it's driving forward, timer 0 is ticking
away, measuring how long it takes until something is found:
OnFwd(OUT_C);
ClearTimer(0);
until (SENSOR_3 < threshold - 3);
Once a dark object is found, Minerva moves forward a little farther to position the grabber over the object. She records the forward movement time for the return trip. Finally, Minerva turns off
output C to stop the robot's forward motion:
Wait(20); // Move up on it a little.
returnTime = Timer(0);
Off(OUT_C);
Having found something interesting, Minerva picks it up:
grab();
Page 106
Now she wants to turn around and return to her starting point. To turn around, she simply reverses the direction of output C for the duration given by
TURNAROUND_TIME
:
OnRev(OUT_C);
Wait(TURNAROUND_TIME);
Now she drives back to her starting point, using the
returnTime
value, which was saved earlier:
OnFwd(OUT_C);
ClearTimer(0);
until (Timer(0) >= returnTime);
Off(OUT_C);
Finally, the
retrieve()
subroutine drops the object that Minerva's carrying and turns around again:
Summary of Contents for MINDSTORMS Robots
Page 22: ...Page 18 The back tread wheels are anchored to the shafts with the 16t gears ...
Page 23: ...Page 19 Page 20 Next start building support for the drive motors ...
Page 26: ...Page 23 The touch sensors are attached only by the shaft that runs through them ...
Page 41: ...Page 41 ...
Page 43: ...Next build the support for the light sensor ...
Page 80: ...Page 85 Make sure the bump on the long pin is up against the 4u beam ...
Page 82: ......
Page 84: ...Page 89 ...
Page 85: ...Step 14 is similar to Step 11 take a deep breath and go slowly ...
Page 87: ...Page 91 ...
Page 88: ...Page 92 Make sure that the two sides are at the same angle They should mirror each other ...
Page 89: ...Page 93 Page 94 ...
Page 90: ...Structural Support Page 95 ...
Page 91: ...Idler Wheel Page 96 ...
Page 92: ...Page 97 Drive Motor ...
Page 93: ...While you re putting the motor in hold on to the worm gear so it doesn t slip off Page 98 ...
Page 94: ...Grabber Arm Motor ...
Page 95: ...Page 99 ...
Page 96: ...Page 100 RCX Attach the RCX on both sides as shown Page 101 ...
Page 158: ......
Page 159: ...Page 175 The 16t gears are nestled inside the tread wheels ...
Page 160: ...Page 176 ...
Page 161: ...Page 177 Attach the motors to output A and output C as shown Page 178 ...