http://forums.parallax.com/forums/default.aspx?f=6&m=129103
In Ping)))Dar – A Radar Style Display, we used the debug terminal to get an idea of what objects look like when the Boe-Bot scans them with the Ping))) Ultrasonic Rangefinder and Mounting Bracket kits. In this activity, we'll use the same setup along with a program that makes the Boe-Bot scan a field of objects and go to the closest one. Figure 1 shows the Boe-Bot's “scan and go to” sequence as it runs GotoClosestObject.bs2. Here's what it does:
√ (The Boe-Bot pauses for 2 seconds after the RESET button on the Board of Education is pressed and released.
√ The Boe-Bot directs the Ping))) Ultrasonic Rangefinder to the right (0°).
√ It scans from right to left (180°) while taking successive distance measurements and saving the angle and distance of the closest measurement it found.
√ The Boe-Bot then points the Ping))) rangefinder in the direction of its closest measurement.
√ The Ping))) is then swept to the right in smaller increments until the object's right edge is detected.
√ The Ping))) is swept to the left (in the same small increments) until the object's left edge is detected.
√ The Boe-Bot calculates the middle of the object and turns in place to face it.
√ The Boe-Bot goes to the object.