Supports measurement of distances.
What Are They?
They measure the distance from the device to an obstruction in front of it.
All readings from this library are in 'cm' and so you can swap one device for another in Project Designer. So long as you give the new device the same name as the old device then your project code will not need to be modified.
But note that you may not always get the same results.
The devices that use an infra red light beam, like the Sharp sensors, have 'tunnel vision'. When they say there is nothing ahead then what they mean is 'there is sufficient gap for a beam of light to pass through' - and your robot may be slightly wider than a beam of light. If not then let me know and perhaps we can become billionaires together. This is normally circumvented, to a degree, by mounting the sensor on a servo and flicking it from side to side like a 'laser light show'. But note that this could still miss thin objects like a chair leg.
Sonar devices emit a 'blip' of sound and listen for echoes. The width of this beam of sound dictates how 'fuzzy' the result is. Some sonars emit a very directed sound pulse whereas others use a fog-horn approach.
So think of sonars as being pessimistic and fuzzy, and light beams as optimistic and precise.
For 'exact' work you may want to use both - ie when the sonar says there is something ahead then use light beams to scan that area.
If you are using more than one of the same type then you need to be careful to avoid incorrect readings. For example: if you have two sonars sending out 'pings' of sound simultaneously then one sonar may hear the echo of the sound produced by the other sensor.This is called 'ghosting' - and also applies to light beam sensors.
The library already makes sure that a given sensor cannot receive ghost replies from the previous time it was read but if you are using more than one sensor then you may want to add extra delays between accessing each sensor.
Assuming you have called your sensor 'myDistance' in Project Designer then it can be accessed as follows:-
cout << "Distance=" << myDistance.getDistance();
Or dumped to the standard out destination using:-
cout << myDistance;
Project Designer supports the following devices