Programming - LEGO MINDSTORMS Robots Manual

Unofficial guide
Table of Contents

Advertisement

Programming

Minerva's basic program is straightforward:
find something to pick up
bring 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 environment that comes with RIS), but you wouldn't be able to implement
some key features. In particular, Minerva's ability to drive back just as far as she drove forward is crucial. There's no way to do this in RCX Code. Minerva's program also does some sensor
calibration that would also be impossible in RCX 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_LIGHT);
SetPower(OUT_A + OUT_C, OUT_FULL);
calibrate() ;
i = 0;
while (i < 5) {
retrieve();
i += 1;
}
OFF(OUT_A + OUT_C);
}
#define NUMBER_OF_SAMPLES 10
int runningTotal;
int threshold;
Page 103

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the MINDSTORMS Robots and is the answer not in the manual?

Questions and answers

Table of Contents