Skip to content

C202 Lab: Measure Your IMU and Calibrate It to the Cameras

This lab measures your rig’s IMU and ties it to the cameras. Part A records the IMU sitting still and turns the log into Kalibr’s imu.yaml. Part B records the rig moving in front of the target and runs Kalibr’s camera–IMU calibration, which gives the transform between IMU and cameras and the time offset between their clocks.

Every command below is copied from the tool’s own documentation, or follows its documented form with your own file names; the source is linked at each step. Where a behaviour is stated from a tool’s source code, the file and commit are named. Square brackets mark values you fill in.

Work through Lessons 1 to 4 first, finish the C201 lab for your cameras, and keep the checklist next to you.

Part A takes hours of recording. Start it first, and work on the Part B preparation while it runs.

The allan_variance_ros README says the tool “is designed for Ubuntu 20.04”, and offers a devcontainer for other systems. Put the repository in the src folder of a ROS 1 catkin workspace, such as ~/catkin_ws/src/allan_variance_ros, then from the workspace folder:

Terminal window
catkin build allan_variance_ros
source devel/setup.bash

You should see the package build without errors. The README’s other route, for systems that are not Ubuntu 20.04, is its devcontainer (.devcontainer/README.md in the repository).

  • Configure the IMU exactly as you will record with it: the same output rate and the same filter settings. Write them down. Lesson 4 shows that the filter changes the time offset; the noise belongs to one configuration too.
  • Let it warm up. To the best of our knowledge, it is best to start the log once the rig has reached its working temperature, because a bias still settling shows up as a trend, not as noise (Temperature and the limits of a static plot).
  • Put it on a damped surface where nothing will touch or bump it for the whole recording. The README: “Place your IMU on some damped surface and record your IMU data to a rosbag.” Any vibration that reaches the IMU ends up in the Allan plot as if it were sensor noise.

Start roscore in one terminal, as the README’s first step says, and the IMU driver. Then record only the IMU topic, in the form the ROS rosbag command line page gives (-O names the bag, --duration stops it):

Terminal window
rosbag record --duration=[HOURS]h -O imu_static.bag [IMU_TOPIC]

How long: the README says “You must record at least 3 hours of data. The longer the sequence, the more accurate the results.” The Kalibr wiki recommends a “~15-24 hour dataset recording of the IMU being stationary” (IMU noise model). Lesson 2’s table shows why: the random walk comes from the long-τ end, where a 3-hour log is uncertain.

Checkpoint: rosbag info imu_static.bag gives the bag’s duration and message count (rosbag command line).

You should see a duration of at least the length you planned, the IMU topic at close to its nominal rate, and a message count close to the IMU rate times the duration. A count well short of that means dropped samples; record again.

The README recommends this step:

Terminal window
rosrun allan_variance_ros cookbag.py --input original_rosbag --output cooked_rosbag

With your file names, --input imu_static.bag --output imu_static_cooked.bag. The script rewrites each message at its header timestamp (scripts/cookbag.py, commit 1d54b60). The Allan computation averages consecutive samples, so they must be in the order they were sampled (Temperature and the limits of a static plot).

Write a config file in the format of the repository’s examples (config/*.yaml):

imu_topic: "[IMU_TOPIC]"
imu_rate: [IMU_RATE_HZ]
measure_rate: [IMU_RATE_HZ] # Rate to which imu data is subsampled
sequence_time: [RECORD_LENGTH_S]

What the source does with these keys (src/AllanVarianceComputor.cpp, commit 1d54b60):

  • measure_rate sets a subsampling step of imu_rate / measure_rate. Some example configs subsample (400 to 100 Hz); config/sim.yaml does not. To the best of our knowledge, keeping measure_rate equal to imu_rate avoids the subsampling caveat of Kalibr’s noise model (Lesson 2).
  • sequence_time caps how many seconds of the log are read: samples after it are skipped. Set it to your record length.
  • Gyroscope units. The source reads the gyroscope values as radians per second, as ROS IMU messages carry them, and converts them to degrees for its output (a comment at the conversion says so).

Put the cooked bag alone in a folder: the tool lists the .bag files in the folder and processes only the first of them (src/allan_variance.cpp). Then run, as the README gives it:

Terminal window
rosrun allan_variance_ros allan_variance [path_to_folder_containing_bag] [path_to_config_file]

You should see progress messages as the log is read, and allan_variance.csv written into the bag’s folder. The source evaluates averaging times from 0.1 s to about 1,000 s.

Run the analysis, passing the config so the topic and rate go into the output file:

Terminal window
rosrun allan_variance_ros analysis.py --data allan_variance.csv --config [path_to_config_file]

The README says to press the space bar to go to the next figure. The script prints, per axis, the white noise (velocity or angle random walk), the bias instability and the random walk, saves acceleration.png and gyro.png, and writes imu.yaml (--output changes the name).

Work through Lesson 2:

  1. The shape. A falling −½ stretch at short τ, a flat bottom, and a rising stretch. Slope −1 at the very start is quantization; a slope towards +1 at the right end is a trend, such as warm-up (Failure cases).
  2. The fitted lines. In analysis.py (commit 1d54b60), the −½ line is fitted to τ below 10 s and the +½ line to the whole curve, not just the rising branch. Check by eye that each line follows the part of the curve it stands for.
  3. The axes. Compare the three axes of each sensor. If one disagrees, note it.
  4. Which axis went into the file. Since commit 7a3a461 (October 2022, message Use worst axis instead of average and support overlapping bins), analysis.py writes the largest of the three axes’ values into imu.yaml, not their mean (np.amax). The example imu.yaml in the README matches the three-axis mean, so it predates that change. Read the printed per-axis values next to the file.
  5. The datasheet. Convert the datasheet’s noise figures and compare (Getting the values from a datasheet). A measured value can differ in either direction (IMUs on Wearable Rigs).
Reading IMU noise from an Allan deviation plot A log-log plot of Allan deviation against averaging time for a stationary IMU. The curve falls with slope minus one half where white noise dominates, flattens at a minimum called the bias instability, then rises with slope plus one half where bias random walk dominates. The white-noise density is read from the falling line at an averaging time of 1 second, and the random walk from the rising line at 3 seconds. white noise: read at τ = 1 s bias instability (the minimum) random walk: at τ = 3 s slope −½ slope +½ 0.010.1110100100010000 Averaging time τ (seconds, log scale) Allan deviation (log)
An Allan deviation plot from hours of a stationary IMU. White noise is read on the falling line at τ = 1 s (Kalibr's noise density) and rate random walk on the rising line at τ = 3 s (Kalibr's random walk). The flat minimum is what Woodman and allan_variance_ros report as bias instability; by the IEEE 952 derivation the coefficient B is that minimum divided by 0.664.

Start from the generated file and check every key against the YAML formats page:

#Accelerometers
accelerometer_noise_density: [VALUE] #Noise density (continuous-time)
accelerometer_random_walk: [VALUE] #Bias random walk
#Gyroscopes
gyroscope_noise_density: [VALUE] #Noise density (continuous-time)
gyroscope_random_walk: [VALUE] #Bias random walk
rostopic: [IMU_TOPIC] #the IMU ROS topic
update_rate: [IMU_RATE_HZ] #Hz (for discretization of the values above)
  • Units: gyroscope values in radians, not degrees.
  • update_rate is the rate the IMU really runs at in the Part B bag, and rostopic is its topic there.
  • Inflation. Decide a factor. The Kalibr wiki: “for lowest-cost sensors, increasing the noise model parameters by a factor of 10x or more may be necessary” (Inflating the noise values). Save the raw file as imu_allan.yaml and the inflated one as imu.yaml, and write the factor down. Step B5 tells you whether it fits.
  • [calib]-camchain.yaml and target.yaml from the C201 lab, for the same cameras at the same resolution and focus.
  • imu.yaml from A7.
  • Kalibr, set up as in C201 lab step 1, with your data folder mounted at /data.
  • Exposure short and fixed, in good, even light. The camera–IMU guide asks to “keep the motion blur low” with “low shutter times” and “good illumination”. A fixed exposure also keeps the time offset fixed during the recording (Lesson 4).
  • The IMU in its production configuration, the same as in A2.
  • Rates. The guide reports that “Good results have been obtained by using a camera rate of 20 Hz and an IMU rate of 200 Hz.” Use your rig’s real IMU rate; it must match update_rate.

Fix the target to a wall or table; it must not move. Record the image topics and the IMU topic together:

Terminal window
rosbag record -O imu_cam.bag [CAM0_TOPIC] [CAM1_TOPIC] [IMU_TOPIC]

If your recorder writes files instead, build the bag with kalibr_bagcreater from cam0/, cam1/ and an imu0.csv with the header timestamp,omega_x,omega_y,omega_z,alpha_x,alpha_y,alpha_z, in “timestamps=[ns], omega=[rad/s], alpha=[m/s^2]” (bag format):

Terminal window
kalibr_bagcreater --folder dataset-dir/. --output-bag awsome.bag

The motion (Lesson 3):

  • Start with the rig at rest, then pick it up gently: “avoid shocks, especially at the beginning/end when you pick up the sensor”. Why: Kalibr workflow, step 7.
  • Keep the target in view of the cameras throughout. Kalibr’s only visual measurements are the target’s corners, so a frame without it ties nothing to the cameras.
  • Rotate about every axis and translate along every axis: “try to excite all IMU axes (rotation and translation)”. Not only pans.
  • Move briskly but smoothly. For scale, Furgale and colleagues’ recordings were “about 90 seconds”, at “an average absolute angular velocity of about 55° s−1”.
  • Put the rig down gently at the end.

Checkpoint: rosbag info imu_cam.bag.

You should see each image topic and the IMU topic, and an IMU message count close to the IMU rate times the duration.

Inside the container, in the form of the guide’s example:

Terminal window
rosrun kalibr kalibr_calibrate_imu_camera \
--target /data/target.yaml \
--imu /data/imu.yaml \
--imu-models calibrated \
--cam /data/[calib]-camchain.yaml \
--bag /data/imu_cam.bag

Use --imu-models scale-misalignment if the IMU’s scale and misalignment have not been corrected. For a rig with two IMUs, give both files and both models, the reference IMU first: --imu /data/imu0.yaml /data/imu1.yaml --imu-models calibrated calibrated (Multi-IMU and IMU intrinsic calibration).

You should see four files when it finishes: imu_cam-camchain-imucam.yaml, imu_cam-imu.yaml, imu_cam-results-imucam.txt and imu_cam-report-imucam.pdf (The files at a glance).

Open the report and the results file and work through Lesson 3:

  1. IMU timing. The measurement-rates page is a flat line at the expected rate. “Inspect the IMU time dt plot carefully in the PDF report!” (RealSense tutorial). If it shows bursts and gaps, stop: fix the timestamps before anything else.
  2. IMU residuals inside the dashed ±3σ lines, for the accelerometer and the gyroscope.
  3. Biases inside their ±3σ bounds.
  4. Reprojection errors inside the 3σ circle, and comparable to the camera calibration’s.
  5. Normalised residuals in the results file: compare them with the noise you assumed.

If a check fails: residuals far outside the lines mean the noise values are too small or the data is bad: raise the inflation or check the timestamps. Biases leaving their bounds mean “your trajectory was too dynamic, or your noise values are not good”. Change one thing at a time and solve again.

In the results file, T_ci takes IMU coordinates to camera coordinates, so its translation is where the IMU sits in that camera’s frame, in metres (How Kalibr names transforms). Compare it with a caliper measurement or the mechanical drawing: “Sanity check your final rotation and translation with hand-measured values.” The rotation part should match how the IMU is mounted; its entries are close to 0 or ±1 if it is mounted square to the camera.

The transforms in a Kalibr camchain-imucam.yaml Three coordinate frames: the IMU, cam0 and cam1. An arrow from the IMU to cam0 is labelled T_cam_imu stored under cam0, meaning it takes a point in IMU coordinates to cam0 coordinates. An arrow from cam0 to cam1 is labelled T_cn_cnm1 stored under cam1, which equals T_c1_c0 and takes a point in cam0 coordinates to cam1 coordinates. A third arrow from the IMU to cam1 is labelled T_cam_imu stored under cam1. The rule printed below: T_a_b takes a point expressed in frame b and returns it expressed in frame a. IMU (imu0) cam0 cam1 cam1: T_cn_cnm1 = T_c1_c0 cam0 coordinates to cam1 cam0: T_cam_imu cam1: T_cam_imu T_a_b takes a point in frame b and returns it in frame a
How Kalibr names its transforms. T_a_b takes a point given in frame b and returns it in frame a. Each camera block in camchain-imucam.yaml stores T_cam_imu (IMU to that camera), and every camera after cam0 stores T_cn_cnm1 (the previous camera to this one, so cam1 holds T_c1_c0).

Find the line timeshift cam0 to imu0: [s] (t_imu = t_cam + shift) in the results file, and timeshift_cam_imu in camchain-imucam.yaml (Lesson 4).

  1. Read the sign. Negative: the camera’s timestamps are late relative to the IMU’s. Positive: the IMU’s are late.
  2. Compare it with how your timestamps are made. Do the frames carry the start, middle or end of exposure? Does the IMU have a filter delay? The table of causes gives measured sizes for each.
  3. Cameras on one clock should agree. On a stereo pair triggered together, the two cameras’ shifts should be close; the wiki’s example has −8.121e-05 s and −8.681e-05 s.
  4. Its bound. The --timeoffset-padding option bounds how far the offset may move from Kalibr’s correlation-based first guess. The multi-IMU page says “trouble finding an appropriate value likely hints to issues in the dataset”: look at the timestamps before widening it.

Record a second camera–IMU dataset under the same settings and calibrate it the same way. Compare the two transforms and the two time offsets. From our conversations with people in the industry, values that move a lot between two good recordings were not well determined by either (Kalibr workflow, step 9). For scale, Furgale and colleagues’ offset estimates stayed “within a domain of ±0.2 ms” across datasets (Offline estimation with Kalibr).

Optional, the exposure slope. If your frames may be stamped at the start or end of exposure, calibrate at several fixed exposure times and fit the offset against exposure. A slope near +0.5 means start-of-exposure stamps, near −0.5 end-of-exposure, near 0 mid-exposure. The prompts page has a prompt that writes the fit.

Go through the sign-off section of the checklist. Store imu_allan.yaml, imu.yaml, the inflation factor, camchain-imucam.yaml, the results file and the report with the data, versioned and tied to the unit’s serial number and the IMU configuration. When you run a tracker that estimates the offset online, start it from the Kalibr value and check its sign convention against Kalibr’s first (Camera-IMU Time Offset, checklist).

Symptom What the sources say to do
IMU timestamps in bursts, as in the wiki’s example of “a burst of IMU are send at a rate of 1ms with gaps of 6ms between” “You will need to rectify the timestamp problems.” (camera–IMU calibration)
IMU residuals far outside ±3σ inflate the noise values; check the timestamps
Time offset cannot settle within its bounds the wiki: “trouble finding an appropriate value likely hints to issues in the dataset”
Target pose flips during the motion “The use of an Aprilgrid is recommended to avoid this problem entirely.”
Bag rejected a ROS 2 bag: convert it to ROS 1 with rosbags-convert (Kalibr workflow, step 4)
Allan plot rises towards slope +1 at the right end a trend such as warm-up: cut it or record again at a steady temperature
allan_variance processed the wrong log more than one .bag in the folder: the tool processes only one

The multi-IMU page sums up the biggest risk: “The most common failure mode of kalibr appears to be incorrect timestamps provided by the user.”