Robot Foundations · Module 4: Sensing the World
Sensors That Look Outward: Distance and Images
To learn what is around it, a robot times echoes to measure distance, or takes pictures to recognise things. Neither does both.
Switch off the lights in a familiar room and walk across it. You do fine by touch and by memory, but you cannot tell which door is which colour, and you cannot read the labels on the shelf. Robots face this choice in every sensor they carry: a sensor can measure how far something is, or tell what it looks like, and the cheap, reliable ones do only one. This lesson explains how the three common outward-looking sensors work and what each is good for.
What you will be able to do
- Explain how a distance sensor turns the time of an echo into a distance.
- Say what a laser scan of a room looks like and what it cannot show.
- Say what a camera gives a robot that a laser scanner does not, and the reverse.
- Choose the sensor that fits a simple job.
The idea
Distance by timing an echo
Shout at a cliff and you hear your voice come back a moment later. The longer the wait, the further away the cliff. Distance sensors work the same way: send out a short pulse, wait for the echo, and turn the waiting time into a distance. The pulse travels to the object and back, so the trip is twice the distance.
The distance is the speed of the pulse multiplied by the waiting time, divided by two.
distance = speed of pulse × time ÷ 2
The division by two is the one thing people forget: the time covers the way there and the way back.
Two kinds of pulse are common:
- Ultrasonic sensors send a click of sound too high-pitched to hear. Sound travels about 343 m/s in air, slowly enough that the echo from 2 m takes about 11.7 milliseconds, easy for cheap electronics to time. They are small and inexpensive, but they see a wide, blurry cone and are fooled by soft surfaces that swallow sound.
- Laser scanners, called LiDAR (Light Detection And Ranging), send a pulse of laser light. Light is fast: 300 million m/s, so the echo from 2 m returns in about 13 nanoseconds (billionths of a second). Fast electronics can time that, and a spinning mirror aims the beam all around, so one device measures hundreds of distances every turn.
What a laser scan looks like
Each beam gives one number: how far away the first thing it hit is. The robot knows the angle of every beam, so each reading is also a direction, and together they are a dot at a known spot. Pip's scanner gives 72 dots per turn, one every 5°.
Two things to notice. First, a scan is a set of dots, not a picture: the robot has numbers, and working out "that is a wall" and "that is a box" is the job of a later program (the Perception track on this site). Second, the box casts a shadow. Nothing is known about the space behind it. The robot knows what it sees, never what is hidden.
Pictures from a camera
A camera measures the brightness and colour of light arriving from each direction and gives the robot an image: a grid of numbers, one or three per tiny square (pixel). A single camera answers a different question from a scanner.
| Laser scanner (LiDAR) | Camera | |
|---|---|---|
| Gives the robot | How far away things are, in every direction | What things look like: colour, shape, texture, text |
| Good at | Walls, obstacles and the shape of the room, in any lighting | Recognising objects, reading signs and labels, telling two boxes of the same size apart |
| Cannot do | Tell a red box from a blue one | Measure distance directly (one image has no depth) |
| Struggles with | Glass and mirrors (light passes through or bounces away), fog and rain, very dark surfaces | Darkness, glare, and anything that changes how it looks |
| Data per reading | 72 numbers per scan for Pip | Tens of thousands to millions of pixels per picture |
Distance sensors tell the robot where things are. Cameras tell it what things are. Most robots carry both.
Special cameras that also measure depth exist (stereo pairs and depth cameras). They sit between the two columns of the table: a picture and a distance for each pixel, usually with a shorter range and more fuss than a scanner.
In lab 2 you will give Pip's simulated robot a LiDAR, a camera and wheel encoders in turn, and see which jobs each can and cannot do. "Stop in front of the wall" needs distance. "Go to the red box" needs colour. "Go to the red box and stop in front of it" needs both.
Words to know
- Time of flight
- Measuring distance from how long a pulse takes to reach an object and return. On Pip: the method of both the ultrasonic sensor and the laser scanner.
- Ultrasonic sensor
- A distance sensor that uses sound too high to hear. On Pip: not fitted: its scanner is more precise, at more cost.
- LiDAR
- Light Detection And Ranging: a distance sensor that times pulses of laser light, often aimed by a spinning mirror. On Pip: its main sensor, 72 beams per turn.
- Scan
- One full set of distance readings from a scanner. On Pip: 5 of the 72 beams hit the box in the figure.
- Camera
- A sensor that records the colour and brightness of light from many directions as an image. On Pip: an optional front camera with a 70° field of view, as in lab 2.
- Pixel
- One tiny square of an image, with its brightness or colour as a number. On Pip: a 640 by 480 picture has about 300 000 of them.
- Shadow (occlusion)
- The space hidden behind an object, which a sensor cannot see. On Pip: the wall behind the box in the scan.
A worked example: two echoes
An ultrasonic echo. A sensor clicks and hears the echo 11.7 ms later (that is 0.0117 s). The speed of sound is 343 m/s.
- Total trip. speed × time = 343 × 0.0117 = 4.01 m.
- Divide by two. The pulse went there and back, so the object is 4.01 ÷ 2 = 2.01 m away.
A laser echo. The scanner sees a pulse return after 13.3 ns. The speed of light is about 3 × 10⁸ m/s.
- Total trip. 3 × 10⁸ × 13.3 × 10⁻⁹ = 4 m.
- Divide by two. 2 m.
Both sensors found an object about 2 m away. The laser needed a clock accurate to a few billionths of a second, which is why laser scanners cost more than ultrasonic sensors. What you pay for is precision: the scanner's beam is a thin line, so it measures one direction at a time, while the ultrasonic cone is wide and cannot say which part of the cone the echo came from.
Choosing. Pip must (a) stop 0.5 m from a wall, and (b) find the box with the orange sticker. For (a) it needs distance, so the scanner is right. For (b) it needs to see a colour, so it needs the camera. The scanner will find both boxes and cannot say which is orange.
Try it yourself
Clap once in a long corridor, or at a wall across a large room, and listen for the echo. Estimate the delay in seconds (counting out loud helps if the delay is long). Use distance = speed × time ÷ 2 with a speed of 343 m/s to estimate how far away the wall is. Then walk to the wall and count your paces (one pace is roughly 0.75 m) to check.
What to expect
An echo from a wall 17 m away comes back after 2 × 17 ÷ 343 ≈ 0.1 s. You can just hear a clap and its echo as two sounds from about that distance. Closer walls give an echo that blends with the clap, which is why ultrasonic sensors need electronics to time what your ear cannot. Your estimate will probably be rough: a few metres out is typical. That is the right feeling for a sensor reading.
Common mistakes
"A laser scanner sees objects."
It measures distances along each beam. Turning those dots into "a chair" or "a person" is a separate task, and the scanner cannot tell a chair from a bin of the same shape.
"A camera tells the robot how far things are."
A single picture has no depth: a small box close by and a large box far away look alike. Distance has to come from another sensor, from two cameras, or from clever assumptions that can fail.
"I forgot to divide by two and my robot stops twice too late."
The pulse travels to the object and back. The most common mistake with echo sensors is to treat the whole trip as the distance. Check the answer against a tape measure the first time you use any one.
Remember this
- Distance sensors time an echo: distance = speed of pulse × time ÷ 2.
- A laser scan is a set of dots with known directions. Objects hide what is behind them.
- A camera gives colour and appearance but not distance. A scanner gives distance but not colour.
- Choose by the job: distance for stopping and avoiding, appearance for recognising.
Check yourself
Three questions. Write an answer in your own words, then reveal the explanation. Nothing you type leaves your browser.
Question 1
An ultrasonic sensor hears an echo 6 ms after the click. How far away is the object? (Sound travels at 343 m/s.)
Explanation
Total trip = 343 × 0.006 = 2.06 m. The object is half that: about 1.03 m away.
Question 2
A robot must pick the correct one of two identical grey boxes by reading a number printed on the front. Which sensor, and why not the other?
Explanation
A camera, because the number is a matter of appearance. A laser scanner measures only distance and would see two identical boxes at known positions, with no way to tell them apart.
Question 3
A robot scans the room and finds an open gap in the wall behind a chair. Is it safe to assume the way through is clear?
Explanation
No. The chair is casting a shadow on the space behind it, and the apparent gap could be a gap in the scan, not in the wall. The robot has not seen what is there. It should move to see it from another angle before relying on it.
What’s next
Those sensors look outward. Robots also need to feel their own motion, with sensors that measure the robot and not the world. They are the subject of the next lesson.
Where this goes on the site
Nothing below is needed to continue this course. These pages take the topic of this module further, and most assume more mathematics or Python than this course does.
- LaterUnderstand & Visualize a Point Cloud
A real LiDAR scan, point by point, in Python.
- LaterPerception
Turning camera images and LiDAR scans into objects.
- LaterWhy Robots Need Probability
Noise treated with the right mathematics.