# C202 第 4 课：时间偏移、多个 IMU 与腕部传感器

> C202 IMU 课程的第四课：Kalibr 的 timeshift_cam_imu 是什么意思及其符号，相机–IMU 时间偏移从哪里来、能有多大，曝光和 IMU 滤波器如何使它变化，跟踪器如何在线估计它，带两个 IMU 的采集设备如何标定，以及为什么腕部传感器没有固定的外参。

Page: https://egocam.ai/zh-cn/university/c202/lesson-4-time-offset-and-multiple-imus/

Kalibr 的相机–IMU 标定写出一个很容易被一眼带过的数：`timeshift_cam_imu`。几毫秒未建模的偏移就足以让视觉惯性跟踪变差，而且当 IMU 滤波器或曝光改变时，这个数也会变。本课先讲这个偏移，再讲一对相机–IMU 覆盖不了的两种情况：带不止一个 IMU 的采集设备，以及装在腕部的传感器。完整的讲解见[相机–IMU 时间偏移](https://egocam.ai/zh-cn/calibration/camera-imu-time-offset/)和[多个 IMU 与头部到腕部的外参](https://egocam.ai/zh-cn/calibration/multi-imu-and-wrist-extrinsics/)。

## 本课用到的术语

另见术语表的[标定](https://egocam.ai/zh-cn/reference/glossary/)和[同步](https://egocam.ai/zh-cn/reference/glossary/)两节。

| 术语 | 含义 |
|---|---|
| 时间偏移 `t_d`（time offset） | 使相机时间戳和 IMU 时间戳一致的平移量：t_imu = t_cam + t_d |
| 延迟（latency） | 从取得一个采样到给它打上时间戳之间的固定延时；它看起来与偏移完全一样 |
| 曝光中点（exposure midpoint） | 一帧曝光的中间时刻，就运动而言最能代表这一帧的时刻 |
| 在线标定（online calibration） | 在跟踪器内部、从每一段录制中估计 `t_d` |
| IMU 间外参（inter-IMU extrinsics） | 同一刚性结构上第二个 IMU 相对参考 IMU 的固定旋转和平移 |
| 头到腕变换（head-to-wrist transform） | 腕部传感器在头部坐标系中的位姿；手臂一动它就变 |

## 符号

[YAML formats](https://github.com/ethz-asl/kalibr/wiki/Yaml-formats) 页面把这个字段定义为 "timeshift between camera and IMU timestamps in seconds (t_imu = t_cam + shift)"（意为：相机时间戳与 IMU 时间戳之间的时间偏移，单位为秒（t_imu = t_cam + shift））。把它加到相机时间戳上，就得到 IMU 时钟上的同一时刻。结果文件把它打印为 `timeshift cam0 to imu0: [s] (t_imu = t_cam + shift)`。

> **Diagram:** timeshift_cam_imu is the number of seconds to add to a camera timestamp to get the same instant on the IMU clock: t_imu = t_cam + shift. A negative value means the image's true IMU-clock time is earlier than its camera timestamp.

由定义可知（[符号约定](https://egocam.ai/zh-cn/calibration/camera-imu-time-offset/)）：相机时间戳相对 IMU 时间戳偏晚时，得到负值；IMU 时间戳偏晚时（由于 IMU 滤波很重，或者相机在曝光开始时打时间戳），得到正值。其他工具可能使用相反的符号，而以错误的符号施加修正，会使误差加倍，而不是抵消。

## 偏移从哪里来

从一个物理事件到它的时间戳之间的每个环节都会增加延迟，而相机的路径与 IMU 的不同。以下是已发表的测量结果，来自实用指南的[成因表](https://egocam.ai/zh-cn/calibration/camera-imu-time-offset/)：

| 成因 | 测得的影响 |
|---|---|
| IMU 读出延迟，由一个微控制器触发相机并读取 IMU | 恒定的 5.3 ms（TUM VI） |
| IMU 数字滤波器设置 | 同一个 IMU 在三种滤波器宽度下分别为 1.55、5.26 和 19.95 ms（VersaVIS） |
| 图像在曝光开始时打时间戳 | 偏移随曝光增大，拟合斜率 0.498（Furgale et al.） |
| 商用传感器，SDK 默认时间戳 | 一段手持录制中为 12.74 ms，对曝光的斜率约 0.5（RealSense ZR300） |

由此得到两条教训。**IMU 滤波器是标定的一部分**：VersaVIS 的作者写道 "time offset is highly dependent on the imu filter configuration"（意为：时间偏移高度依赖于 IMU 滤波器配置），所以固件对 IMU 采样率或滤波器的改动会使这个偏移失效。**曝光会使偏移变化**，除非帧是在曝光中点打时间戳的。如果在曝光开始时打时间戳，曝光从 20 ms 降到 1 ms 会使偏移变化 0.5 × 19 = 9.5 ms。解决办法是在曝光中点打时间戳，或者把每次触发平移半个曝光时间，或者记录每一帧的曝光并在事后修正时间戳。

要弄清你属于哪种情况，就在几个固定的曝光时间下分别标定，并拟合偏移对曝光的关系：斜率接近 +0.5 说明是曝光开始时的时间戳，接近 −0.5 是曝光结束时的时间戳，接近 0 是曝光中点的时间戳（[用 Kalibr 离线估计](https://egocam.ai/zh-cn/calibration/camera-imu-time-offset/)）。

## 多大的偏移有影响

Qin 和 Shen 平移了 EuRoC benchmark 的 IMU 时间戳，并在不做时间标定的情况下运行 VINS-Mono："The performance deteriorates dramatically when the time offset increases. The tolerance interval is only within 6 milliseconds."（意为：时间偏移增大时，性能急剧恶化。容许区间只在 6 毫秒以内。）有了在线标定，精度不再取决于偏移（[Qin and Shen, 2018](https://arxiv.org/abs/1808.00692v1)；[跟踪器能容忍多大的偏移](https://egocam.ai/zh-cn/calibration/camera-imu-time-offset/)）。

## Kalibr 的搜索窗口

Kalibr 先把相机看到的角速率与陀螺仪测到的角速率做相关来估计偏移，然后在批量估计中细化它。`--timeoffset-padding` 选项（默认 0.03 s）限定这个细化的范围。[多 IMU 页面](https://github.com/ethz-asl/kalibr/wiki/Multi-IMU-and-IMU-intrinsic-calibration)解释说，"an initial guess for the temporal offset is obtained from correlating absolute angular velocities as perceived independently by camera and IMU"（意为：时间偏移的初始估计是通过对相机和 IMU 各自独立感知到的绝对角速度做相关得到的），这个 padding 是 "merely a guess for the bounds within which this offsets will vary during calibration"（意为：只是对标定过程中这个偏移变化范围的一个猜测），并且 "trouble finding an appropriate value likely hints to issues in the dataset"（意为：难以找到合适的值，很可能暗示数据集有问题）。源代码也是这样做的：报告的偏移是相关得到的先验值加上细化的部分（[IccSensors.py](https://github.com/ethz-asl/kalibr/blob/master/aslam_offline_calibration/kalibr/python/kalibr_imu_camera_calibration/IccSensors.py) 中的 `getResultTimeShift`）。

## 在线估计，以及一个数不够用的时候

如果采集设备重启后进入了不同的缓冲延迟、曝光改变了，或者时钟漂移了，离线得到的偏移就会过时。现代的跟踪器把 `t_d` 放在它们的状态里：[Li and Mourikis (2014)](https://doi.org/10.1177/0278364913515286) 证明了它 "is locally identifiable, except in a small number of degenerate motion cases"（意为：是局部可辨识的，少数退化运动情形除外），OpenVINS 和 VINS-Mono 在运行时估计它。使它可观测的是旋转，而第一人称录制中有大量的头部旋转（[视觉惯性跟踪器中的在线估计](https://egocam.ai/zh-cn/calibration/camera-imu-time-offset/)）。

如果相机和 IMU 运行在不同的振荡器上，偏移会稳定地增大，没有哪个常数能跟得上。硬件上的答案是所有传感器共用一个时钟；RoboCap 的共享 TCXO 意味着漂移 "affects the absolute timeline only and not inter-sensor synchronization"（意为：只影响绝对时间线，而不影响传感器之间的同步）（[偏移在一次录制中发生变化时](https://egocam.ai/zh-cn/calibration/camera-imu-time-offset/)）。在一段长录制中，在线估计值稳定地变化，就是要留意的迹象。

## 带两个 IMU 的采集设备

当前的采集设备常常在一个刚性头部单元上带两个 IMU；RoboCap、6C cap 和 Aria Gen 2 都是这样（[同一个刚体上的多个 IMU](https://egocam.ai/zh-cn/calibration/multi-imu-and-wrist-extrinsics/)）。它们的相对位姿是固定的，所以每个制造版本标定一次。Kalibr 在同一次相机–IMU 运行中完成它（[Multi-IMU and IMU intrinsic calibration](https://github.com/ethz-asl/kalibr/wiki/Multi-IMU-and-IMU-intrinsic-calibration)）：

- 在 `--imu` 之后每个 IMU 给一个 `imu.yaml`："The first IMU will be the reference IMU (IMU0)"（意为：第一个 IMU 将作为参考 IMU（IMU0））；
- 在 `--imu-models` 之后每个 IMU 给一个模型；
- 各个 IMU 事先已同步：只有相机到 IMU0 的偏移是用最大似然估计的。`--imu-delay-by-correlation` 通过相关来估计其他 IMU 的偏移，这 "will not be as accurate as the maximum-likelihood estimate"（意为：不会像最大似然估计那样准确）。

wiki 给出的命令形式：

```bash
kalibr_calibrate_imu_camera --bag [filename.bag] --cam [camchain.yaml] --imu [imu0.yaml ... imuN.yaml] --imu-models [MODEL0 ... MODELN] --target [target.yaml]
```

把各个 IMU 区分开的杆臂项在慢速旋转时很小，所以运动必须轻快，而且必须有变化："motions such as constant acceleration or rotation along a single axis at a constant rate result in a failure mode"（意为：恒定加速度或者绕单一轴匀速旋转这样的运动会导致失效）（[Lee, Hanley and Bretl, 2022](https://arxiv.org/pdf/2205.14724)）。他们的仅用 IMU 的方法不需要标定板；在他们的硬件测试中，标定板照明很差时，Kalibr 在 21 次运行中成功了 1 次，而他们的方法 21 次全部成功。

## 腕部传感器：没有固定的外参

腕部相机或 IMU 与头部之间没有刚性连接，所以不存在一个可以标定的恒定的头到腕变换。它必须每一帧都测量，办法有：在每个腕部设备上运行 SLAM、共享地图、XR 头显的手柄跟踪或者标记物；或者通过记录相对运动在设计上把它消去（[头部和腕部的传感器：没有固定的外参](https://egocam.ai/zh-cn/calibration/multi-imu-and-wrist-extrinsics/)）。标定转移到这条链路中固定的那些部分上。

> **Diagram:** Extrinsics are the rotation R and translation t between sensors. On a rigid head unit they are fixed and calibrated once; a wrist camera moves relative to the head, so its pose is tracked frame by frame instead.

单独对腕部 IMU 做积分会漂移：在 DexCap 的测试中，仅用 IMU 的跟踪在回到起点时偏差为 8.0 ± 3.1 cm，而用 SLAM 时为 0.4 ± 0.2 cm。

## 自测

1. Kalibr 报告 `timeshift_cam_imu = -0.004`。哪一路数据的时间戳偏晚？要得到 IMU 时间，你给相机时间戳加上什么？
2. 你在 2 ms 曝光下做了标定。在现场，自动曝光在 1 到 20 ms 之间变化，而你的帧是在曝光开始时打时间戳的。标定出的偏移还对吗？
3. 固件增大了 IMU 的滤波器宽度。你还沿用旧的偏移吗？
4. 你的采集设备有两个 IMU，由不同的微控制器读取，没有共用的时钟。Kalibr 假定了什么，这对精度意味着什么？
5. 为什么不能像标定 `T_cam_imu` 那样，把头戴相机和腕戴相机之间的变换标定一次就行？

### 答案

1. 相机的：负的偏移意味着图像在 IMU 时钟上的真实时间早于它的相机时间戳。给相机时间戳加上 −0.004 s。
2. 不对。在曝光开始时打时间戳的情况下，偏移的变化量是曝光变化量的一半，在这里最多为 0.5 × 19 = 9.5 ms。在曝光中点打时间戳，平移触发，或者根据记录的曝光逐帧修正。
3. 不。滤波器设置会改变偏移，在 VersaVIS 的测量中，不同滤波器宽度之间最多相差约 18 ms。重新标定。
4. 它假定各个 IMU 彼此已同步。如果没有同步，`--imu-delay-by-correlation` 会通过相关给每个额外的 IMU 一个偏移，它不如最大似然估计准确；所有 IMU 共用一个时基可以避开这个问题。
5. 手臂会动，所以这个变换每一帧都在变。它必须逐帧跟踪（或者在设计上消去），而不是标定一次。

## 参考来源

- 实用指南：[相机–IMU 时间偏移](https://egocam.ai/zh-cn/calibration/camera-imu-time-offset/)、[多个 IMU 与头部到腕部的外参](https://egocam.ai/zh-cn/calibration/multi-imu-and-wrist-extrinsics/)、[Kalibr 文件参考](https://egocam.ai/zh-cn/kalibr/kalibr-file-reference/)，以及术语表的[标定](https://egocam.ai/zh-cn/reference/glossary/)和[同步](https://egocam.ai/zh-cn/reference/glossary/)两节。
- Kalibr wiki，ETH Zurich ASL：[YAML formats](https://github.com/ethz-asl/kalibr/wiki/Yaml-formats) 和 [Multi-IMU and IMU intrinsic calibration](https://github.com/ethz-asl/kalibr/wiki/Multi-IMU-and-IMU-intrinsic-calibration)。
- Kalibr 源代码（commit `1f60227`）：[IccSensors.py](https://github.com/ethz-asl/kalibr/blob/master/aslam_offline_calibration/kalibr/python/kalibr_imu_camera_calibration/IccSensors.py) 和 [IccUtil.py](https://github.com/ethz-asl/kalibr/blob/master/aslam_offline_calibration/kalibr/python/kalibr_imu_camera_calibration/IccUtil.py)。
- Qin, T. and Shen, S. (2018). [Online temporal calibration for monocular visual-inertial systems](https://arxiv.org/abs/1808.00692v1). *IEEE/RSJ IROS*.
- Li, M. and Mourikis, A. I. (2014). [Online temporal calibration for camera–IMU systems: Theory and algorithms](https://doi.org/10.1177/0278364913515286). *The International Journal of Robotics Research*.
- Tschopp, F. et al. (2020). [VersaVIS: An open versatile multi-camera visual-inertial sensor suite](https://arxiv.org/abs/1912.02469v1). *Sensors*.
- Lee, J., Hanley, D. and Bretl, T. (2022). [Extrinsic calibration of multiple inertial sensors from arbitrary trajectories](https://arxiv.org/pdf/2205.14724).
- Ali, Q. et al. (2026). [RoboCap: A new platform for egocentric robot learning](https://arxiv.org/abs/2610.07217). arXiv:2610.07217.
- Wang, C. et al. (2024). [DexCap: Scalable and portable mocap data collection system for dexterous manipulation](https://arxiv.org/pdf/2403.07788). *RSS*.
