
}
task heartbeatWatcher () {
while (true) {
if (missedBeats > 1) {
PlaySound (SOUND_DOWN);
stop messageWatcher;
Off(OUT_C);
until (armLock == 0);
Off(OUT_A);
until (Message () == HEARTBEAT_MESSAGE);
PlaySound(SOUND_UP);
missedBeats = 0;
start messageWatcher;
}
missedBeats = misse 1;
Wait(HEARTBEAT_TIME);
}
}
Don't Break That Arm
The
grab
and
release
tasks, as I said, have the ability to interrupt each other. They use a variable,
armLock
, to avoid potentially dangerous situations. For example, suppose that
release
is
running. It drives the arm motor in reverse until the arm is up and the limit touch sensor is pressed. Then the motor is run forward to release the touch sensor. Before the touch sensor is released,
however, suppose
grab
starts up. It stops
release
and runs the motor forward until the touch sensor is pressed. It's already pressed, so
grab
starts running the motor in reverse, waiting for the
touch sensor to be released. Since the arm is already at the top of its travel, running the arm motor in reverse creates pressure on the gears and will either break the arm apart or cause the gears to
skip.
Page 157
Using the
armLock
variable enables
grab
and
release
to complete the press-release cycle of the arm limit switch without being interrupted. Both
grab
and
release
wait for
armLock
to
be 0 before interrupting the other task, like this:
until (armLock == 0);
The
grab
and
release
tasks set
armLock
to 1 before doing the sensitive press-release cycle. This means Minerva should never break her own arm.
Stayin' Alive
The
heartbeatWatcher
task also deserves some mention. It adds one to the
missedBeats
variable just as often as it expects the remote to send a heartbeat. Remember that just as
heartbeatWatcher
is adding to
missedBeats
, the
messageWatcher
task is subtracting from
missedBeats
every time it hears the heartbeat message. If
missedBeats
is ever
greater than one,
heartbeatWatcher
shuts Minerva down. This shutdown is not as straightforward as you might think, however. First, a sound is played (the descending arpeggio). This lets
the human operator know that contact with the remote has been lost. Then
heartbeatWatcher
shuts down the
messageWatcher
task and turns off Minerva's drive motor:
PlaySound(SOUND_DOWN);
stop messageWatcher;
Off(OUT_C);
heartbeatWatcher
also wants to shut down Minerva's arm motor, but it respects the
armLock
variable so the arm is not left in an uncertain state:
until (armLock == 0);
Off(OUT_A);
Now
heartbeatWatcher
waits to regain the heartbeat signal from the remote. If it is regained,
heartbeatWatcher
plays another sound (the ascending arpeggio), resets
missedBeats
,
and starts up
messageWatcher
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 ...