
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:
Содержание MINDSTORMS Robots
Страница 22: ...Page 18 The back tread wheels are anchored to the shafts with the 16t gears ...
Страница 23: ...Page 19 Page 20 Next start building support for the drive motors ...
Страница 25: ...Page 22 Attach the motor wires to output A and output C Next build the platform for the front bumpers ...
Страница 26: ...Page 23 The touch sensors are attached only by the shaft that runs through them ...
Страница 41: ...Page 41 ...
Страница 43: ...Next build the support for the light sensor ...
Страница 80: ...Page 85 Make sure the bump on the long pin is up against the 4u beam ...
Страница 82: ......
Страница 84: ...Page 89 ...
Страница 85: ...Step 14 is similar to Step 11 take a deep breath and go slowly ...
Страница 86: ...Page 90 Grabber Arm In Step 17 the half bushings go between the center block and the cams pear shaped pieces ...
Страница 87: ...Page 91 ...
Страница 88: ...Page 92 Make sure that the two sides are at the same angle They should mirror each other ...
Страница 89: ...Page 93 Page 94 ...
Страница 90: ...Structural Support Page 95 ...
Страница 91: ...Idler Wheel Page 96 ...
Страница 92: ...Page 97 Drive Motor ...
Страница 93: ...While you re putting the motor in hold on to the worm gear so it doesn t slip off Page 98 ...
Страница 94: ...Grabber Arm Motor ...
Страница 95: ...Page 99 ...
Страница 96: ...Page 100 RCX Attach the RCX on both sides as shown Page 101 ...
Страница 158: ......
Страница 159: ...Page 175 The 16t gears are nestled inside the tread wheels ...
Страница 160: ...Page 176 ...
Страница 161: ...Page 177 Attach the motors to output A and output C as shown Page 178 ...
Страница 162: ...The light sensor which is mounted on the bumper is attached to input 2 The touch sensor goes on input 1 Page 179 ...