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: the IMU on its own
Section titled “Part A: the IMU on its own”Part A takes hours of recording. Start it first, and work on the Part B preparation while it runs.
A1: Build allan_variance_ros
Section titled “A1: Build allan_variance_ros”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:
catkin build allan_variance_rossource devel/setup.bashYou 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).
A2: Prepare the rig
Section titled “A2: Prepare the rig”- 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.
A3: Record the static log
Section titled “A3: Record the static log”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):
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.
A4: Put the messages in timestamp order
Section titled “A4: Put the messages in timestamp order”The README recommends this step:
rosrun allan_variance_ros cookbag.py --input original_rosbag --output cooked_rosbagWith 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).
A5: Compute the Allan deviation
Section titled “A5: Compute the Allan deviation”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 subsampledsequence_time: [RECORD_LENGTH_S]What the source does with these keys (src/AllanVarianceComputor.cpp, commit 1d54b60):
measure_ratesets a subsampling step ofimu_rate / measure_rate. Some example configs subsample (400 to 100 Hz);config/sim.yamldoes not. To the best of our knowledge, keepingmeasure_rateequal toimu_rateavoids the subsampling caveat of Kalibr’s noise model (Lesson 2).sequence_timecaps 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:
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.
A6: Read the plots and the numbers
Section titled “A6: Read the plots and the numbers”Run the analysis, passing the config so the topic and rate go into the output file:
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:
- 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).
- The fitted lines. In
analysis.py(commit1d54b60), 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. - The axes. Compare the three axes of each sensor. If one disagrees, note it.
- Which axis went into the file. Since commit
7a3a461(October 2022, messageUse worst axis instead of average and support overlapping bins),analysis.pywrites the largest of the three axes’ values intoimu.yaml, not their mean (np.amax). The exampleimu.yamlin the README matches the three-axis mean, so it predates that change. Read the printed per-axis values next to the file. - 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).
A7: Write the imu.yaml for Kalibr
Section titled “A7: Write the imu.yaml for Kalibr”Start from the generated file and check every key against the YAML formats page:
#Accelerometersaccelerometer_noise_density: [VALUE] #Noise density (continuous-time)accelerometer_random_walk: [VALUE] #Bias random walk
#Gyroscopesgyroscope_noise_density: [VALUE] #Noise density (continuous-time)gyroscope_random_walk: [VALUE] #Bias random walk
rostopic: [IMU_TOPIC] #the IMU ROS topicupdate_rate: [IMU_RATE_HZ] #Hz (for discretization of the values above)- Units: gyroscope values in radians, not degrees.
update_rateis the rate the IMU really runs at in the Part B bag, androstopicis 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.yamland the inflated one asimu.yaml, and write the factor down. Step B5 tells you whether it fits.
Part B: the IMU against the cameras
Section titled “Part B: the IMU against the cameras”B1: Gather the inputs
Section titled “B1: Gather the inputs”[calib]-camchain.yamlandtarget.yamlfrom the C201 lab, for the same cameras at the same resolution and focus.imu.yamlfrom A7.- Kalibr, set up as in C201 lab step 1, with your data folder mounted at
/data.
B2: Lock the settings
Section titled “B2: Lock the settings”- 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.
B3: Record the camera–IMU dataset
Section titled “B3: Record the camera–IMU dataset”Fix the target to a wall or table; it must not move. Record the image topics and the IMU topic together:
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):
kalibr_bagcreater --folder dataset-dir/. --output-bag awsome.bagThe 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.
B4: Run the calibration
Section titled “B4: Run the calibration”Inside the container, in the form of the guide’s example:
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.bagUse --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).
B5: Judge the result
Section titled “B5: Judge the result”Open the report and the results file and work through Lesson 3:
- 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.
- IMU residuals inside the dashed ±3σ lines, for the accelerometer and the gyroscope.
- Biases inside their ±3σ bounds.
- Reprojection errors inside the 3σ circle, and comparable to the camera calibration’s.
- 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.
B6: Check the transform
Section titled “B6: Check the transform”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.
B7: Read the time offset
Section titled “B7: Read the time offset”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).
- Read the sign. Negative: the camera’s timestamps are late relative to the IMU’s. Positive: the IMU’s are late.
- 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.
- 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.
- Its bound. The
--timeoffset-paddingoption 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.
B8: Calibrate again and compare
Section titled “B8: Calibrate again and compare”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.
B9: Sign off and store
Section titled “B9: Sign off and store”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).
When a step fails
Section titled “When a step fails”| 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.”
Sources
Section titled “Sources”- Buchanan, R. allan_variance_ros, Oxford Robotics Institute: README,
config/*.yaml,scripts/analysis.py,scripts/cookbag.py,src/allan_variance.cppandsrc/AllanVarianceComputor.cpp(commit1d54b60, January 2025), and the history ofscripts/analysis.py(commit7a3a461). - Kalibr wiki, ETH Zurich ASL: camera–IMU calibration, Multi-IMU and IMU intrinsic calibration, IMU noise model, YAML formats, bag format, Calibrating Intel RealSense cameras.
- Kalibr source code, github.com/ethz-asl/kalibr (commit
1f60227): kalibr_calibrate_imu_camera, IccSensors.py, IccUtil.py. - ROS wiki: rosbag command line.
- Furgale, P., Rehder, J. and Siegwart, R. (2013). Unified temporal and spatial calibration for multi-sensor systems. IEEE/RSJ IROS.
- Field guide: IMU Noise Models and Allan Variance, Kalibr Workflow, Kalibr File Reference, Camera-IMU Time Offset, IMUs on Wearable Rigs.