Two sensors on one robot never share a spot or a clock. Stamp a LiDAR 10 ms late and, at 30 m/s, its points land 30 cm behind the car the camera sees. At rest the same error is zero.
Drag the speed and pick how the rig keeps its clocks. Watch the warm LiDAR points slide off the blue camera box. Then we build it piece by piece: each sensor's own numbers, the mount, the time offset, the sync hardware, and the motion that makes it all measurable.
You need a rotation as a 3 by 3 matrix and a little arithmetic. We build the rest from zero.
Lesson 15 of 22 in Sensor Fusion: Classical to Modern. It follows INS/GNSS Coupling and leads to Visual-Inertial Odometry.
Illustrative: gap = speed × offset. 10 ms stands for an unsynced driver delay (illustrative). 0.5 ms is the size of the online estimate's error in Qin and Shen's simulations (RMSE 0.36 to 0.68 ms). 1 µs stands for PTP, which IEEE 1588 rates in the sub-microsecond range.
Chapter 0
See how a wrong mount or a late clock grows with motion and hides at rest
You build a camera and IMU filter. The equations check out and you tuned the noise. On the robot, the estimate drifts whenever the robot turns fast. When it stops, the drift stops. You check the filter again. It is fine.
Every lesson so far assumed that two readings arrive in one frame and on one clock. Real sensors give neither. Each one sits at its own place on the robot and keeps its own clock. Two unknowns decide whether fusion works:
Calibration is the job of finding them. Each sensor also has private numbers, its intrinsics, which Chapter 1 covers.
The rig carries an IMU and a camera. Set a mount error and a clock error, then turn the rig faster. Both errors are lines through zero.
Illustrative: exact small-error formulas. Phantom velocity is turn rate times mount error. Image error is focal length (500 px) times turn rate times clock offset, for a feature near the image centre.
How big is the error? Call the speed of the thing you measure v, and the time offset t-d. A reading stamped t-d late shows the world as it was t-d earlier. So it is off by the distance moved in that time.
e equals v times t-d.
Multiply the speed v by the offset t-d. That is how far the world moved between the real instant and the stamp.
A car passes at v = 30 m/s and the LiDAR stamps run t-d = 10 ms late: e = 30 × 0.010 = 0.30 m. A camera with a 500 px focal length turns at 1 rad/s, so a feature near the centre moves at about 500 px/s. With t-d = 5 ms, e = 2.5 px. At rest v = 0, so e = 0.
A wrong mount acts the same way. Say you believe the camera sits on the IMU, but it sits 2 cm away. A turn moves the camera on a circle, at a speed the filter never predicted.
phantom speed = turn rate × mount error = 1 rad/s × 0.02 m = 0.02 m/s
Chapter 1
Turn raw pixels and counts into units before you place one sensor against another
Intrinsic calibration maps one sensor's raw output to physical units. It never mentions another sensor. Do it first, because every later step assumes clean units.
A camera's intrinsics say how a ray becomes a pixel. Take a point in front of the camera at sideways position X, height Y and depth Z, in camera axes. Divide by the depth to get the normalised coordinates x = X/Z and y = Y/Z. Call r² = x² + y² the squared distance from the image centre. Real lenses bend rays more near the edge; the radial distortion coefficient k-1 says how much.
u equals c-x plus f-x times x times, one plus k-one r squared.
Divide the sideways position by the depth to get x. Bend it by one plus k-one r squared. Scale by the focal length f-x and shift by the principal point c-x. The row v follows the same rule with f-y, c-y and y.
With made-up numbers: f-x = 500 px and c-x = 320 px. A point at the corner of a 640 by 480 image has x = 0.64 and y = 0.48, so r² = 0.64. With k-one = −0.2 the bend is 1 − 0.128 = 0.872, and u = 320 + 500 × 0.64 × 0.872 = 599 px. Ignore the distortion and you expect 640 px: 41 px off in u, 51 px off along the radius.
The dashed grid is what a perfect pinhole would see. Blue is what the lens records. Drag k-one, then switch on the correction.
Illustrative: a 640 by 480 camera, focal length 500 px, centre (320, 240), one radial term. Real models add k-two, k-three and two tangential terms.
Zhang's method (2000) finds the focal length, centre and distortion from photos of a flat checkerboard in a few poses, at least two. It starts from a closed-form answer, then refines it by maximum likelihood.
The IMU has private errors too, one set per axis. A bias b is an offset at rest. A scale factor error s puts the reading off by a fraction. Misalignment means the axes are not exactly square. For one axis, call the true rate x and the reading m.
m = (1 + s) · x + b · s = 0.005: a 360°/s spin reads 361.8°/s, 1.8°/s too much
Lesson 13 removed the turn-on bias by averaging at rest. A scale factor needs motion of a known size, such as a rate table or a measured full turn.
Chapter 2
Move a point from one sensor's axes to another's, and see which error matters near and far
Extrinsic calibration finds the rigid transform between two sensors: how sensor A's axes turn relative to sensor B's, and where A's origin sits in B's axes. A car's LiDAR and camera are the clear case. To paint a LiDAR point onto the image, you move it into camera axes, then project it with the intrinsics of Chapter 1.
Call a point in sensor A's axes p-A, and the same point in sensor B's axes p-B. Call the rotation from A's axes to B's axes R, a 3 by 3 matrix. Call the position of A's origin in B's axes t.
p-B equals R times p-A, plus t.
Turn the point p-A with R so it uses B's axes. Then shift it by t. Six numbers fix R and t: three angles and three distances.
With made-up numbers: p-A = (1.0, 0.5, 20.0) m, R a 1° turn about the vertical axis, t = (0.10, −0.05, 0.02) m. Then p-B = (1.449, 0.450, 20.000) m. Leave out the 1° and the point projects 8.8 px too far left with a 500 px focal length.
The blue bar is the pole in a zoomed camera view. Warm dots are LiDAR returns from the pole, moved with your mount. Add a rotation or a translation error, then move the pole near and far.
Illustrative: focal length 500 px, both errors sideways and in the same direction. Exact projection, so the two shifts add.
The two errors behave differently. A rotation error shifts every point by about f × tan(angle) pixels at any depth. A translation error shifts a point at depth Z by f × error / Z, so it fades with distance.
0.5°: 500 × tan 0.5° = 4.4 px at every depth · 5 cm: 500 × 0.05 / 2 = 12.5 px at 2 m, 1.3 px at 20 m
So check the rotation on far targets and the translation on near ones. For a camera and an IMU, the translation is the lever arm. It sets the phantom speed of Chapter 0.
Chapter 3
Compare how two bolted sensors each see one motion, and solve for the bolt
A ruler cannot measure millimetres and fractions of a degree inside a robot. But a bolt holds the two sensors together, so they move as one. Each reports the same motion in its own axes, and that is enough to recover the bolt.
Write every pose and motion as a rigid transform: a rotation plus a translation. Call sensor A's motion between two instants A. Call the same motion, as sensor B reports it, B. Call the unknown pose of B in A's axes X.
Now go from B at the end back to A at the start. Move with A, then step across to B. Or step across first, then move with B. Both routes reach the same place.
A times X equals X times B.
Chain A with X, and chain X with B. The two chains must match for every motion. Record several motions and find the one X that makes all of them match best.
Rotations only: let R-X be a 90° turn about z. A turn about A's axis (1, 0, 0) shows in B about (0, −1, 0). Check: R-X turns (0, −1, 0) into (1, 0, 0), so the axes match through the mount.
Split each transform into a rotation R and a translation t, and the equation splits in two. Call the turn axis of A's motion α (alpha) and of B's β (beta), each as long as its angle. I is the identity matrix.
rotation: RA RX = RX RB, so α = RX β
translation: (RA − I) tX = RX tB − tA
Solve the rotation first: find the R-X that best lines up every α with its β. The translation line is then linear in t-X: stack it over all motions and solve. Tsai and Lenz (1989) gave this rotation-first split; Park and Martin (1994) gave a closed-form least-squares rotation.
Each press records one motion seen by both sensors. Top: the fitted mount's rotation error; bottom: its translation error. Add varied turns, then reset and try turns about z.
Illustrative toy: true mount 90° about z and (5, −2, 10) cm. Each motion turns 0.5 to 1 rad, with 0.01 rad and 2 mm of noise per sensor.
Over 200 seeded runs of this toy, the median rotation error is 1.1° after 5 varied motions and 0.33° after 40; the translation error falls from 6.4 mm to 1.4 mm. With turns about z only, the error stays near 90°.
The Code Lab solves the rotation the Tsai and Lenz way: one linear constraint per motion, skew(α + β) x = β − α, then x back to R-X.
Chapter 4
Slide one sensor's rate signal against the other's and read the lag at the peak
Every reading carries a timestamp, and the stamp is not the instant the sensor sampled. Triggering, transfer and a separate clock all add delay. Qin and Shen (2018) define the time offset t-d by t-IMU = t-cam + t-d: the amount to add to the camera stamps so that the two streams agree.
Both sensors see the same rotation. The gyro measures the turn rate directly. The camera gives it too: track features between frames and work out how far the camera turned. Compare the size of the rate, not its direction, so the unknown mount rotation does not matter. If the camera stamps are late, its curve is the gyro's curve shifted to the right.
Warm is the gyro's turn rate, blue is the camera's. Drag the shift until the curves line up and the pink score peaks. Then make the motion gentle.
Illustrative toy: 20 s of motion, gyro at 200 Hz, camera rate at 30 Hz, true offset 25 ms, small noise on both. The score is the normalised correlation. Gentle motion is the same path at one tenth of the speed.
Call the gyro's rate size g, the camera's rate size h, the camera stamps t-k, and a trial shift tau. Score each shift by how well the curves agree, and keep the best.
t-d-hat equals the tau that makes largest the sum over k of g at t-k minus tau, times h at t-k.
For a trial shift tau, read the gyro curve g tau earlier than each camera stamp t-k. Multiply by the camera value h and add the products. The shift with the biggest total lines the curves up. That shift is t-d-hat.
With made-up numbers: g = 0, 1, 3, 1, 0, one sample every 10 ms, and h is the same curve one sample late: 0, 0, 1, 3, 1. Shift 0 scores 6. Shift 10 ms scores 0×0 + 1×1 + 3×3 + 1×1 = 11. Shift 20 ms scores 6. The peak says t-d-hat = 10 ms.
In practice, subtract each curve's mean first and divide by their sizes, so the score runs from −1 to 1. Over 100 seeded runs of this toy, the mean is 25.0 ms and the spread 0.6 ms. At one tenth of the motion the spread grows to 7.8 ms. Motion is the signal.
The Code Lab scores shifts by the sum of squared differences and keeps the smallest. For curves of fixed size this picks the same shift, because (a − b)² = a² − 2ab + b², and only the product term depends on the shift.
Chapter 5
Let a batch fit or a running filter estimate the offset with everything else
The slide finds one number from a special recording. Two well-known tools go further. They estimate the offset inside the same fit that estimates the motion and the mount.
Kalibr (Furgale, Rehder and Siegwart, 2013) is a batch method. It writes the rig's trajectory as a B-spline: a smooth curve built from a few control points, which you can read at any instant. Kalibr compares each measurement with the curve at its own stamp plus the offset. Changing the offset only moves where the curve is read. So the offset becomes one more unknown in a maximum-likelihood fit, next to the extrinsics. The curve idea comes from Furgale, Barfoot and Sibley (2012).
The online method in VINS-Mono (Qin and Shen, 2018) runs while the robot moves. Over a few milliseconds a feature moves at nearly constant speed across the image. So a late stamp is the same as a small slide of the feature along its own velocity. Call a feature's measured pixel position z, its velocity in the image V, and the offset t-d.
z of t-d equals z plus t-d times V.
Measure how fast the feature moves in the image, V. Multiply by the offset t-d and add it to the measured position z. The estimator adjusts t-d, like any other state, until camera and IMU agree.
V = 200 px/s and t-d = 10 ms: the feature slides 2 px. Qin and Shen simulated an IMU at 100 Hz and a camera at 10 Hz, 100 trials per offset. True offsets of 5, 15 and 30 ms came out as 5.12, 15.06 and 30.17 ms, with RMSE 0.36 to 0.68 ms.
The estimator starts from 0 ms with a wide purple band. The dashed line is the true offset, 10 ms. Run it with rich motion, then with slow motion.
Illustrative: a one-state recursive least-squares filter. Each camera frame, 30 a second, gives 4 features with 0.5 px noise. Rich motion moves features at about 60 px/s, slow motion at about 1 px/s, as on a hovering drone. Prior: 0 ms with a standard deviation of 20 ms.
Rich motion pins the offset to under 1 ms within about a second. Slow motion leaves the band wide: a 1 px/s feature slides only 0.01 px for a 10 ms offset, far below the 0.5 px noise.
Chapter 6
Trigger, pulse and exchange timestamps so the offset is near zero before software runs
Estimation removes a constant offset. It cannot remove jitter, a delay that changes from sample to sample. A software stamp, taken when the data reaches the computer, carries the whole driver and bus delay, and that delay varies. The cure is to stamp the data at the sensor, against one shared clock. Three tools do it:
PTP rests on four timestamps. The master sends a message at t-1 on its own clock, and the slave receives it at t-2 on the slave's clock. The slave replies at t-3, and the master receives the reply at t-4. Assume the trip takes the same time each way. Call the slave clock minus the master clock theta.
theta equals, t-two minus t-one, minus, t-four minus t-three, all over two.
The outbound gap t-two minus t-one is delay plus offset. The return gap t-four minus t-three is delay minus offset. Subtract the second from the first: the delay cancels and two thetas remain. Halve it.
With made-up numbers: t-1 = 0, t-2 = 150, t-3 = 300 and t-4 = 250 µs. The outbound gap is 150 and the return gap is −50. Theta = (150 + 50) / 2 = 100 µs, and the one-way delay is (150 − 50) / 2 = 50 µs.
The left line is the master's clock, the right line the slave's. Pink arrows are the two messages. Set the true clock offset, then make the path slower one way than the other.
Illustrative: a mean one-way delay of 50 µs and a 150 µs pause before the reply. Asymmetry makes the outbound trip longer and the return shorter by half the amount each.
If the path takes 60 µs out and 40 µs back, the estimate is off by (60 − 40) / 2 = 10 µs. Half of any asymmetry lands in theta, and nothing in the four stamps can reveal it. That is why PTP networks use switches that stamp packets in hardware.
A camera adds one more delay: the exposure. Qin and Shen found the estimated offset grows with exposure time at a slope of about 0.5, because the best instant to stamp an image is mid-exposure. With a 20 ms exposure, that is 10 ms of offset.
Chapter 7
Match each unknown to the motion that reveals it, and read the spread, not only the answer
A parameter is observable when changing it would change the data. If no measurement would notice the change, the data cannot tell you its value. The solver still prints a number, filled by noise or by your first guess.
For the offset, the information comes from motion. A late stamp slides each feature by the offset times its velocity (Chapter 5). If features barely move, the slide hides inside the pixel noise. Call the pixel noise sigma-z, the typical feature speed V, and the number of feature measurements N.
sigma-t-d equals sigma-z over, V times the square root of N.
Divide the pixel noise sigma-z by the feature speed V: that is the offset one measurement can resolve. Average N measurements and the spread shrinks by the square root of N.
sigma-z = 0.5 px and N = 1,000, so root N = 31.6. At V = 100 px/s, sigma-t-d = 0.5 / (100 × 31.6) = 0.16 ms. At V = 5 px/s it is 3.2 ms. A seeded simulation of the first case gives 0.157 ms.
Every unknown has a motion that reveals it, and a motion that hides it:
| Motion | What stays hidden | Why |
|---|---|---|
| Still | the offset and the mount rotation | nothing changes, so there is nothing to compare |
| Glide on a rail | the mount rotation, and the offset | no turns; at constant speed a time shift looks like a fixed position shift |
| Turns about one axis | the mount's turn about that axis | both sensors agree on that axis whatever the mount (Chapter 3) |
| Full motion | nothing | turns about all three axes, moves along all three, at changing speed |
Each purple bar is the spread of one unknown, on a log scale. The green line is good enough. Pick a motion and record for 60 s.
Illustrative information model. Each second adds one turn of 0.8 rad; its axis pair informs the two mount angles across that axis (0.014 rad of combined noise). When the motion changes speed, each second also adds 30 frames of 20 features at 150 px/s with 0.5 px noise. Prior: 5° and 20 ms. Good enough: 0.2° and 0.5 ms.
Chapter 8
Pick the motion, the length and the stamps, then read the report card and the speed test
Here is a camera and IMU session in miniature. The toy rig hides a mount, 90° about z and (5, −2, 10) cm, and a time offset of 25 ms. You choose how to move it, for how long, and where the stamps come from.
Run a session. The toy fits the mount with the least-squares fit of Chapter 3 and finds the offset with the slide of Chapter 4. The report card shows each error against a target: under 1° for rotation, under 1 cm for translation, under 1 ms for the offset.
Then it validates. It turns the rig faster and faster, applies the calibrated values, and plots the image error left over. A flat line means the calibration holds at speed. A line that climbs with speed means a leftover offset. A line that starts high means a leftover mount error.
Top: the three errors against their targets. Bottom: leftover image error against turn rate. Start with the rail, then try one axis, then full motion, then shorten it.
Illustrative toy: one motion every 2 s for the mount fit (same noise as Chapter 3) and a gyro at 200 Hz with a camera at 30 Hz for the lag search. Driver stamps add 4 ms of random jitter per frame. Validation residual: f × tan(rotation error), plus f × turn rate × offset error, plus the lever-arm term over 0.1 s for features at 3 m. f = 500 px, noise 0.3 px.
With full motion for 60 s and stamps at the sensor, every bar lands under its target and the validation line stays flat. The rail leaves both the rotation and the offset unknown. One axis finds the offset but not the mount's turn about z. Switch to driver stamps: the offset still comes out right on average, but the speed test fans out, because jitter changes every frame.
Chapter 9
Name the calibration fault from how the residual changes with speed and with time
Every calibration fault looks like a filter that is a bit off. Their shapes differ. Plot the residual against speed, and against time, and each fault shows its own fingerprint.
Each choice plants one fault in a 10-minute log. Dots are residuals, the line is the trend. Switch the axis between turn rate and time.
Illustrative faults: a 5 ms offset, a 0.3° mount rotation, or a mount that creeps 0.4° as the rig warms. The lever arm is 3 cm, seen as phantom speed over 0.1 s for features 1 to 4 m away. Focal length 500 px, 0.3 px noise.
A time offset gives a line through zero. Its slope gives the offset back:
1.5 px at 0.6 rad/s and 3.0 px at 1.2 rad/s: slope 2.5 px per rad/s, so t-d = 2.5 / 500 px = 5 ms
| Fingerprint | Cause | Fix |
|---|---|---|
| Zero at rest, a straight line with speed | time offset | estimate t-d (Chapter 4), stamp at the sensor |
| A constant offset at every speed | mount rotation | refit with turns about several axes |
| Grows with turn rate, larger for near features | lever arm (mount translation) | refit t-X with near targets and turns |
| Fine when cold, worse with time or heat | thermal or mechanical drift | online calibration, a stiffer mount |
| A huge variance on one parameter | too little excitation | recalibrate with full motion |
| Random, centred, flat with speed | real sensor noise | the only case where you tune the noise covariances |
Chapter 10
Keep the equations, the numbers, the checklist and the code in one place
Fusion assumes one frame and one clock, and calibration earns that assumption. Intrinsics turn each sensor's raw output into units. Extrinsics place one sensor in the other's axes, read from motion through AX = XB. You find the time offset by sliding rate signals, estimate it as a state, or remove it with hardware stamps. None of it works without the motion that makes it observable.
| Quantity | Formula | Numbers from this page |
|---|---|---|
| Error from an offset | e = v · td | 30 m/s, 10 ms: 30 cm; 500 px/s, 5 ms: 2.5 px |
| Lever-arm speed | turn rate × mount error | 1 rad/s, 2 cm: 2 cm/s |
| Pinhole with distortion | u = cx + fx x (1 + k1 r²) | corner, k-one −0.2: 599 px, not 640 |
| Extrinsic transform | pB = R pA + t | 1° left out: 8.8 px at 20 m |
| Hand-eye | A X = X B | toy: 1.1° after 5 motions, 0.33° after 40 |
| Lag search | t̂d = argmaxτ Σ g(tk − τ) h(tk) | toy: 25.0 ms, spread 0.6 ms |
| Offset as a state | z(td) = z + td V | 200 px/s, 10 ms: 2 px |
| PTP offset | θ = ((t2 − t1) − (t4 − t3)) / 2 | 100 µs; 20 µs asymmetry: 10 µs error |
| Offset spread | σtd = σz / (V √N) | 0.16 ms at 100 px/s; 3.2 ms at 5 px/s |
pythonimport numpy as np def estimate_td(t_imu, gyro_rate, t_cam, cam_rate, taus): # slide the gyro curve; keep the shift with the best normalised correlation b = cam_rate - cam_rate.mean() def score(tau): a = np.interp(t_cam - tau, t_imu, gyro_rate); a = a - a.mean() return a @ b / np.sqrt((a @ a) * (b @ b)) return taus[np.argmax([score(t) for t in taus])] # t_IMU = t_cam + t_d def fit_mount(alphas, betas, RAs, tAs, tBs): # rotation: least-squares R with alpha_i = R beta_i (Park and Martin; SVD form) M = sum(np.outer(b, a) for a, b in zip(alphas, betas)) U, S, Vt = np.linalg.svd(M) D = np.diag([1, 1, np.sign(np.linalg.det(Vt.T @ U.T))]) R = Vt.T @ D @ U.T # translation: stack (R_A - I) t_X = R t_B - t_A and solve by least squares C = np.vstack([RA - np.eye(3) for RA in RAs]) d = np.hstack([R @ tB - tA for tA, tB in zip(tAs, tBs)]) t, *_ = np.linalg.lstsq(C, d, rcond=None) return R, t, S # a tiny last value in S means a degenerate (one-axis) data set
| System | What it needs | How teams find it |
|---|---|---|
| Visual-inertial odometry | camera intrinsics, camera to IMU mount, t-d | a Kalibr-style batch run, then online refinement |
| Self-driving sensor rigs | every LiDAR, camera and radar mount; one clock | targets or scene edges; PTP or PPS with hardware stamps |
| Headsets | camera to IMU mounts and offsets | factory calibration, then online tracking of flex and heat |
| Robot arms with cameras | camera to gripper mount | hand-eye AX = XB at setup, again after a bump |
Now press Present or Teach and derive the seven equations from memory, from the error of an offset to the offset spread. Then go back to the car and say why the gap vanishes at rest.
Lesson 15 of 22 in Sensor Fusion: Classical to Modern on Engineermaxxing. The methods follow the papers above. Every toy number on this page carries the word illustrative.