EasyManuals Logo

LEGO MINDSTORMS Robots User Manual

LEGO MINDSTORMS Robots
226 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #101 background imageLoading...
Page #101 background image
Page 105
release();
// Turn around.
OnRev(OUT_C);
Wait(TURNAROUND_TIME);
}
Let's look at the simple parts first. The grab() and release() inline subroutines take care of the grabber arm. All they do is run the arm motor in one direction until the limit sensor is pressed.
Running the motor forward causes the arm to descend, the grabber to close, and the arm to lift again. Running the motor in reverse makes the arm descend, the grabber open, and the arm lift again.
The mechanics of the arm take care of everything, as I'll explain later in the chapter. All we have to do is wait for the arm to lift, which presses the switch when it's finished. You might have
noticed that the light sensor and the touch sensor are both attached to the same input. I'll talk about how this works later. For now, just be aware that it's necessary for grab() and release() to
move away from the touch sensor to use the light sensor.
The calibrate() subroutine examines the values coming from Minerva's light sensor. It computes an average value, which is stored in the variable threshold. The retrieve()
subroutine uses this value to figure out if it's looking at an object that should be picked up. Specifically, it tests if the light sensor value is a little less than the original average:
until (SENSOR_3 < threshold - 3);
Calibrating the sensor in this way frees us from hard-coding a light sensor threshold value into Minerva's program. It also makes Minerva better able to deal with different lighting conditions.
The retrieve() subroutine is the heart of Minerva's program. It drives forward (by turning output C on) until it finds something dark to pick up. While it's driving forward, timer 0 is ticking
away, measuring how long it takes until something is found:
OnFwd(OUT_C);
ClearTimer(0);
until (SENSOR_3 < threshold - 3);
Once a dark object is found, Minerva moves forward a little farther to position the grabber over the object. She records the forward movement time for the return trip. Finally, Minerva turns off
output C to stop the robot's forward motion:
Wait(20); // Move up on it a little.
returnTime = Timer(0);
Off(OUT_C);
Having found something interesting, Minerva picks it up:
grab();
Page 106
Now she wants to turn around and return to her starting point. To turn around, she simply reverses the direction of output C for the duration given by TURNAROUND_TIME:
OnRev(OUT_C);
Wait(TURNAROUND_TIME);
Now she drives back to her starting point, using the returnTime value, which was saved earlier:
OnFwd(OUT_C);
ClearTimer(0);
until (Timer(0) >= returnTime);
Off(OUT_C);
Finally, the retrieve() subroutine drops the object that Minerva's carrying and turns around again:

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

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

LEGO MINDSTORMS Robots Specifications

General IconGeneral
Product LineLEGO MINDSTORMS
CategoryToy
Age Range10+
Batteries RequiredYes
Memory64 MB RAM, 16 MB Flash
ConnectivityBluetooth, USB
SensorsTouch, Color, Gyro
Battery TypeAA
Interactive FeaturesProgrammable, Remote Control
App CompatibilityiOS, Android
ProcessorARM9
Pieces Count601
Battery Count6
App NameLEGO MINDSTORMS EV3 Programmer App

Related product manuals