Distance Sensor

The distance sensor provided is the Sharp GP2D12.

This is capable of measuring the distance to objects at ranges from 10 to 80cm.  It provides a voltage output which can be connected to an analog input on the Handyboard.

For details, see the manufacturer's data sheet.

How does it work?

The distance sensor transmits a short burst of infra-red light at intervals of about 1ms.  The light source is behind one of the lenses (the one on the left in the picture above), which focuses the light into a narrow beam.

Light reflected from an object in this beam will return to the sensor, at an angle which depends on the distance to the object.  This light passes through the other lens on the distance sensor, and is focused onto an array of light detectors.  Light arriving at different angles will fall on a different set of light detectors.  

Voltage output

The electronic circuits inside the sensor process the information from the light detectors to produce an output voltage related to distance as shown:

Note that this is the graph for a typical distance sensor.  There may be significant variations between individual distance sensors.  If you want to convert the output voltage into a precise distance, you should test your particular distance sensor first. 

The output is only updated every 38 to 40ms.  If you read the output of the distance sensor every 5ms, you will just get the same information 7 or 8 times.

Connecting to Handyboard

The output of the distance sensor is not compatible with the normal Handyboard input circuits.  The Handyboard has a 47kOhm resistor connected to each input port, and this prevents the distance sensor from working properly.

We have removed these resistors from ports 4 and 5.  The distance sensors will only work properly in these analog input ports.  Some other sensors need the resistor, and will not work properly in these ports.

The Handyboard  analog( )  function will return an integer proportional to the voltage at the port: 
0 for 0V,  up to a maximum of 255 for 5V.

Noise

The distance sensor output is noisy - there is a lot of variation in the output voltage when nothing is moving in front of the distance sensor, and even during the 40ms period when the output is not updated.  This is mainly due to the operation of the internal circuit of the distance sensor.

To try to remove some of this variation, we have connected a simple low-pass filter to the output of the distance sensor.  This acts to average the output voltage over a time interval of about 1.5ms, and smooth out any sharp variations.

If you wish, you can do more averaging in software: take several readings from the distance sensor and calculate an average value.  This will also have the effect of smoothing out the variations, and should give a result closer to the true output of the sensor.  The disadvantage is that it takes time - if you try to do this every time you want a value from the distance sensor, it will take a long time to get a result.  A better approach might be to have a separate program working in the background, constantly reading the distance sensor, so that the main program can have an up-to-date average when it wants it.

Interference

The beacons and the distance sensors use infra-red light of similar frequency (or wavelength).  This means that they can interfere with each other.

If the light from a beacon enters the distance sensor, it can cause false readings.  The problem is only significant when the distance sensor is relatively close to the beacon, and aimed in the direction of the beacon.  It is particularly bad when the reflected light from the target object is weak (perhaps the object is far away, or does not reflect the infra-red light from the distance sensor very well).

The black shield just below the beacon is intended to reduce these effects, by preventing the light from the beacon from heading downwards.  

The assumption is that distance sensors will be mounted close to the table surface.  By keeping the light from the beacon at a higher level, the interference can be reduced significantly.

In most cases, any distance errors due to interference will be small and will vary randomly.  You can reduce the effect by averaging a few successive values from the distance sensor, or just by checking the sensor twice before taking a significant action.  Remember that the distance sensor output is only updated at intervals of about 40ms, so there is no point in checking it at times which are too close together if you are trying to eliminate this type of interference.

There is potential for interference in the other direction also - the light from the distance sensor can interfere with a beacon receiver.  The narrow beam of light from the distance sensor and the shielding of the beacon receiver make this much less likely to occur.  However, if light from a distance sensor does fall directly on a beacon receiver, it can prevent the receiver from receiving the beacon signal.  It can also cause the beacon receiver software to output the time interval of the distance sensor (around 1ms) instead of the time interval of the beacon.  It should be easy to reject such values in software.

Other optical sensors, such as those used for line detection, could also interfere with the distance sensors.  This is unlikely to be a problem, as the light from those sensors should be directed downwards, onto the table surface.  The rules of the RoboRugby competition will not allow a robot to transmit any infra-red light horizontally, except for light transmitted by distance sensors. 

Infra-red light from the line detecting components is continuous, not pulsed, so it is less likely to cause false readings from a distance sensor.  

 

Copyright 2006, UCD School of Electrical, Electronic and Mechanical Engineering. Contact