
Page 154
grabber arm command it sent to avoid unnecessarily sending the same command twice.
To provide some feedback to the human operator,
lightWatcher
plays tones when it sends the grab or release commands.
The
hearbeat
task is very simple. It repeatedly sends the heartbeat command to the IR port.
Programming Minerva
Minerva's program, then, must listen for incoming messages on the IR port and respond to them. This is fairly simple, but it's complicated by two things:
1. Minerva should listen for the heartbeat commands from the remote. If she doesn't hear them, she should stop what she's doing until the IR link is established again.
2. The human operator should be able to change the direction of the arm as it is moving, without waiting for an entire grab or release cycle to be completed. This feature, however, should not
interfere with Minerva's ability to stop the arm when it moves up as far as it can go.
Minerva's program is split into four primary tasks:
message Watcher
The
messagewatcher
task examines the IR port for incoming messages. When one arrives, it is examined and the appropriate action is taken.
grab
and
release
The
grab
and
release
tasks are kicked off by
messageWatcher
to control Minerva's arm. They are separate tasks so that
messageWatcher
can continue to receive commands from the
remote while the arm is moving. You could, for example, start driving forward while the arm was grabbing.
grab
and
release
have the ability to interrupt each other, so you can change the
direction of the arm as it's moving.
heartbeatWatcher
This task keeps count of missing heartbeats. When
messageWatcher
receives a heartbeat, it subtracts one from a tally of missing heartbeats, kept in the
missedBeats
variable. The
heartbeatWatcher
adds one to this count; if it's ever more than one,
heartbeatWatcher
assumes it has lost contact with the remote. It then stops the
messageWatcher
task and shuts
down the robot's motors. When the heartbeat is heard again,
heartbeatWatcher
starts up
messageWatcher
once again.
Here's the entire program. I'll describe more of the details after the listing.
Page 155
#define FORWARD_MESSAGE 16
#define SPIN_MESSAGE 17
#define STOP_MESSAGE 18
#define GRAB_MESSAGE 19
#define RELEASE_MESSAGE 20
#define HEARTBEAT_MESSAGE 21
#define HEARTBEAT_TIME 20
int message;
int armLock;
int missedBeats;
task main() {
SetSensor (SENSOR_3, SENSOR_LIGHT);
armLock = 0;
missedBeats = 0;
start messageWatcher;
start heartbeatWatcher;
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 ...