For hackers and DIY enthusiasts, it is always a challenge to make correct measurements between their robots and nearby objects such as an autonomous vehicle. Estimating the distance is important for the robot to make a decision about avoiding bumping into obstacles. Although this may be considered trivial for a small robot running into a wall, it could turn out deadly for the same robot encountering an autonomous vehicle.
In 2013, NASA held a competition called SRR or Sample Return Robot, where several entrants used various techniques for making measurements using visual aids such as cameras. Two entrants used LIDAR, which can also be used with the single board computer, the Raspberry Pi, or RBPi.
Although using similar methods, LIDAR uses light for measurements, rather than its forerunner RADAR or Radio Detection and Ranging. According to the Merriam-Webster dictionary, LIDAR was first used 1963 for measurement of clouds and Apollo 13 used it to measure the surface of the moon. Since then, the reductions in the size of lasers have led to additional uses, including the military using LIDAR for range finding.
A scanning LIDAR uses the laser beam to sweep a wide area both vertically and horizontally. The feedback provides a cloud of distantness measurement points. This is similar to aircraft control radar swinging a beam through the sky. There are two principal methods for measuring distances using a laser. One is to measure the time of flight of a laser pulse and the other is to measure the angle by which the laser beam deflects.
For the time of flight measurement, you send out a pulse of laser and measure the time for the signal to return. That time divided by the speed of light gives the distance the laser traveled out and back. The distance to the object is then half the calculated distance. Given the high speed at which light travels, it is difficult to measure distances below a meter using lasers, because light would be returning in about seven nanoseconds. LIDAR uses continuous modulation of the laser by amplitude or frequency and measures the phase difference between the transmitted and received signals. This process using modulation allows measurements down to centimeters.
The LIDAR is actually a sealed unit with a motor at one end that spins a turret at about 300 RPM. Inside the turret are the laser and the receiving sensor. Spinning allows a 360-degree scan of the surrounding area. There are two optical ports out of the turret, corresponding to the laser and the sensor. A two-pin connector provides power to the motor. Another four pin connector is for supplying the inner control and serial interface circuits with 5V and 3V3 DC.
WiringPi is a library of programming the GPIO on the RBPi that offers an absurdly simple and minimal user interface for handling the LIDAR. Additionally, WiringPi is suitable for several RBPi models. Another advantage in using WiringPi is its ability to do hardware PWM on one GPIO pin of the RBPi. Another possibility is to use PID or Proportional Integral Differential control system in a loop to maintain constant speed of the turret motor.