Page 114 - The Unofficial Guide to Lego Mindstorms Robots
P. 114
103
Programming
Minerva's basic program is straight forward:
fi nd something to pick up
bri ng it back to the starting point
The program assumes that the objects to pick up will be dark and that the surface Minerva is driving on is light. To return to
the starting point, Minerva measures how long it has to drive forward to pick something up. Then it turns around and drives
back for the same amount of time. Here's a slightly exploded version of Minerva's program:
drive forward until the light sensor sees something dark
pick it up with the grabber
turn around
drive back to the starting point
drop whatever's in the grabber
I've written Minerva's program in NQC (see Chapter 4, Not Quite C). You could create a program in RCX Code (the
en vironment that comes with RIS), but you wouldn't be able to implement some key features. In particular, Minerva's ab ility to
dr ive back just as far as she drove forward is crucial. T here's no way to do this in RCX Code. Minerva's program also does
so me sensor calibration that would also be impossible in R CX Code.
Here's the whole program:
#define TURNAROUND_TIME 425
int i;
task main() {
// Arm limit sensor and grabber light sensor.
SetSensor(SENSOR_3, SENSOR_LIGH T);
SetPower(OUT_A + OUT_C, OUT_FUL L);
calibrate() ;
i = 0;
while (i < 5) {
retrieve();
i += 1;
}
OFF(OUT_A + OUT_C);
}
#define N UMBER_OF_SAMPLES 10
int runningTotal;
int threshold;