How distance sensing works
Before diving into connecting and programming distance sensors, we should examine how they operate. Chapter 7, Planning and Shopping for More Devices, evaluated options and chose optical (light-based) distance sensors. We will be focusing on this type for the remainder of this chapter.
Many distance sensors operate using a principle known as time of flight. The following diagram demonstrates this:
Figure 8.1 – Optical distance sensor operation
The preceding diagram shows pictures of robots with sensors and the returned light. On the top left, a single beam is emitted (shown as a cone), hits an object, and its reflection (shown as a dashed line) hits the sensor (the blue box), which detects it. The time between emitting the beam and receiving the response is the time of flight used to calculate the distance. At the top right of the diagram, both sensors are active. However, the left sensor detects a closer object in its beam...