
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;
Содержание 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 ...