Sensors: GPS, IMU, cameras and lidar
Every sensor is good at some things and bad at others. Learn what each one measures, where it fails, and why machines combine several of them.
In 60 seconds
Sensors: GPS, IMU, cameras and lidar
Every sensor is good at some things and bad at others. Learn what each one measures, where it fails, and why machines combine several of them.
The main sensors
| Sensor | What it measures | Good at | Weak at |
|---|---|---|---|
| GPS / satellite navigation | Position on Earth from satellite signals | Works anywhere with open sky; error does not grow over time | Often a few metres off; worse near tall buildings and trees; does not work indoors or in tunnels; updates only a few times a second |
| IMU: accelerometer | Acceleration, including the pull of gravity | Knows which way is down when the machine is still | Very noisy with vibration; cannot tell tilt from speeding up |
| IMU: gyroscope | How fast it is turning | Smooth and fast; great for short moments | A small bias adds up over time, so the angle slowly drifts |
| Magnetometer (compass) | Earth's magnetic field | Gives a heading | Confused by motors, steel, wires and buildings |
| Barometer | Air pressure, used for height | Cheap height estimate | Changes with weather and wind |
| Camera | Images: colour, texture, signs, lane lines | Rich detail; cheap; can read signs | Needs light; struggles with glare, darkness, fog and rain; depth is hard from one camera |
| Lidar | Distance, by timing pulses of laser light | Accurate 3D shape; works in the dark | Costly; heavy rain, fog and dust reduce range; glass and very dark surfaces can confuse it |
| Radar | Distance and speed, using radio waves | Works in rain, fog and dark; measures speed directly | Low detail; hard to tell what an object is |
| Ultrasonic | Distance, using sound echoes | Cheap; fine for very short range, like parking | Short range; soft or angled surfaces give weak echoes |
Why one sensor is never enough
Averaging: the simplest fusion
import numpy as np
rng = np.random.default_rng(1)
true_value = 20.0 # say, a true tilt of 20 degrees
noise, bias = 3.0, 0.0 # try bias = 2.0 as well
for n in [1, 4, 16, 64]:
# 2000 experiments, each averaging n readings
readings = true_value + bias + rng.normal(0, noise, size=(2000, n))
averages = readings.mean(axis=1)
print(f"average of {n:2d} readings: typical error {averages.std():.2f}, "
f"mean error {averages.mean() - true_value:+.2f}")The complementary filter
angle = alpha × (last angle + gyro rate × dt) + (1 − alpha) × accelerometer anglealpha close to 1, such as 0.98, the smooth gyroscope decides the short-term changes, and the accelerometer slowly pulls the angle back so it cannot drift away. Flight controllers use this idea or its big brother, the Kalman filter, which also keeps track of how uncertain each estimate is.- Trust one sensor completely
- Assume a sensor's number is the truth
- Test only on a sunny day in an open field
- Combine sensors whose weaknesses are different
- Model noise and bias, and check them
- Test in dark, rain, dust, near buildings and with vibration
bias = 2.0 and run it again. Which number gets smaller as you average more, and which one does not?Watch and read more
Lab
An average function and a working complementary filter that beats both the gyroscope and the accelerometer alone.
The problem
This runs in your browser with made-up sensor data: a drone rocking gently, a gyroscope with a small bias, and a very noisy accelerometer.
- Finish
average(readings). - Finish
complementary_filter: at each step, blendgyro_guesswith the accelerometer angle usingalpha. - Run it and compare the three errors printed at the end. The filter should beat both sensors alone.
- Try
alpha= 0.5 and 0.999. Write one sentence on what goes wrong at each end.
Practice lab
Edit the code and run it. Python runs in your browser — nothing is sent to our server.
No output. Add print(...) to see values.
You are done when
Hard questions
Try to answer before you reveal. If you can answer these, you understood the lesson.
Q1Why can the accelerometer not be trusted for tilt when the drone speeds up or brakes?Reveal
An accelerometer feels gravity and the drone's own acceleration mixed together. When the drone speeds up, the extra push looks just like a tilt. When it is still or moving steadily, only gravity is left, so the tilt reading is right. That is why the filter uses it only as a slow correction, not for quick changes.
Q2How would you choose alpha for a real drone, not made-up data?Reveal
Record real flights, ideally with a reference such as a more accurate sensor or a motion-capture setup, and try several values. Look at the trade-off: lower alpha follows the accelerometer's vibration noise; higher alpha lets gyroscope drift grow. The best value depends on the sample rate, vibration and how big the gyroscope bias is. A Kalman filter can adjust this balance automatically from noise estimates.
Questions people ask
What does IMU stand for?
Inertial measurement unit. It usually combines an accelerometer and a gyroscope, and often a magnetometer. A small IMU chip is inside most phones, which is how your phone knows when you turn it sideways.
Why not use only lidar, if it is so accurate?
Lidar gives good shape and distance, but it cannot read a traffic light's colour or a sign's text, it is costly, and bad weather reduces its range. Cameras add colour and meaning; radar adds speed and bad-weather range. Different teams choose different mixes, and each choice has trade-offs.
Can a phone be used as a robot's sensor?
Yes, for learning. A phone has an IMU, a camera and satellite navigation. Several free apps can stream or log these readings, which is a cheap way to see real noise and drift for yourself.
What is the difference between noise and bias?
Noise is random: sometimes too high, sometimes too low. Averaging helps. Bias is steady: always off in the same direction. Averaging does not help; you need calibration or another sensor to correct it.
Lesson test
5 questions. Get 3 right (60%) to pass and complete this lesson.