# Camera to IMU on a Robot: The Swing Path, the Time Offset and the IMU's Position

> The camera-to-IMU step of a robot calibration cell: how the swing motion is shaped by motion blur and by what the robot controller does to a dense path, a rotation and time offset from the gyroscope alone, why the time offset moves with exposure, why the IMU's position is the weakest result, and two tested prompts.

Page: https://egocam.ai/robot-cell/camera-imu/

:::note[A record of one build]
Every number on this page was measured on the cell of the [case study](https://egocam.ai/robot-cell/) unless a source is given. It is one cell, one robot and eleven cameras: read it as experience, not as a standard.
:::

After the [stereo solve](https://egocam.ai/robot-cell/the-solve/) the cell knows where the target is in every frame. The camera-to-IMU step uses that to find three things: how the IMU is turned relative to the left lens, the time offset between the IMU's time stamps and the frames', and where the IMU sits. Background on the quantities themselves is on [IMU Calibration](https://egocam.ai/calibration/imu-calibration/) and [Camera-IMU Time Offset](https://egocam.ai/calibration/camera-imu-time-offset/).

In our experience, the three results are not equally hard. The rotation and the time offset came out well from the first real recording and agreed with Kalibr. The position did not, and it is still the weakest number the cell produces.

## The swing path

The camera does not stop in this part of the recording. The robot swings it in front of the target.

| Version | Motion | What happened |
|---|---|---|
| 1 | One axis at a time, 12 degrees and 40 mm at 0.6 Hz, 96 s | 14 to 16 % of frames blurred beyond 0.5 px at 2 ms exposure |
| 2 | All six axes at once, each at its own frequency between 0.8 and 1.6 Hz, small amplitudes, many closely spaced points | Validated on synthetic data. On the real arm the controller blended the points: the camera moved 1 to 2 degrees instead of the planned amplitude |
| 3 | One full pose per half swing, plus or minus 15 degrees and 60 mm around each of three anchor poses | 65 to 80 degrees per second RMS on every axis, 5 to 6 m/s^2; the path in production |

Three things shaped it:

- **Blur comes from angular speed, information about the IMU's position from angular acceleration.** For a swing of amplitude A at frequency f, speed grows with f times A and acceleration with f squared times A. At equal blur a faster, smaller swing tells more.
- **Exposure is the lever on duration.** From an information estimate, the path needed 54 s at 2 ms exposure for 0.5 px of blur, and 17 s at 1 ms. More light on the target means a shorter exposure and a shorter path.
- **The path in production is not sharp.** Version 2 was designed for half a pixel of blur. Version 3 swings at 65 to 80 degrees per second RMS, which at 1.5 ms exposure and a focal length of 618 px is 1.0 to 1.3 px of blur RMS. Tags still decode, and the rotation and time offset do not suffer. The IMU's position is what pays.

And one piece of robot behaviour: a controller that blends corners turns a dense path of small steps into a much smaller motion. A test program that swung one joint with different point spacings showed that with one to three points per swing the arm kept 84 to 92 % of a 10 degree swing.

In our experience, the robot's stand matters here and nowhere else: at full speed the swing shook the base. The path runs at half speed, and the stand was shortened.

## Rotation and time offset from the gyroscope

The camera's angular velocity between two frames, from the target's pose in each, must equal the gyroscope's mean over the same interval, turned by one fixed rotation. For each candidate time offset the best rotation has a closed form; the offset with the smallest residual wins. No accelerometer, no trajectory model.

In our experience, this is robust. On the first camera, at 7 ms exposure with visible blur, it gave the same rotation as Kalibr's camera-IMU calibration to 0.08 degrees and the same time offset to 0.2 ms (minus 3.9 against minus 4.08 ms).

## The time offset moves with exposure

| Recording | Exposure | Time offset (IMU minus camera) |
|---|---|---|
| First camera, no cell lights | 7 ms | minus 3.90 ms |
| Same camera, cell lights, full speed | 1.5 ms | minus 2.00 ms |
| Same, half speed | 1.5 ms | minus 1.95 ms |

In our experience, the offset is a property of the camera and its exposure setting together: the frame's time stamp sits at a fixed place in the exposure, so the middle of the exposure moves when the exposure changes. Store the exposure with the offset, and calibrate at the exposure the camera will be used at, or record the relation.

Across cameras at the same exposure the offset ranged from minus 0.4 to minus 2.0 ms, and one camera gave minus 1.75 ms and minus 0.50 ms in two takes. We have not explained that spread.

## The IMU's position is the weakest result

In our experience, the position needs far better data than the rotation: sharp frames, a stiff base, and strong angular acceleration. At 7 ms exposure our own solve and Kalibr disagreed by about 15 mm. With lights, positions from the swing recordings of four cameras agreed to about 2 mm across the lens axis and 8 mm along it. A second method, from the stop-and-shoot stills (integrating the IMU between two sharp stills), was stable to 0.8 mm under every variation tried on one camera, although about a quarter of the moves, the fast ones, did not fit; it disagreed with the swing recordings by 6 to 11 mm across the axis. Two methods that are each repeatable and disagree with each other is not a result yet.

What helped judge it:

- **The length of gravity.** The fit estimates gravity as a free vector; its length must come out at 9.81 m/s^2. It is an independent check of the accelerometer scale and of the fit.
- **The accelerometer residual against its signal.** When the residual is a large share of the signal, the position is not determined, whatever the printed digits say.
- **The design.** The sensors and the IMU are soldered to one board; across the lens axis the board's drawing must hold.

## The scales, measured

The datasheet named the IMU chip, not the range it was configured to. Both scales were measured against the robot's known motion: 8.192 counts per degree per second and 1024 counts per g.

## The prompt: the solve

- **Inputs:** the target's pose in the left lens for every frame that saw it, the IMU samples on the same clock, the IMU's scales, the exposure.
- **How to check:** the length of gravity is near 9.81; the rotation is close to a design rotation (ours is a half turn about one axis); results from three separate thirds of the recording agree; a second tool agrees on rotation and offset.

```text
Write the camera-to-IMU step of a calibration pipeline and run it on the data here. The stereo
calibration is already done; this step finds how the IMU is turned relative to the left lens, the
time offset between the IMU's clock stamps and the frames', and where the IMU sits.

Data in this directory:
- `poses.json`: for each video frame that saw the calibration board, the frame time in seconds and
  the pose of the board in the left lens's frame (rotation vector and translation in metres), from
  the finished camera calibration. About 60 frames per second; some frames are missing (board not
  detected).
- `imu.csv`: time in seconds, gyro x, y, z and accelerometer x, y, z in raw counts, about 600 per
  second. Scales: [8.192 counts per degree per second, 1024 counts per g].
- The recording starts with a few seconds standing still, then the camera is swung about all axes in
  front of the board.

Method, in this order, because each part needs the one before:
1. Rotation and time offset from the gyroscope alone. The camera's angular velocity between
  consecutive frames (from the board poses) must equal the gyro's mean over the same interval,
  turned by a fixed rotation. For each candidate time offset in a range of [+-60 ms], average the
  gyro over the shifted intervals, fit the rotation in closed form (Kabsch / SVD on the two sets of
  vectors), and keep the offset with the smallest residual; refine the offset to [0.05 ms]. Estimate
  the gyro bias from the still start. Skip intervals that span a missing frame.
2. Position of the IMU (lever arm), gravity and accelerometer bias from the accelerometer. Fit a
  smoothing spline to the camera POSITIONS and differentiate it twice for the camera's acceleration.
  Take the angular rate and angular acceleration from the GYROSCOPE (bias removed, turned into the
  camera frame with the rotation from step 1, lightly smoothed), not from differentiated board
  poses: differentiating orientation twice makes the answer swing by centimetres with the smoothing.
  Then solve the linear least-squares problem in which the measured specific force equals the
  camera's acceleration minus gravity, plus the terms from rotation about the lever arm, plus a
  bias. Report the value at a knot spacing of [0.10] s, repeat for spacings from [0.07 to 0.15] s
  and say how much the lever arm moves: that movement, together with the spread between thirds in
  step 3, is its error bar. The length of the gravity vector must come out near 9.81 m/s^2: print
  it, it is a free check of the accelerometer scale.
3. Honest error bars: repeat step 1 and 2 on three separate thirds of the swinging part of the
  recording (the gyro bias from the still start serves all three) and report the spread. State which
  results you would trust, and to how many millimetres or milliseconds.

Things that will mislead you if ignored:
- report the rotation as R with v_imu = R v_camera (a direction in the left lens's frame turned into
  the IMU's frame), the offset as t_imu = t_camera + offset, and the IMU's position in the left
  lens's frame; write these three conventions into the result file in words;
- the time offset depends on the exposure time of the camera (the frame's stamp sits somewhere
  inside the exposure), so it is a property of the camera AND its settings: store the exposure of
  this recording, [1.5 ms], with it;
- motion blur and a shaking robot base hurt the lever arm long before they hurt the rotation; if the
  accelerometer residual is large compared with the signal, say the lever arm is not determined
  rather than print three digits.

Write `imu_calib.py`, `imu_result.json` (rotation matrix, offset in ms, lever arm in mm, gravity
norm, biases, residuals, per-third values) and print a summary. Then compare with `truth.json` if it
is present and print the errors.
```

## How this prompt was tested

Two fresh AI sessions, each with a synthetic recording with known truth: about 48 s, a still start, swings on all axes up to 70 to 90 degrees per second, 12 % of frames missing, noise on poses and IMU.

The first session got an earlier wording. Its solve matched the truth in rotation and time offset at once, but its IMU position moved by up to 14 mm with the smoothing it chose, because it differentiated the target poses twice for angular acceleration. Taking angular rate and acceleration from the gyroscope removed that. The prompt was rewritten to say so.

The second session got the wording above (two sentences about what to report were tightened from its notes afterwards) and a different recording, and never saw the truth; its result file was scored afterwards.

| | Error of the second session's first attempt |
|---|---|
| Rotation | 0.011 degrees |
| Time offset (truth 3.40 ms) | 0.019 ms |
| IMU position (truth 12, 7 and 18 mm from the lens) | 0.02, 0.22 and 0.05 mm |
| Length of gravity | 9.803 m/s^2 |
| Its own statement of the position's error bar | about 2 mm, from the spread across knot spacings and thirds |

Its own error bar was ten times its actual error, and it declined to call the position determined to a millimetre. On a clean synthetic recording that is cautious. On real recordings it is the right habit: the spread between thirds is what a blurred frame or a shaking base shows up in first.

## The prompt: the swing path

- **Inputs:** the cell model from [Cell model and viewer](https://egocam.ai/robot-cell/cell-model-and-viewer/), the exposure and the focal length in pixels.
- **How to check:** the report's blur percentiles and clearances; in the viewer every target shows the target board in at least one lens; a first run at half speed with someone watching the base.

```text
Plan the robot motion for the camera-to-IMU calibration in the cell modelled in this directory
(`cell/` has the kinematics, the board, the lenses and the collision distances; read and use it;
`inputs.yaml` has the home pose, the joint speeds and the detection limits). In this recording the
camera does not stop: the robot swings it in front of the board so the gyroscope and accelerometer
see motion about every axis while the board stays in view.

What the motion must achieve, and the physics that sets its shape:
- Rotation about all three axes and acceleration along all three, at the same time rather than one
  axis after another: it is shorter and the axes do not hide in each other.
- Motion blur is the price of the motion. Blur in pixels is about (angular speed in rad/s) x
  (exposure in s) x (focal length in px); with exposure [1.5 ms] and focal length [618 px], 60
  degrees per second is about 1 px. Sharp frames (under half a pixel) would need a swing so slow
  that the accelerometer sees almost nothing, so this recording accepts some blur: aim for an RMS
  angular speed of [60 to 90] degrees per second on each axis, and report the RMS and 95th
  percentile of blur that gives. Tags still decode at that blur; the rotation and the time offset
  tolerate it; the IMU's position is what pays, and more light (a shorter exposure) is the only
  thing that buys it back.
- The IMU's position is found from angular ACCELERATION, the blur comes from angular SPEED. For a
  swing of amplitude A at frequency f, speed grows with f A and acceleration with f^2 A, so at equal
  blur a faster, smaller swing tells more. But a robot controller smooths closely spaced points: on
  our arm a path of many small steps came out at a fifth of the planned amplitude. So use few,
  large, well separated targets: one full pose per half swing, about [+-15 degrees and +-60 mm]
  around an anchor pose, and let the controller blend.
- The board must stay detectable through the swing: at least [8] whole tags decodable in the better
  of the two lenses at every target. The swing of [+-15 degrees and +-60 mm] is per camera axis, all
  axes at once and not in step with each other.
- Use [3] anchor poses at different distances and tilts, about [40] targets each at [50] % of the
  datasheet joint speeds (write the speed into the path file per anchor), a pause of [1.5 s] at each
  anchor, and start with a hold of [4 s] at home (the software finds this hold to know where the
  swinging part begins).
- Keep away from the wrist singularity (joint 5 more than [15] degrees from zero): near it small
  camera motions need huge joint speeds.

Safety, for every target and every move between targets, sampled about every degree, using the
collision functions in `cell/` (per link where the limits differ), and including the arm's own links
against each other and against the board and stand: the camera body at least [100] mm from the
robot's base, turret, upper arm and elbow and [60] mm from the forearm; the cable box at least [50]
mm and [20] mm from the same; both at least [150] mm from the board, the stand, the floor and what
the robot stands on; joints inside limits with [5] degrees to spare. If a camera path has already
run on the real arm, use its smallest distances instead.

Write `plan/plan_imu_path.py`, `out/imu_path.json` (`{"anchors": [{"q0": [6 joint angles, degrees,
model convention], "points": [[6 angles], ...]}, ...]}`: the robot goes home, holds, then for each
anchor goes to q0, pauses, visits the points in order, returns to q0; home at the end), and
`out/imu_path_report.md`: per anchor the RMS and peak angular speed and linear acceleration of the
camera on each axis (state the motion profile you assume between targets; a controller that blends
corners moves smoothly through them), predicted blur RMS and 95th percentile, the fewest tags
visible at any target, closest approaches, and total time. Rebuild the viewer with this path. Run a
separate `tests/check_imu_path.py` that fails on any broken margin and print its result.

One more thing to put in the report: run the first test of this path on the real arm at half speed
and watch the base. If the robot's stand shakes, the board poses and the IMU disagree for a reason
no solver can fix.
```

## How the swing-path prompt was tested

A fresh AI session got an earlier wording of this prompt in the directory of a cell model built by another session (see [Cell model and viewer](https://egocam.ai/robot-cell/cell-model-and-viewer/#how-this-prompt-was-tested)). Its path was then scored with the clearance checker and tag counter that the real cell's paths pass.

| | Its path | Our path in production |
|---|---|---|
| Anchors and targets | 3 and 120 | 3 and 117 |
| Fewest whole tags in the better lens at any target | 15 | 17 |
| Rotation between consecutive targets, median | 36 degrees | 27 degrees |
| Rotation axis, share on camera x, y, z | 0.49, 0.46, 0.50 | 0.58, 0.50, 0.51 |
| Camera to forearm, smallest, poses and moves | 77 mm | 85 mm |
| Cable box to forearm | 32 mm | 57 mm |
| Camera to the rest of the robot | 214 mm | 264 mm |
| Camera to the target and stand | 251 mm | 241 mm |
| Joint 5 from zero, smallest | 57 degrees | 36 degrees |
| Time for the swings at half speed | 36 s | 32 s |

A usable path by every measure we score, inside the clearances of our proven camera path.

It also caught a contradiction in the prompt, and in this page as first written. The earlier wording asked for blur under 0.5 px and for swings of 15 degrees at half speed. It computed that the two cannot both hold: at that speed the blur is several times the limit, and at the speed that meets the limit the accelerometer sees almost nothing. It was right, and the same is true of our own path, which is why the paragraph above about the path not being sharp exists. The prompt now states the trade as we really made it.

## Sources

- [Kalibr wiki: camera-IMU calibration](https://github.com/ethz-asl/kalibr/wiki/camera-imu-calibration) — ETH Zurich ASL, software documentation.
- [Unified temporal and spatial calibration for multi-sensor systems](https://doi.org/10.1109/IROS.2013.6696514) — Furgale, Rehder and Siegwart, IROS 2013.
- [Least-Squares Fitting of Two 3-D Point Sets](https://doi.org/10.1109/TPAMI.1987.4767965) — Arun, Huang and Blostein, IEEE TPAMI 1987; the closed-form rotation fit.
