Linearity, calibration and latency
A sensor is perfectly accurate, but its answer arrives 200 ms late. At 2 m/s, how far has the robot moved?
About 40 min · 3 goals · Checked by automated tests
1.Why should I care?
Raw sensor numbers are rarely in the units you want. Calibration turns them into centimetres or newtons, and knowing a sensor's latency tells you whether its answer still describes the world by the time you use it.
- ◇ Describe linearity and non-linearity in a sensor's response.
- ◇ Build a two-point calibration that converts raw readings to physical units.
- ◇ Explain latency and bandwidth and estimate the error latency causes on a moving robot.
2.Discover
In the Code Lab, write calibrate(raw) for the load cell in the prediction: compute the gain and offset from the two calibration points, then test it on 120, 520 and 920. Add a check that warns when a reading falls outside the calibrated span.
Can't use the interactive? Read a description instead
This lesson uses the Code Lab. Equivalent paper task: given calibration points (0 kg, 120 counts) and (10 kg, 920 counts), compute gain = 80 counts per kg, then convert readings 120, 520 and 920 to 0, 5 and 10 kg, and flag readings below 120 or above 920 as outside the calibrated span.
3.Checkpoint: guided practice
Check what you just discovered before going on. Hints appear after a wrong answer.
Practice 1
A pressure sensor reads 200 counts at 0 kPa and 3200 counts at 100 kPa. What is its gain in counts per kPa?
4.Apply it
Extend your calibrate() function to take any number of reference points and report the largest residual from the best straight line through the end points. Test it on a sensor that bows by 2% at mid-span and say whether two-point calibration is good enough for ±1% accuracy.
5.Understand
Linear response
A linear sensor's output is a straight line of its input: output = gain × input + offset. Many sensors are nearly linear over part of their range and curve near the ends. Linearity on a spec sheet says how far the real curve strays from the best straight line, often as a percentage of full scale.
Two-point calibration
Measure two known inputs and record the raw outputs. The gain is the change in raw reading per unit input: (r₂ − r₁) ÷ (x₂ − x₁). Then input = (raw − r₁) ÷ gain + x₁. Choose the two points near the ends of the span you care about, and check a third point in the middle to spot non-linearity.
Latency and bandwidth
Latency is the delay between something happening and the reading reflecting it: conversion time, filtering, communication. Bandwidth describes how fast a change the sensor can follow at all. A robot moving at speed v that acts on a reading with latency τ is acting on a world that has already moved v × τ.
Spec-sheet honesty
Most numbers on a datasheet hold only under stated conditions: temperature, supply voltage, warm-up time. Calibrate in conditions like the ones the robot will meet, and re-check after big changes.
Explain it another way
Calibration is like learning a friend's accent: once you know how their 'raw' sounds map to words, you understand them perfectly. Latency is like hearing thunder after the lightning.
With calibration points (x₁, r₁), (x₂, r₂): gain k = (r₂ − r₁)/(x₂ − x₁), x = x₁ + (r − r₁)/k. Residuals at extra reference points estimate non-linearity. Position error from latency τ at speed v is approximately v·τ.
If the true response is r = k·x + c + b·x(X − x)/X (a bow of size b over span X), a two-point fit at x = 0 and x = X leaves an error that peaks at mid-span, x = X/2, of size b·X/4 in output units.
Line-scan cameras on conveyors trigger exposures from an encoder so latency is constant, then shift the reject actuator's timing by the known delay. Without that, a 50 ms delay at 1 m/s misses the part by 5 cm.
Worked example 1
An IR distance sensor reads 3.1 V at 10 cm and 0.8 V at 40 cm. Assuming linearity between them, what distance does 1.95 V mean?
Gain = (0.8 − 3.1) ÷ (40 − 10) = −0.0767 V/cm. Distance = 10 + (1.95 − 3.1) ÷ (−0.0767) = 10 + 15.0 = 25 cm. Real IR sensors curve, so check a third point.
Worked example 2
A camera pipeline has 80 ms latency and the robot drives at 1.5 m/s. How far does it travel before it can react?
1.5 × 0.080 = 0.12 m: 12 cm before the image even reaches the controller.
Common mix-ups
- Calibrating once at the factory is enough forever.
✓ Sensors drift with temperature, age and mounting. Critical systems re-check calibration regularly. - If a sensor is accurate, its timing doesn't matter.
✓ A late reading of a moving world is wrong by speed × latency, however accurate it was when taken.
6.Practice on your own
Practice, not a test. Wrong answers get a hint and another try.
Practice 2
Using that calibration (200 counts at 0 kPa, 30 counts per kPa), what pressure does a reading of 1700 counts mean, in kPa?
Practice 3
A drone flying at 6 m/s uses an altimeter with 50 ms latency. How far does it move during that latency, in metres?
Practice 4
Why check a third reference point in the middle after a two-point calibration?
Practice 5
A temperature probe takes 20 s to settle after being dipped in hot water. This mostly limits its…
7.Predict
A sensor reads 120 at 0 kg and 920 at 10 kg, and responds in a straight line. What does a reading of 520 mean?
Guess first. Being wrong here is how the surprise works.
8.Reflect
Concepts: How sensors measure · Measurement error and uncertainty