VINS-Mono之外参标定和视觉IMU联合初始化

文章目录

    • 1.前言
    • 2. 外参标定 (利用旋转约束估计外参数旋转 q c b ) q^{b}_{c}) qcb)
    • 3. 视觉IMU联合初始化
      • 3.1 陀螺仪偏置的估计 (利用旋转约束估计 b w b_{w} bw)
      • 3.2 速度、重力和尺度初始化 (利用预积分约束估计 v b k b k v^{b_{k}}_{b_{k}} vbkbk g c 0 g^{c_{0}} gc0 s s s)
      • 3.3 优化重力向量 g c 0 g^{c_{0}} gc0
      • 3.4 对齐导航世界坐标系

1.前言

本博客主要介绍VINS-Mono初始化时相机与IMU对齐,主要包括相机到IMU的外参估计、陀螺仪偏置、相机位移和估计空间点的尺度、重力加速度、每帧速度,主要参考了深蓝学院的VIO课程及博客VINS-Mono理论学习——视觉惯性联合初始化与外参标定和崔华坤的《VINS 论文推导及代码解析》。
总体而言,视觉IMU对齐流程主要包括以下几部分:

  1. 若旋转外参数 q c b q^{b}_{c} qcb未知,则先估计旋转外参数
  2. 利用旋转约束估计陀螺仪偏置: q b k c 0 = q c k c 0 ⊗ ( q c b ) − 1 q^{c_{0}}_{b_{k}} = q_{c_{k}}^{c_{0}}\otimes (q^{b}_{c})^{-1} qbkc0=qckc0(qcb)1
  3. 利用平移约束估计重力方向,速度,以及尺度初始值 s p ˉ b k c 0 = s p ˉ c k c 0 − R b k c 0 p c b s\bar p^{c_{0}}_{b_{k}} = s \bar p^{c_{0}}_{c_{k}} - R^{c_{0}}_{b_{k}}p^{b}_{c} spˉbkc0=spˉckc0Rbkc0pcb
  4. 对重力向量 g c 0 g^{c_{0}} gc0进行进一步的优化
  5. 求解世界坐标系 w w w和初始相机坐标系 c 0 c_{0} c0之间的旋转矩阵 q c 0 w q^{w}_{c_{0}} qc0w,并将轨迹对齐到世界坐标系中

2. 外参标定 (利用旋转约束估计外参数旋转 q c b ) q^{b}_{c}) qcb)

相邻俩时刻 k k k, k + 1 k+1 k+1之间, k k k时刻的IMU到 k + 1 k+1 k+1时刻的相机外参旋转矩阵有: R c k + 1 b k = R b k + 1 b k ⋅ R c b = R c b ∗ R c k + 1 c k R^{b_{k}}_{c_{k+1}}=R^{b_{k}}_{b_{k+1}} \cdot R^{b}_{c} = R^{b}_{c} * R^{c_{k}}_{c_{k+1}} Rck+1bk=Rbk+1bkRcb=RcbRck+1ck 转换为四元素有: q b k + 1 b k ⊗ q c b = q c b ⊗ q c k + 1 c k q^{b_{k}}_{b_{k+1}} \otimes q^{b}_{c} = q^{b}_{c} \otimes q^{c_{k}}_{c_{k+1}} qbk+1bkqcb=qcbqck+1ck 上式可写为: ( L ( q b k + 1 b k ) − R ( q c k + 1 c k ) ) q c b = Q k + 1 k ⋅ q c b = 0 (\mathcal{L}(q^{b_{k}}_{b_{k+1}})-\mathcal{R}(q^{c_{k}}_{c_{k+1}}))q^{b}_{c} = Q^{k}_{k+1} \cdot q^{b}_{c} = 0 (L(qbk+1bk)R(qck+1ck))qcb=Qk+1kqcb=0
将多个时刻的上式方程累计起来,并加上鲁棒核权重,可构建超定方程: [ w 1 0 ⋅ Q 1 0 w 2 1 ⋅ Q 2 1 ⋯ w N N − 1 ⋅ Q N N − 1 ] q c b = Q N ⋅ q c b = 0 (1) \begin{bmatrix}w^{0}_{1} \cdot Q^{0}_{1} \\ w^{1}_{2} \cdot Q_{2}^{1} \\ \cdots \\ w^{N-1}_{N} \cdot Q_{N}^{N-1}\end{bmatrix} q^{b}_{c} = Q_{N}\cdot q^{b}_{c} = 0 \tag{1} w10Q10w21Q21wNN1QNN1qcb=QNqcb=0(1) 其中:
w k + 1 k = { 1 ,    r k + 1 k < t h r e s h o l d t h r e s h o l d r k + 1 k ,    o t h e r w i s e w_{k+1}^{k} = \left\{\begin{matrix} 1, \ \ r^{k}_{k+1}wk+1k={1,  rk+1k<thresholdrk+1kthreshold,  otherwise 由旋转和轴角之间的关系 t r ( R ) = 1 + 2 cos ⁡ θ tr(R)=1+2\cos\theta tr(R)=1+2cosθ,能得到角度误差 r r r的计算为: r k + 1 k = a c o s ( ( t r ( ( R b k + 1 b k R ^ c b ) − 1 R ^ c b R c k + 1 c k ) − 1 ) / 2 ) = a c o s ( ( t r ( R ^ c b   − 1 R b k + 1 b k   − 1 R c b ^ R c k + 1 c k ) − 1 ) / 2 ) r^{k}_{k+1}=acos((tr((R^{b_{k}}_{b_{k+1}}\hat{R}^{b}_{c})^{-1}\hat{R}^{b}_{c}R^{c_{k}}_{c_{k+1}})-1)/2) \\ = acos((tr(\hat{R}^{b \ -1}_{c}R^{b_{k}\ -1}_{b_{k+1}}\hat{R^{b}_{c}}R^{c_{k}}_{c_{k+1}})-1)/2) rk+1k=acos((tr((Rbk+1bkR^cb)1R^cbRck+1ck)1)/2)=acos((tr(R^cb 1Rbk+1bk 1Rcb^Rck+1ck)1)/2)
公式(1)的求解同样采用SVD分解,即最下奇异值对应的奇异向量即为IMU坐标系到相机坐标系的旋转(四元素表示),具体代码见initial_ex_rotation.cpp 函数 CalibrationExRotation()


对于 t r ( R ) = 1 + 2 cos ⁡ θ tr(R)=1+2\cos \theta tr(R)=1+2cosθ的推导如下:
旋转矩阵和轴角的关系为: R = cos ⁡ θ I + ( 1 − cos ⁡ θ ) a a T − sin ⁡ θ [ a ] × R=\cos\theta I +(1-\cos \theta) aa^{T} - \sin \theta [a]_{\times} R=cosθI+(1cosθ)aaTsinθ[a]× 其中 a = [ a 1 , a 2 , a 3 ] T a=[a_{1}, a_{2}, a_{3}]^{T} a=[a1,a2,a3]T为单位旋转轴, θ \theta θ为绕着旋转轴转动的角度, [ a ] × = [ 0 − a 3 a 2 a 3 0 − a 1 − a 2 a 1 0 ] [a]_{\times}=\begin{bmatrix} 0 & -a_{3} & a_{2} \\ a_{3} & 0 & -a_{1} \\ -a_{2} & a_{1} &0\end{bmatrix} [a]×=0a3a2a30a1a2a10
同时,由于 a a a为单位旋转轴,有 t r ( a a T ) = 1 tr(aa^{T})=1 tr(aaT)=1,故:
t r ( R ) = cos ⁡ θ   t r ( I ) + ( 1 − cos ⁡ θ ) t r ( a a T ) + sin ⁡ θ   t r ( [ a ] × ) = 3 cos ⁡ θ + ( 1 − cos ⁡ θ ) = 1 + 2 cos ⁡ θ tr(R)=\cos \theta \ tr(I)+(1-\cos \theta) tr(aa^{T}) + \sin\theta \ tr([a]_{\times}) \\ = 3\cos\theta + (1-\cos \theta) = 1+2\cos \theta tr(R)=cosθ tr(I)+(1cosθ)tr(aaT)+sinθ tr([a]×)=3cosθ+(1cosθ)=1+2cosθ 同时也有 R a = a Ra=a Ra=a,即旋转轴上在旋转后并不发生变化,旋转轴 a a a为旋转矩阵 R R R的特征值为1对应的特征向量。
关于旋转矩阵和轴角的关系可参考:https://en.wikipedia.org/wiki/Rotation_matrix


3. 视觉IMU联合初始化

VINS-Mono之外参标定和视觉IMU联合初始化_第1张图片

假如我们已经有一个初始的IMU到相机的外参 T c b = [ R c b ∣ p c b ] T^{b}_{c}=[R^{b}_{c}| p^{b}_{c}] Tcb=[Rcbpcb],同时又有不同时刻帧的位姿 T c k c 0 = [ R c k c 0 ∣ p c k c 0 ] T^{c_{0}}_{c_{k}}=[R^{c_{0}}_{c_{k}}|p^{c_{0}}_{c_{k}}] Tckc0=[Rckc0pckc0] (基于第一帧坐标系下),那么我们可以知道姿态从相机坐标系到IMU坐标系的关系 T b k c 0 = [ R b k c 0 ∣ p b k c 0 ] T^{c_{0}}_{bk}=[R^{c_{0}}_{b_{k}}|p^{c_{0}}_{b_{k}}] Tbkc0=[Rbkc0pbkc0]与前俩者的关系: T c k c 0 = T b k c 0 T c b T^{c_{0}}_{c_{k}} = T^{c_{0}}_{b_{k}}T^{b}_{c} Tckc0=Tbkc0Tcb 则有: [ R c k c 0 s p ˉ c k c 0 0 1 ] = [ R b k c 0 s p ˉ b k c 0 0 1 ] [ R c b p c b 0 1 ] \begin{bmatrix}R^{c_{0}}_{c_{k}} & s\bar{p}^{c_{0}}_{c_{k}} \\ 0 & 1\end{bmatrix} = \begin{bmatrix}R^{c_{0}}_{b_{k}} & s\bar{p}^{c_{0}}_{b_{k}} \\ 0 & 1\end{bmatrix} \begin{bmatrix}R^{b}_{c} & {p}^{b}_{c} \\ 0 & 1\end{bmatrix} [Rckc00spˉckc01]=[Rbkc00spˉbkc01][Rcb0pcb1] 将式子展开有【论文公式(14)】: R c k c 0 = R b k c 0 R c b → R b k c 0 = R c k c 0 ( R c b ) − 1 R^{c_{0}}_{c_{k}}=R^{c_{0}}_{b_{k}}R^{b}_{c} \rightarrow R^{c_{0}}_{b_{k}}=R^{c_{0}}_{c_{k}}(R^{b}_{c})^{-1} Rckc0=Rbkc0RcbRbkc0=Rckc0(Rcb)1 s p ˉ c k c 0 = R b k c 0 p c b + s p ˉ b k c 0 → s p ˉ b k c 0 = s p ˉ c k c 0 − R b k c 0 p c b (2) s\bar{p}^{c_{0}}_{c_{k}}=R^{c_{0}}_{b_{k}}p^{b}_{c}+s\bar{p}^{c_{0}}_{b_{k}} \rightarrow s\bar{p}^{c_{0}}_{b_{k}}=s\bar{p}^{c_{0}}_{c_{k}}-R^{c_{0}}_{b_{k}}p^{b}_{c} \tag{2} spˉckc0=Rbkc0pcb+spˉbkc0spˉbkc0=spˉckc0Rbkc0pcb(2)
视觉IMU联合初始化中的视觉SFM位姿与IMU位姿的对齐主要在vins_estimator/src/initial/initial_aligment.cpp中的VisualIMUAlignment()函数中。

3.1 陀螺仪偏置的估计 (利用旋转约束估计 b w b_{w} bw)

对于窗口的连续俩帧 b k b_{k} bk b k + 1 b_{k+1} bk+1,已经从SFM中得到了旋转 q b k c 0 q^{c_{0}}_{b_{k}} qbkc0 q b k + 1 c 0 q^{c_{0}}_{b_{k+1}} qbk+1c0,从IMU预积分中得到了相邻帧的旋转 γ ^ b k + 1 b k \hat{\gamma}^{b_{k}}_{b_{k+1}} γ^bk+1bk。根绝约束方程,联立所有相邻帧,可以得到最小化代价函数【论文公式(15)】:
m i n δ b w ∑ k ∈ B ∥ q b k + 1 c 0   − 1 ⊗ q b k c 0 ⊗ γ b k + 1 b k ∥ 2 (3) \underset{\delta b_{w}}{min}\sum_{k\in\mathcal{B}} \left \| q^{c_{0} \ -1}_{b_{k+1}} \otimes q^{c_{0}}_{b_{k}} \otimes \gamma^{b_{k}}_{b_{k+1}}\right \|^{2} \tag{3} δbwminkBqbk+1c0 1qbkc0γbk+1bk2(3) 其中 B \mathcal{B} B为滑动窗口内的所有图像帧,另外对预积分进行一阶泰勒展开近似,即对其线性化: γ b k + 1 b k ≈ γ ^ b k + 1 b k ⊗ [ 1 1 2 J b w γ δ b w ] (4) \gamma^{b_{k}}_{b_{k+1}} \approx \hat {\gamma}^{b_{k}}_{b_{k+1}} \otimes \begin{bmatrix} 1 \\ \frac{1}{2}J^{\gamma}_{b_{w}}\delta b_{w} \end{bmatrix} \tag{4} γbk+1bkγ^bk+1bk[121Jbwγδbw](4) 由于在理想情况下,即当 q b k c 0   − 1 ⊗ q b k + 1 c 0 = γ b k + 1 b k q^{c_{0} \ -1 }_{b_{k}} \otimes q^{c_{0}}_{b_{k+1}} = \gamma^{b_{k}}_{b_{k+1}} qbkc0 1qbk+1c0=γbk+1bk,这俩个旋转的差异 ( q b k c 0   − 1 ⊗ q b k + 1 c 0 ) − 1 γ b k + 1 b k (q^{c_{0} \ -1 }_{b_{k}} \otimes q^{c_{0}}_{b_{k+1}})^{-1}\gamma^{b_{k}}_{b_{k+1}} (qbkc0 1qbk+1c0)1γbk+1bk的旋转角度为0,根据四元素的表示,可得虚部为 0 \mathbf{0} 0,实部为1: q b k + 1 c 0   − 1 ⊗ q b k c 0 ⊗ γ b k + 1 b k = [ 1 0 ] q^{c_{0} \ -1}_{b_{k+1}} \otimes q^{c_{0}}_{b_{k}} \otimes \gamma^{b_{k}}_{b_{k+1}} = \begin{bmatrix} 1 \\ \mathbf{0} \end{bmatrix} qbk+1c0 1qbkc0γbk+1bk=[10] 则有: γ b k + 1 b k = q b k c 0   − 1 ⊗ q b k + 1 c 0 ⊗ [ 1 0 ] (5) \gamma^{b_{k}}_{b_{k+1}} = q^{c_{0} \ -1}_{b_{k}} \otimes q^{c_{0}}_{b_{k+1}} \otimes \begin{bmatrix} 1 \\ \mathbf{0} \end{bmatrix} \tag{5} γbk+1bk=qbkc0 1qbk+1c0[10](5) 将公式(4)代入公式(5),得: γ ^ b k + 1 b k ⊗ [ 1 1 2 J b w γ δ b w ] = q b k c 0   − 1 ⊗ q b k + 1 c 0 ⊗ [ 1 0 ] \hat {\gamma}^{b_{k}}_{b_{k+1}} \otimes \begin{bmatrix} 1 \\ \frac{1}{2}J^{\gamma}_{b_{w}}\delta b_{w} \end{bmatrix} = q^{c_{0} \ -1}_{b_{k}} \otimes q^{c_{0}}_{b_{k+1}} \otimes \begin{bmatrix} 1 \\ \mathbf{0}\end{bmatrix} γ^bk+1bk[121Jbwγδbw]=qbkc0 1qbk+1c0[10] 当只考虑虚部(虚部为三维向量)的时候,我们有: J b w γ δ b w = 2 ⌊ γ ^ b k + 1 b k   − 1 ⊗ q b k c 0   − 1 ⊗ q b k + 1 c 0 ⌋ x y z J^{\gamma}_{b_{w}}\delta b_{w} =2 \left \lfloor \hat{\gamma}^{b_{k} \ -1}_{b_{k+1}} \otimes q^{c_{0} \ -1}_{b_{k}} \otimes q^{c_{0}}_{b_{k+1}} \right \rfloor_{xyz} Jbwγδbw=2γ^bk+1bk 1qbkc0 1qbk+1c0xyz 将左边转为对称矩阵,这样就可以直接用LDLT对系数矩阵进行分解了: J b w γ   T J b w γ δ b w = 2 J b w γ   T ⌊ γ ^ b k + 1 b k   − 1 ⊗ q b k c 0   − 1 ⊗ q b k + 1 c 0 ⌋ x y z → A x = b J^{\gamma \ T}_{b_{w}}J^{\gamma}_{b_{w}}\delta b_{w} =2 J^{\gamma \ T}_{b_{w}} \left \lfloor \hat{\gamma}^{b_{k} \ -1}_{b_{k+1}} \otimes q^{c_{0} \ -1}_{b_{k}} \otimes q^{c_{0}}_{b_{k+1}} \right \rfloor_{xyz} \rightarrow Ax=b Jbwγ TJbwγδbw=2Jbwγ Tγ^bk+1bk 1qbkc0 1qbk+1c0xyzAx=b 求出陀螺仪的偏置bias后,需要对IMU预积分进行重新计算。
代码见vins_estimator/initial/initial_aligment.cpp中的solveGyroscopeBias

3.2 速度、重力和尺度初始化 (利用预积分约束估计 v b k b k v^{b_{k}}_{b_{k}} vbkbk g c 0 g^{c_{0}} gc0 s s s)

对于当前部分需要了估计的变量有:【论文式(16)】 X I 3 n + 3 + 1 = [ v b 0 b 0 , v b 1 b 1 , ⋯   , v b n b n , g c 0 , s ] \mathcal{X}_{I}^{3n+3+1}=[v_{b_{0}}^{b_{0}}, v_{b_{1}}^{b_{1}}, \cdots ,v_{b_{n}}^{b_{n}}, g^{c_{0}}, s] XI3n+3+1=[vb0b0,vb1b1,,vbnbn,gc0,s] 其中, v b k b k v_{b_{k}}^{b_{k}} vbkbk表示 k k k时刻(捕获到图像的时刻)IMU body坐标系的速度在IMU body坐标系的表示, g c 0 g^{c_{0}} gc0为重力向量在第 0 0 0帧相机坐标系下的表示, s s s表示尺度因子,将视觉轨迹拉伸到米制单位。

在IMU预积分中我们已经推导过基于世界坐标系 w w w(东北天坐标系)的预积分量约束: R w b k p b k + 1 w = R w b k ( p b k w + v b k w ‾ Δ t k − 1 2 g w Δ t k 2 ) + α b k + 1 b k R^{b_{k}}_{w}p^{w}_{b_{k+1}} = R^{b_{k}}_{w}(p_{b_{k}}^{w}+\underline{v_{b_{k}}^{w}}\Delta t_{k}-\frac{1}{2}g^{w}\Delta t_{k}^{2})+\alpha_{b_{k+1}}^{b_{k}} Rwbkpbk+1w=Rwbk(pbkw+vbkwΔtk21gwΔtk2)+αbk+1bk R w b k v b k + 1 w ‾ = R w b k ( v b k w ‾ − g w Δ t k ) + β b k + 1 b k R^{b_{k}}_{w}\underline{v^{w}_{b_{k+1}}} = R^{b_{k}}_{w}(\underline{v^{w}_{b_{k}}}-g^{w}\Delta t_{k})+\beta_{b_{k+1}}^{b_{k}} Rwbkvbk+1w=Rwbk(vbkwgwΔtk)+βbk+1bk 将世界坐标系 w w w 换成相机初始时刻坐标系 c 0 c_{0} c0有: α b k + 1 b k = R c 0 b k ( s ( p ˉ b k + 1 c 0 − p ˉ b k c 0 ) + 1 2 g c 0 Δ t k 2 − R b k c 0 v b k b k ‾ Δ t k ) \alpha_{b_{k+1}}^{b_{k}} = R^{b_{k}}_{c_{0}}(s(\bar{p}^{c_{0}}_{b_{k+1}}-\bar{p}^{c_{0}}_{b_{k}})+\frac{1}{2} g^{c_{0}}\Delta t^{2}_{k}-\underline{R^{c_{0}}_{b_{k}}v^{b_{k}}_{b_{k}}}\Delta t_{k}) αbk+1bk=Rc0bk(s(pˉbk+1c0pˉbkc0)+21gc0Δtk2Rbkc0vbkbkΔtk) β b k + 1 b k = R c 0 b k ( R b k + 1 c 0 v b k + 1 b k + 1 ‾ − R b k c 0 v b k b k ‾ + g c 0 Δ t k ) \beta_{b_{k+1}}^{b_{k}} = R^{b_{k}}_{c_{0}}(\underline{R^{c_{0}}_{b_{k+1}}v^{b_{k+1}}_{b_{k+1}}}-\underline{R^{c_{0}}_{b_{k}}v^{b_{k}}_{b_{k}}}+g^{c_{0}} \Delta t_{k}) βbk+1bk=Rc0bk(Rbk+1c0vbk+1bk+1Rbkc0vbkbk+gc0Δtk)
将论文式(14) (即本文公式(2)) 代入 α b k + 1 b k \alpha_{b_{k+1}}^{b_{k}} αbk+1bk有: δ α b k + 1 b k = α b k + 1 b k − R c 0 b k ( s p ˉ b k + 1 c 0 − s p ˉ b k c 0 + 1 2 g c 0 Δ t k 2 − R b k c 0 v b k b k Δ t k ) = α b k + 1 b k − R c 0 b k ( s p ˉ c k + 1 c 0 − R b k + 1 c 0 p c b − ( s p ˉ c k c 0 − R b k c 0 p c b ) + 1 2 g c 0 Δ t k 2 − R b k c 0 v b k b k Δ t k ) = α b k + 1 b k − s R c 0 b k ( p ˉ c k + 1 c 0 − p ˉ c k c 0 ) + R c 0 b k R b k + 1 c 0 p c b − p c b + v b k b k Δ t k − 1 2 R c 0 b k g c 0 Δ t k 2 ) = 0 3 × 1 \delta \alpha^{b_{k}}_{b_{k+1}} = \alpha^{b_{k}}_{b_{k+1}}-R^{b_{k}}_{c_{0}}(s\bar{p}^{c_{0}}_{b_{k+1}}-s\bar{p}^{c_{0}}_{b_{k}}+\frac{1}{2} g^{c_{0}}\Delta t^{2}_{k}-R^{c_{0}}_{b_{k}}v^{b_{k}}_{b_{k}}\Delta t_{k}) \\= \alpha^{b_{k}}_{b_{k+1}}-R^{b_{k}}_{c_{0}}( s\bar{p}^{c_{0}}_{c_{k+1}}-R^{c_{0}}_{b_{k+1}}p^{b}_{c} -(s\bar{p}^{c_{0}}_{c_{k}}-R^{c_{0}}_{b_{k}}p^{b}_{c})+\frac{1}{2} g^{c_{0}}\Delta t^{2}_{k}-R^{c_{0}}_{b_{k}}v^{b_{k}}_{b_{k}}\Delta t_{k}) \\ = \alpha^{b_{k}}_{b_{k+1}}-sR^{b_{k}}_{c_{0}}( \bar{p}^{c_{0}}_{c_{k+1}}-\bar{p}^{c_{0}}_{c_{k}}) + R^{b_{k}}_{c_{0}}R^{c_{0}}_{b_{k+1}}p^{b}_{c} - p^{b}_{c}+v^{b_{k}}_{b_{k}}\Delta t_{k}-\frac{1}{2}R^{b_{k}}_{c_{0}} g^{c_{0}}\Delta t^{2}_{k}) = 0_{3 \times 1} δαbk+1bk=αbk+1bkRc0bk(spˉbk+1c0spˉbkc0+21gc0Δtk2Rbkc0vbkbkΔtk)=αbk+1bkRc0bk(spˉck+1c0Rbk+1c0pcb(spˉckc0Rbkc0pcb)+21gc0Δtk2Rbkc0vbkbkΔtk)=αbk+1bksRc0bk(pˉck+1c0pˉckc0)+Rc0bkRbk+1c0pcbpcb+vbkbkΔtk21Rc0bkgc0Δtk2)=03×1 这里 v b k b k v_{b_{k}}^{b_{k}} vbkbk g c 0 g^{c_{0}} gc0 s s s均为待优化变量,将其转成 A x = b Ax=b Ax=b的形式:
R c 0 b k ( p ˉ c k + 1 c 0 − p ˉ c k c 0 ) s − v b k b k Δ t k + 1 2 R c 0 b k g c 0 Δ t k 2 = α b k + 1 b k + R c 0 b k R b k + 1 c 0 p c b − p c b (6) R^{b_{k}}_{c_{0}}(\bar{p}^{c_{0}}_{c_{k+1}}-\bar{p}^{c_{0}}_{c_{k}})s-v^{b_{k}}_{b_{k}}\Delta t_{k}+\frac{1}{2}R^{b_{k}}_{c_{0}}g^{c_{0}}\Delta t_{k}^{2} = \alpha^{b_{k}}_{b_{k+1}}+R^{b_{k}}_{c_{0}}R^{c_{0}}_{b_{k+1}}p^{b}_{c}-p^{b}_{c} \tag{6} Rc0bk(pˉck+1c0pˉckc0)svbkbkΔtk+21Rc0bkgc0Δtk2=αbk+1bk+Rc0bkRbk+1c0pcbpcb(6) 对于 β b k + 1 b k \beta^{b_{k}}_{b_{k+1}} βbk+1bk, 则有 δ β b k + 1 b k = β b k + 1 b k − R c 0 b k ( R b k + 1 c 0 v b k + 1 b k + 1 − R b k c 0 v b k b k + g c 0 Δ t k ) = 0 3 × 1 \delta \beta_{b_{k+1}}^{b_{k}}=\beta^{b_{k}}_{b_{k+1}}-R^{b_{k}}_{c_{0}}(R^{c_{0}}_{b_{k+1}}v^{b_{k+1}}_{b_{k+1}}-R^{c_{0}}_{b_{k}}v^{b_{k}}_{b_{k}}+g^{c_{0}}\Delta t_{k}) = 0_{3\times 1} δβbk+1bk=βbk+1bkRc0bk(Rbk+1c0vbk+1bk+1Rbkc0vbkbk+gc0Δtk)=03×1 这里的优化变量 v b k b k v^{b_{k}}_{b_{k}} vbkbk v b k + 1 b k + 1 v^{b_{k+1}}_{b_{k+1}} vbk+1bk+1 g c 0 g^{c_{0}} gc0,将其转成 A x = b Ax=b Ax=b的形式:
R c 0 b k R b k + 1 c 0 v b k + 1 b k + 1 − R c 0 b k R b k c 0 v b k b k + R c 0 b k g c 0 Δ t k = β b k + 1 b k (7) R^{b_{k}}_{c_{0}}R^{c_{0}}_{b_{k+1}}v^{b_{k+1}}_{b_{k+1}}-R^{b_{k}}_{c_{0}}R^{c_{0}}_{b_{k}}v^{b_{k}}_{b_{k}}+R^{b_{k}}_{c_{0}}g^{c_{0}}\Delta t_{k} = \beta^{b_{k}}_{b_{k+1}} \tag{7} Rc0bkRbk+1c0vbk+1bk+1Rc0bkRbkc0vbkbk+Rc0bkgc0Δtk=βbk+1bk(7) 将公式(6)(7)写出矩阵的形式:论文式【(18)(19)】
H b k + 1 b k X I + n b k + 1 b k = [ − I Δ t k 0 1 2 R c 0 b k Δ t k 2 R c 0 b k ( p ˉ c k + 1 c 0 − p ˉ c k c 0 ) − I R c 0 b k R b k + 1 c 0 R c 0 b k Δ t k 0 ] 6 × 10 [ v b k b k v b k + 1 b k + 1 g c 0 s ] 10 × 1 + n b k + 1 b k = [ α b k + 1 b k + R c 0 b k R b k + 1 c 0 p c b − p c b β b k + 1 b k ] 6 × 1 = z ^ b k + 1 b k (8) H^{b_{k}}_{b_{k+1}} \mathcal{X}_{I} + n^{b_{k}}_{b_{k+1}}= \begin{bmatrix} -I \Delta t_{k} & 0 &\frac{1}{2}R^{b_{k}}_{c_{0}}\Delta t_{k}^{2} & R^{b_{k}}_{c_{0}}(\bar{p}^{c_{0}}_{c_{k+1}}-\bar{p}^{c_{0}}_{c_{k}}) \\ -I & R^{b_{k}}_{c_{0}}R^{c_{0}}_{b_{k+1}} & R^{b_{k}}_{c_{0}}\Delta t_{k} & 0\end{bmatrix}_{6\times10}\begin{bmatrix} v^{b_{k}}_{b_{k}} \\ v^{b_{k+1}}_{b_{k+1}}\\ g^{c^{0}} \\ s\end{bmatrix}_{10 \times 1} + n^{b_{k}}_{b_{k+1}} \\ = \begin{bmatrix} \alpha^{b_{k}}_{b_{k+1}}+R^{b_{k}}_{c_{0}}R^{c_{0}}_{b_{k+1}}p^{b}_{c}-p^{b}_{c} \\ \beta^{b_{k}}_{b_{k+1}}\end{bmatrix}_{6 \times 1} = \hat{z}^{b_{k}}_{b_{k+1}} \tag{8} Hbk+1bkXI+nbk+1bk=[IΔtkI0Rc0bkRbk+1c021Rc0bkΔtk2Rc0bkΔtkRc0bk(pˉck+1c0pˉckc0)0]6×10vbkbkvbk+1bk+1gc0s10×1+nbk+1bk=[αbk+1bk+Rc0bkRbk+1c0pcbpcbβbk+1bk]6×1=z^bk+1bk(8)其中 R b k c 0 R_{b_{k}}^{c_{0}} Rbkc0 R b k + 1 c 0 R^{c_{0}}_{b_{k+1}} Rbk+1c0 p ˉ b k c 0 \bar{p}_{b_{k}}^{c_{0}} pˉbkc0 p ˉ c k c 0 \bar{p}_{c_{k}}^{c_{0}} pˉckc0可从视觉的SFM获得, Δ t k \Delta t_{k} Δtk为相邻俩帧图像之间的时间间隔。
公式(8)转换成线性最小二乘问题对状态量进行求解: m i n X I ∑ k ∈ B ∣ ∣ z ^ b k + 1 b k − H b k + 1 b k X I k ∣ ∣ 2 \underset{\mathcal{X_{I}}}{min}\sum_{k\in \mathcal{B}} ||\hat{z}^{b_{k}}_{b_{k+1}}-H^{b_{k}}_{b_{k+1}}\mathcal{X}^{k}_{I}||^{2} XIminkBz^bk+1bkHbk+1bkXIk2 从矩阵角度来看,也看看做解方程 H b k + 1 b k X I k = z ^ b k + 1 b k → A x = b H^{b_{k}}_{b_{k+1}}\mathcal{X}^{k}_{I}=\hat{z}^{b_{k}}_{b_{k+1}} \rightarrow Ax=b Hbk+1bkXIk=z^bk+1bkAx=b
为了将矩阵系统化为矩阵利用LDLT求解,可得 H b k + 1 b k   T H b k + 1 b k X I k = H b k + 1 b k   T z ^ b k + 1 b k → A x = b H^{b_{k} \ T}_{b_{k+1}}H^{b_{k}}_{b_{k+1}}\mathcal{X}^{k}_{I}=H^{b_{k} \ T}_{b_{k+1}}\hat{z}^{b_{k}}_{b_{k+1}} \rightarrow Ax=b Hbk+1bk THbk+1bkXIk=Hbk+1bk Tz^bk+1bkAx=b,得到如下情况:
VINS-Mono之外参标定和视觉IMU联合初始化_第2张图片
具体代码见 vins_estimator/initial/initial_aligment.cpp中的LinearAlignment().
在vins_mono代码中,由于具有多个 v b k b k v^{bk}_{b_{k}} vbkbk需要优化,因此vins_mono将优化的变量均放在一个矩阵中,如下图所示:
VINS-Mono之外参标定和视觉IMU联合初始化_第3张图片
如上图所示考虑了将 ( v b 1 b 1 , v b 2 b 2 , g c 0 , s ) (v^{b1}_{b1}, v^{b2}_{b2}, g^{c_{0}},s) (vb1b1,vb2b2,gc0,s) ( v b 2 b 2 , v b 3 b 3 , g c 0 , s ) (v^{b2}_{b2}, v^{b3}_{b3}, g^{c_{0}},s) (vb2b2,vb3b3,gc0,s) ( v b 3 b 3 , v b 4 b 4 , g c 0 , s ) (v^{b3}_{b3}, v^{b4}_{b4}, g^{c_{0}},s) (vb3b3,vb4b4,gc0,s)等三组变量构建的 A x = b Ax=b Ax=b放在了一个大矩阵中,其中蓝色框代表非零项,数字代表融合次数,未标数字代表1次融合。

3.3 优化重力向量 g c 0 g^{c_{0}} gc0

为什么需要优化重力向量?
利用公式(8)求解的重力向量并没有模长的限制,即 ∣ ∣ g c 0 ∣ ∣ = 9.81 ||g^{c_{0}}||=9.81 gc0=9.81,因此重力向量 g c 0 g^{c_{0}} gc0实际上只有俩个自由度。
VINS-Mono之外参标定和视觉IMU联合初始化_第4张图片
采用球面坐标,在切面空间上用两个变量重新参数化重力,将其表示为: g c 0 ^ = ∣ ∣ g ∣ ∣ ⋅ g ˉ ^ c 0 + w 1 b → 1 + w 2 b → 2 = ∣ ∣ g ∣ ∣ ⋅ g ˉ ^ c 0 + b → w \hat{g^{c_{0}}} = ||g|| \cdot \hat{\bar{g}}^{c_{0}}+w_{1}\overrightarrow{b}_{1}+w_{2}\overrightarrow{b}_{2} = ||g|| \cdot \hat{\bar{g}}^{c_{0}} + \overrightarrow{b}w gc0^=ggˉ^c0+w1b 1+w2b 2=ggˉ^c0+b w 其中 g ˉ ^ c 0 \hat{\bar{g}}^{c_{0}} gˉ^c0为上一部分公式(8)得到的重力向量初始值的单位向量, w 2 × 1 = [ w 1 , w 2 ] w_{2 \times 1} = [w_{1}, w_{2}] w2×1=[w1,w2]为待优化变量, b → 3 × 2 = [ b → 1 , b → 2 ] \overrightarrow{b}_{3\times 2} = [\overrightarrow{b}_{1},\overrightarrow{b}_{2}] b 3×2=[b 1,b 2]​中的 b → 1 , b → 2 \overrightarrow{b}_{1},\overrightarrow{b}_{2} b 1,b 2 ∣ ∣ g ∣ ∣ ⋅ g ˉ ^ c 0 ||g|| \cdot \hat{\bar{g}}^{c_{0}} ggˉ^c0的正切平面上且正交,定义如下: b → 1 = { ( g ˉ ^ c 0 × [ 1 , 0 , 0 ] ) ,   g ˉ ^ c 0 ≠ [ 1 , 0 , 0 ] T ( g ˉ ^ c 0 × [ 0 , 0 , 1 ] ) ,   o t h e r w i s e   ,   b → 2 = g ˉ ^ c 0 × b → 1 \overrightarrow{b}_{1}= \left\{\begin{matrix} (\hat{\bar{g}}^{c_{0}} \times [1, 0 ,0]), \ \hat{\bar{g}}^{c_{0}} \neq [1,0,0]^{T} \\ (\hat{\bar{g}}^{c_{0}} \times [0, 0 ,1]), \ otherwise \end{matrix}\right. \ , \ \overrightarrow{b}_{2} = \hat{\bar{g}}^{c_{0}} \times \overrightarrow{b}_{1} b 1={(gˉ^c0×[1,0,0]), gˉ^c0=[1,0,0]T(gˉ^c0×[0,0,1]), otherwise , b 2=gˉ^c0×b 1 因此优化变量将从 g c 0 g^{c_{0}} gc0(三个自由度)变为 w c 0 w^{c_{0}} wc0(俩个自由度):
H b k + 1 b k X I + n b k + 1 b k = [ − I Δ t k 0 1 2 R c 0 b k Δ t k 2 b → R c 0 b k ( p ˉ c k + 1 c 0 − p ˉ c k c 0 ) − I R c 0 b k R b k + 1 c 0 R c 0 b k Δ t k b → 0 ] 6 × 9 [ v b k b k v b k + 1 b k + 1 w s ] 9 × 1 + n b k + 1 b k = [ α b k + 1 b k + R c 0 b k R b k + 1 c 0 p c b − p c b − 1 2 R c 0 b k Δ t k ∣ ∣ g ∣ ∣ ⋅ g ˉ ^ c 0 β b k + 1 b k − R c 0 b k Δ t k ∣ ∣ g ∣ ∣ ⋅ g ˉ ^ c 0 ] 6 × 1 = z ^ b k + 1 b k (8) H^{b_{k}}_{b_{k+1}} \mathcal{X}_{I} + n^{b_{k}}_{b_{k+1}}= \begin{bmatrix} -I \Delta t_{k} & 0 &\frac{1}{2}R^{b_{k}}_{c_{0}}\Delta t_{k}^{2} \overrightarrow{b} & R^{b_{k}}_{c_{0}}(\bar{p}^{c_{0}}_{c_{k+1}}-\bar{p}^{c_{0}}_{c_{k}}) \\ -I & R^{b_{k}}_{c_{0}}R^{c_{0}}_{b_{k+1}} & R^{b_{k}}_{c_{0}}\Delta t_{k} \overrightarrow{b} & 0\end{bmatrix}_{6\times 9}\begin{bmatrix} v^{b_{k}}_{b_{k}} \\ v^{b_{k+1}}_{b_{k+1}}\\ w \\ s\end{bmatrix}_{9 \times 1} + n^{b_{k}}_{b_{k+1}} \\ = \begin{bmatrix} \alpha^{b_{k}}_{b_{k+1}}+R^{b_{k}}_{c_{0}}R^{c_{0}}_{b_{k+1}}p^{b}_{c}-p^{b}_{c}-\frac{1}{2}R^{b_{k}}_{c_{0}}\Delta t_{k}||g|| \cdot \hat{\bar{g}}^{c_{0}}\\ \beta^{b_{k}}_{b_{k+1}}-R^{b_{k}}_{c_{0}}\Delta t_{k}||g|| \cdot \hat{\bar{g}}^{c_{0}}\end{bmatrix}_{6 \times 1} = \hat{z}^{b_{k}}_{b_{k+1}} \tag{8} Hbk+1bkXI+nbk+1bk=[IΔtkI0Rc0bkRbk+1c021Rc0bkΔtk2b Rc0bkΔtkb Rc0bk(pˉck+1c0pˉckc0)0]6×9vbkbkvbk+1bk+1ws9×1+nbk+1bk=[αbk+1bk+Rc0bkRbk+1c0pcbpcb21Rc0bkΔtkggˉ^c0βbk+1bkRc0bkΔtkggˉ^c0]6×1=z^bk+1bk(8)
采用最小二乘对待优化变量 X I \mathcal{X}_{I} XI进行重新优化。
具体代码见 vins_estimator/initial/initial_aligment.cpp中的RefineGrivity().
在代码中,当完成4次迭代完成 w 2 × 1 = [ w 1 , w 2 ] T w_{2 \times 1} =[w_{1}, w_{2}]^{T} w2×1=[w1,w2]T的求解后和 g c 0 g^{c_{0}} gc0的每次更新,有 g ^ c 0 = ( g c 0 + [ b → 1 , b → 2 ] ∗ [ w 1 , w 2 ] T ) \hat{g}^{c_{0}} = (g^{c_{0}}+[\overrightarrow{b}_{1},\overrightarrow{b}_{2}]*[w_{1}, w_{2}]^{T}) g^c0=(gc0+[b 1,b 2][w1,w2]T),则最后的重力向量为: g c 0 = g ^ c 0 ∣ ∣ g ^ c 0 ∣ ∣ ∗ ∣ ∣ g ∣ ∣ {g}^{c_{0}}=\frac{\hat{g}^{c_{0}} }{||\hat{g}^{c_{0}} ||} *||g|| gc0g^c0g^c0g

3.4 对齐导航世界坐标系

由于我们的求解都是在第一帧相机坐标系 c 0 c^{0} c0的,因此需要计算 R c 0 w R^{w}_{c_{0}} Rc0w将所有 c 0 c^{0} c0坐标系下的变量转到世界坐标系下,令
R c 0 w = e x p ( [ θ a ] ) R^{w}_{c_{0}}=exp([\theta \mathbf{a}]) Rc0w=exp([θa]) g ^ c 0 \hat{g}^{c_{0}} g^c0为重力细化后得到的 c 0 c^{0} c0坐标系的重力向量, g w = [ 0 , 0 , 9.81 ] T g^{w}=[0,0,9.81]^{T} gw=[0,0,9.81]T为世界坐标系下的重力向量,故单位旋转轴 a \mathbf{a} a为: a = g ^ c 0 × g ^ w ∣ ∣ g ^ c 0 × g ^ w ∣ ∣ \mathbf{a}=\frac{\hat{g}^{c_{0}} \times \hat{g}^{w}}{||\hat{g}^{c_{0}} \times \hat{g}^{w}||} a=g^c0×g^wg^c0×g^w 旋转角度 θ \theta θ为: θ = a t a n g ^ c 0 × g ^ w g ^ c 0 ⋅ g ^ w = a t a n ∣ ∣ g ^ c 0 ∣ ∣ ⋅ ∣ ∣ g ^ w ∣ ∣ sin ⁡ θ ∣ ∣ g ^ c 0 ∣ ∣ ⋅ ∣ ∣ g ^ w ∣ ∣ cos ⁡ θ \theta=atan \frac{\hat{g}^{c_{0}} \times \hat{g}^{w}}{\hat{g}^{c_{0}} \cdot \hat{g}^{w}} =atan \frac{||\hat{g}^{c_{0}}|| \cdot ||\hat{g}^{w}|| \sin \theta}{||\hat{g}^{c_{0}}|| \cdot ||\hat{g}^{w}|| \cos \theta} θ=atang^c0g^wg^c0×g^w=atang^c0g^wcosθg^c0g^wsinθ

问题1: 加速度的偏置 b a t b_{at} bat为什么没有估计?
由于线性加速度的模型为: a ^ t = a t + b a t + R w t g w + n a \hat{a}_{t} = a_{t}+b_{at}+R_{w}^{t}g^{w}+n_{a} a^t=at+bat+Rwtgw+na,由于有重力的作用,加速度偏置 b a b_{a} ba R w t g w R_{w}^{t}g^{w} Rwtgw几个数量级,很难在初始化的时候估计重力向量的同时估计出加速度偏置,故没必要初始化加速度偏置的初始值 b a t b_{at} bat

问题2:平移外参数 p c b p^{b}_{c} pcb为何没有初始化?
由于平移相比于旋转而言,对于系统来�

你可能感兴趣的:(Visual,Inertial,Odometry)