跳转到内容

C202 第 3 课:用 Kalibr 做相机–IMU 标定

相机已经标定(C201),IMU 的噪声值已经测出(第 2 课),还剩一项标定:IMU 相对每台相机在什么位置,以及它们的时钟之间是什么关系。Kalibr 的 kalibr_calibrate_imu_camera 同时估计这两者。本课讲录制、输入、命令和结果。分步骤的版本见 Kalibr 工作流程的第 6 到第 9 步。

另见术语表的标定一节。

术语 含义
相机–IMU 外参(camera–IMU extrinsics) IMU 坐标系与某台相机坐标系之间的旋转和平移
T_cam_imu Kalibr 中从 IMU 坐标到相机坐标的变换;它的平移量是从相机看 IMU 所在的位置
timeshift_cam_imu Kalibr 加到相机时间戳上、以得到 IMU 时钟上同一时刻的时间偏移
激励(excitation) 使每个参数都可观测的运动:绕每个轴旋转,并沿每个轴平移
连续时间批量标定(continuous-time batch calibration) 用一条样条拟合采集设备的轨迹,使 IMU 采样和相机帧可以联合优化外参和时间偏移
归一化残差(normalised residual) 误差除以求解器被告知应当预期的噪声

Kalibr 遵循 Furgale, Rehder and Siegwart (2013) 的方法。它把 IMU 的轨迹和零偏表示为 B 样条,即时间的连续函数。样条可以在任意时刻求值,所以把图像时间戳按一个候选偏移量平移时,不需要对 IMU 数据重新积分,于是这个偏移就成为单次批量估计中又一个未知量,与重力方向、相机–IMU 变换以及随时间变化的位姿和零偏一起求解(用 Kalibr 离线估计)。

在一次估计中完成这件事很重要。在 40 个真实数据集上,该论文报告的 RMS 时序误差为 “0.054ms, 0.344ms, 0.165ms and 0.572ms”(意为:0.054 ms、0.344 ms、0.165 ms 和 0.572 ms),分别对应联合标定、单独的时间延迟估计、仅用陀螺仪和仅用加速度计。

The Kalibr workflow: two recordings, two calibrations A flow chart of the Kalibr workflow for cameras plus an IMU, as the Kalibr wiki describes it. Two recordings, both stored as ROS 1 bags, with the roles swapped. Recording 1, the camera dataset: the cameras stay fixed and the Aprilgrid target is moved in front of them, at around 4 Hz. It goes with target.yaml, which holds the target's measured tag size and spacing, into kalibr_calibrate_cameras, which writes camchain.yaml with each camera's intrinsics and distortion and the camera-to-camera transforms. Recording 2, the camera-IMU dataset: the target stays fixed and the rig is moved to excite every rotation and translation axis; the guide reports good results at a 20 Hz camera rate and 200 Hz IMU rate. It goes with target.yaml, camchain.yaml and imu.yaml, the four IMU noise values from an Allan deviation or the datasheet, into kalibr_calibrate_imu_camera, which writes camchain-imucam.yaml, adding T_cam_imu and timeshift_cam_imu to each camera. Both tools also write a results text file and a PDF report to judge before accepting. Recording 1 cameras fixed, target moved in front camera rate ~4 Hz target.yaml measured tag size, spacing Recording 2 target fixed, rig moved on every axis; e.g. camera 20 Hz, IMU 200 Hz imu.yaml 4 noise values kalibr_calibrate_cameras camera calibration kalibr_calibrate_imu_camera camera–IMU calibration camchain.yaml intrinsics, distortion, camera-to-camera transforms camchain-imucam.yaml camchain plus T_cam_imu and timeshift_cam_imu per camera camchain.yaml feeds in check: results-cam.txt, report-cam.pdf check: results-imucam.txt, report-imucam.pdf Both recordings are ROS 1 bags. The roles swap: cameras still, then target still
Kalibr's two calibrations and the files that pass between them. The camera calibration uses a recording in which the cameras stay still and the target moves; the camera–IMU calibration uses one in which the target stays still and the rig moves on every axis, and it takes camchain.yaml from the first step plus the IMU noise values in imu.yaml. Rates are the Kalibr wiki's suggestions (about 4 Hz for the first recording; 20 Hz camera and 200 Hz IMU for the second). Each tool also writes a results file and a PDF report to judge before you accept the output.

录制:标定板不动,采集设备动

Section titled “录制:标定板不动,采集设备动”

角色与 C201 相反。相机–IMU 指南说:“The calibration target is fixed in this calibration and the camera-imu system is moved in front of the target to excite all IMU axes.”(意为:在这项标定中,标定板是固定的,相机–IMU 系统在标定板前移动,以激励 IMU 的所有轴。)它的提示:

  • “try to excite all IMU axes (rotation and translation)”(意为:尽量激励 IMU 的所有轴(旋转和平移))
  • “avoid shocks, especially at the beginning/end when you pick up the sensor”(意为:避免冲击,尤其是在开头和结尾拿起传感器的时候)
  • “keep the motion blur low”(意为:保持运动模糊小),采用 “low shutter times”(意为:短快门时间)和 “good illumination”(意为:良好的照明)
  • “ensure low jitter timestamps in same clock”(意为:确保时间戳抖动小,并且在同一个时钟上)

每条提示的理由,包括为什么冲击和没有标定板的帧有害,列在 Kalibr 工作流程,第 7 步中。该指南还说 “Good results have been obtained by using a camera rate of 20 Hz and an IMU rate of 200 Hz.”(意为:使用 20 Hz 的相机帧率和 200 Hz 的 IMU 采样率取得了良好的结果。)Furgale 及其同事的录制时长 “typically 1–2 minutes”(意为:通常为 1 到 2 分钟);在他们的实验中,每次录制 “about 90 seconds”(意为:约 90 秒),并且 “an average absolute angular velocity of about 55° s−1 and an average absolute acceleration of 1.1m/s2”(意为:平均绝对角速度约为 55 °/s,平均绝对加速度为 1.1 m/s²)(Kalibr 工作流程,第 7 步)。

同样这些页面上有两点警告。只左右摇摆的采集设备,在其他轴上什么也没给求解器。原因在于杆臂:IMU 相对相机的偏移只体现在加速度计中,通过一些需要旋转才出现的项,而绕某一个轴的旋转会掩盖沿该轴的任何偏移(为什么每个轴都必须动)。另外,使用对称的标定板时,“movements which could lead to flips in the target pose estimates have to be avoided”(意为:必须避免可能导致标定板位姿估计翻转的运动);用 Aprilgrid 可以避开这个问题。

录制时,IMU 的配置要与生产中完全一样:相同的输出速率,相同的滤波器设置。滤波器会改变时间偏移,第 4 课会说明。

输入 参数 从哪里来
一个包含图像和 IMU 数据的 ROS 1 bag --bag 直接录制、由 ROS 2 转换,或者用 kalibr_bagcreater 由图像和一个 imu0.csv 生成(bag format)
相机标定 --cam kalibr_calibrate_cameras 输出的 <bag>-camchain.yaml(C201 实验)
IMU 文件,每个 IMU 一个 --imu 带有第 2 课噪声值的 imu.yaml
标定板 --target 带有实测标定板尺寸的 target.yaml
IMU 模型,每个 IMU 一个 --imu-models calibrated、scale-misalignment 或 scale-misalignment-size-effect

源代码把相机参数写作 --cams;wiki 和工具的用法说明写的是 --cam(kalibr_calibrate_imu_camera)。该工具用 Python 的 argparse 构建选项,它在默认情况下 “allows long options to be abbreviated to a prefix, if the abbreviation is unambiguous”(意为:允许把长选项缩写为一个前缀,只要这个缩写没有歧义)(argparse 文档),所以 wiki 的 --cam 会对应到 --cams。

IMU 模型。默认的 calibrated 假定 IMU 的比例和失准已经修正。scale-misalignment 还会估计每个传感器的一个比例与失准矩阵、陀螺仪对加速度的敏感度,以及陀螺仪轴与加速度计轴之间的旋转。scale-misalignment-size-effect 还会确定加速度计每个轴的位置(imu.yaml:输出文件)。

该指南给出了一般形式:

终端窗口
kalibr_calibrate_imu_camera --bag [filename.bag] --cam [camchain.yaml] --imu [imu.yaml] --target [target.yaml]

以及针对其示例 bag 的这个例子:

终端窗口
rosrun kalibr kalibr_calibrate_imu_camera \
--target april_6x6.yaml \
--imu imu_adis16448.yaml \
--imu-models calibrated \
--cam cam_april-camchain.yaml \
--bag imu_april.bag

该指南说明时间标定默认开启;--no-time-calibration 将它关闭。相机之间的变换沿用相机标定的结果,除非你传入 --recompute-camera-chain-extrinsics,源代码称它 “exclusively recommended for debugging purposes”(意为:仅建议用于调试目的)(Kalibr 工作流程,第 8 步)。

文件 内容
<bag>-camchain-imucam.yaml camchain,加上每台相机的 T_cam_imu 和 timeshift_cam_imu
<bag>-imu.yaml 输入的 IMU 值,加上模型、T_i_b、time_offset,对于更丰富的模型还有估计出的矩阵
<bag>-results-imucam.txt 归一化残差和未归一化的残差、两个方向的变换、时间偏移、基线、重力向量
<bag>-report-imucam.pdf 各曲线图

这些文件名是源代码写出的名称;wiki 把它们的顺序反过来写,写作 camchain-imucam-%BAGNAME%.yaml(文件一览)。

Kalibr 把每个变换命名为 T_a_b,它把坐标系 b 中的点变到坐标系 a。所以,用 YAML formats 页面的话说,T_cam_imu 是 “transformation from IMU to camera coordinates (T_c_i)”(意为:从 IMU 坐标到相机坐标的变换(T_c_i)),它的平移量是 IMU 在相机坐标系中的位置。结果文件把两个方向都打印出来,写作 T_ci 和 T_ic。

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).

wiki 的 RealSense 教程用几行字给出了各项检查;实用指南列出了每一项在哪里(Kalibr 工作流程,第 9 步、report-imucam.pdf):

检查 在哪里 应当看到什么 如果不是
IMU 采样时序 IMU 测量速率页 在预期速率处的一条平线 “Inspect the IMU time dt plot carefully in the PDF report!”(意为:仔细检查 PDF 报告中的 IMU 时间 dt 图!)先修好时间戳
IMU 残差 加速度误差页和角速度误差页 在 ±3σ 虚线之内 “your IMU noise or the dataset are incorrect”(意为:你的 IMU 噪声或数据集不正确)
零偏估计 加速度计零偏页和陀螺仪零偏页 在 ±3σ 边界之内 “your trajectory was too dynamic, or your noise values are not good”(意为:你的轨迹太剧烈,或者你的噪声值不好)
变换 结果文件中的 T_ci 与采集设备相符 “Sanity check your final rotation and translation with hand-measured values.”(意为:用手工测量的值对最终的旋转和平移做合理性检查。)
重投影 重投影页 点在 3σ 圆之内 减小运动模糊

±3σ 线来自你提供的噪声值。多 IMU 页面说,它们的作用是 “foster an intuition about the correctness of the noise parameters and models”(意为:帮助建立对噪声参数和模型是否正确的直觉)。第 2 课的放大倍数就是这样评判的:残差远在线外,说明假定的噪声太小或者数据不好。据我们所知,归一化残差远小于 1,说明假定的噪声比数据表现出来的大得多(results-imucam.txt)。

时间偏移有它自己的一课,就是下一课。

  1. 在相机–IMU 录制中,什么不动,什么动?这与 C201 有什么不同?
  2. 你的采集设备在标定板前左右挥动了两分钟。这段录制有什么问题?
  3. 你的 IMU 的比例因子从未标定过。你给 --imu-models 传什么值?
  4. cam0 的 T_cam_imu 在 x 方向有约 3 cm 的平移量。这个数描述的是什么?
  5. 角速度残差远在 ±3σ 虚线之外。说出两个可能的原因。
  1. 标定板不动,采集设备动,而且在每个轴上都动。在相机标定中,相机不动,标定板动。
  2. 它只激励了一个旋转轴。求解器需要绕每个轴的旋转和沿每个轴的平移。
  3. scale-misalignment(或 scale-misalignment-size-effect),它会估计它们;calibrated 假定它们已经修正。
  4. IMU 在 cam0 坐标系中的位置,单位为米。用尺子或机械图纸核对它。
  5. imu.yaml 中的噪声值太小(放大得不够),或者数据集不好,例如时间戳有问题。