WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

Sharp GP2

Sharp Infra Red distance sensors.
There are a number of different sensors but they are all used in the same way. The difference between them is the usable range over which they can detect objects. The devices work by shining a beam of light which is reflected back from an object. The further away the object is then the more it displaces the light to the sides. Therefore: you will notice that the devices which can detect further distances are physically larger because the 'eye' which sees the reflection needs to be further away from the transmitter. Equally the transmitter needs to be more powerful and is therefore larger.
Because these devices uses a beam of light then they are not very good at detecting thin objects - like chair legs. This happens because the beam of light may move from one side of the leg to the other and so therefore it misses the fact that the leg is there. For a less precise detector you should consider using a sonar.
The devices output a voltage and so should be connected be to an ADC pin and use the +5V regulated supply to power them. A word of caution: these devices are inherently noisy and require spikes of current. The noise can be reduced by connecting the black casing to ground (yes - it looks like plastic but it is actually conductive). If your robot has a metal shell then bolt the sensor to the shell and connect the shell to ground. The current spikes can be minimised by fitting a capacitor of around 10uF close to the device - preferably by soldering an SMD capacitor into the device itself.
You will still find some spikes in the readings and so, if these spikes confuse your robot, then you should consider writing a low pass filter in software to filter out these spikes. But a word of caution: that spike may actually be correct ie something has suddenly come into view.
The range of devices we support are as follows:-
sharp GP2D12.jpg
GP2D12 This measures between 10cm and 80cm
Sharp GP2D120.jpg
GP2D120 This measures between 4cm and 30cm
Sharp GP2D15.jpg
GP2D15 This measures between 10cm and 80cm
Sharp GP2Y0A02YK.jpg
GP2Y0A02YK This measures between 20cm and 150cm
Sharp GP2Y0A21YK.jpg
GPY0A21YK This measures between 4cm and 30cm
Sharp GP2Y0A02YK0F.jpg
GP2Y0A02YK0F This measures 20cm to 150cm
Sharp GP2Y0A710K0F.jpg
GP2Y0A710K0F This measures 100cm to 550cm
Sharp GP2Y0A700K0F.jpg
GP2Y0A700K0F This measures 100cm to 550cm
Note that the larger the maximum distance then the more peak current these devices will require. It is common for them to require a peak current of 0.3 amps !
Assuming you have called your sensor 'myDistance' in Project Designer then it can be accessed as follows:-
DISTANCE_TYPE cm = myDistance.getDistance();
cout << "Distance=" << cm;
Or dumped to the standard out destination using:-
cout << myDistance;
Function Summary

Valid XHTML 1.0 Transitional