VIO系统在使用IMU测量值进行状态预测时,需要将连续时间的微分方程离散化为差分方程,离散化的本质是积分,根据数值积分近似程度不同,常用的有欧拉法、中点法和四阶龙格库塔法等,OpenVINS和MSCKF_VIO虽然都使用RK4积分,但具体代码实现却有所区别。
一、MSCKF_VIO RK4积分
姿态使用JPL四元数表示,MSCKF_VIO姿态不使用RK4积分,而是直接使用Zeroth Order Quaternion Integrator
积分器,输入是
t
n
t_n
tn时刻的角速度测量值,得到
t
n
+
Δ
t
{t_n} + \Delta t
tn+Δt和
t
n
+
Δ
t
2
{t_n} + \frac{\Delta t}{2}
tn+2Δt时刻的姿态,
ω
=
ω
m
t
n
−
b
g
w
b
q
t
n
+
Δ
t
=
[
ω
∣
ω
∣
sin
(
∣
ω
∣
2
Δ
t
)
cos
(
∣
ω
∣
2
Δ
t
)
]
⊗
w
b
q
t
n
=
(
cos
(
∣
ω
∣
2
Δ
t
)
⋅
I
4
×
4
+
1
∣
ω
∣
sin
(
∣
ω
∣
2
Δ
t
)
⋅
Ω
(
ω
)
)
w
b
q
t
n
w
b
q
t
n
+
Δ
t
2
=
[
ω
∣
ω
∣
sin
(
∣
ω
∣
4
Δ
t
)
cos
(
∣
ω
∣
4
Δ
t
)
]
⊗
w
b
q
t
n
=
(
cos
(
∣
ω
∣
4
Δ
t
)
⋅
I
4
×
4
+
1
∣
ω
∣
sin
(
∣
ω
∣
4
Δ
t
)
⋅
Ω
(
ω
)
)
w
b
q
t
n
\begin{aligned} \boldsymbol{\omega} &= \boldsymbol{\omega}_{m_{t_n}} - \mathbf{b}_g \\ {}^b_w q_{{t_n} + \Delta t} &= \begin{bmatrix} \frac{\boldsymbol{\omega}}{|\boldsymbol{\omega}|} \sin \left(\frac{|\boldsymbol{\omega}|}{2} \Delta t\right) \\ \cos \left(\frac{|\boldsymbol{\omega}|}{2} \Delta t\right) \end{bmatrix} \otimes {}^b_w q_{{t_n}} = \left(\cos \left(\frac{|\boldsymbol{\omega}|}{2} \Delta t\right) \cdot \mathbf{I}_{4 \times 4}+\frac{1}{|\boldsymbol{\omega}|} \sin \left(\frac{|\boldsymbol{\omega}|}{2} \Delta t\right) \cdot \boldsymbol{\Omega}(\boldsymbol{\omega})\right) {}^b_w q_{{t_n}} \\ {}^b_w q_{{t_n} + \frac{\Delta t}{2}} &= \begin{bmatrix} \frac{\boldsymbol{\omega}}{|\boldsymbol{\omega}|} \sin \left(\frac{|\boldsymbol{\omega}|}{4} \Delta t\right) \\ \cos \left(\frac{|\boldsymbol{\omega}|}{4} \Delta t\right) \end{bmatrix} \otimes {}^b_w q_{{t_n}} = \left(\cos \left(\frac{|\boldsymbol{\omega}|}{4} \Delta t\right) \cdot \mathbf{I}_{4 \times 4}+\frac{1}{|\boldsymbol{\omega}|} \sin \left(\frac{|\boldsymbol{\omega}|}{4} \Delta t\right) \cdot \boldsymbol{\Omega}(\boldsymbol{\omega})\right) {}^b_w q_{{t_n}} \end{aligned}
ωwbqtn+Δtwbqtn+2Δt=ωmtn−bg=
∣ω∣ωsin(2∣ω∣Δt)cos(2∣ω∣Δt)
⊗wbqtn=(cos(2∣ω∣Δt)⋅I4×4+∣ω∣1sin(2∣ω∣Δt)⋅Ω(ω))wbqtn=
∣ω∣ωsin(4∣ω∣Δt)cos(4∣ω∣Δt)
⊗wbqtn=(cos(4∣ω∣Δt)⋅I4×4+∣ω∣1sin(4∣ω∣Δt)⋅Ω(ω))wbqtn
输入
t
n
t_n
tn时刻的加速度测量值,对位置和速度进行RK4积分
v
0
=
v
t
n
k
1
=
[
p
˙
1
v
˙
1
]
=
[
v
0
R
{
w
b
q
t
n
}
⊤
(
a
m
t
n
−
b
a
)
+
g
]
k
2
=
[
p
˙
2
v
˙
2
]
=
[
v
0
+
Δ
t
2
v
˙
1
R
{
w
b
q
t
n
+
Δ
t
2
}
⊤
(
a
m
t
n
−
b
a
)
+
g
]
k
3
=
[
p
˙
3
v
˙
3
]
=
[
v
0
+
Δ
t
2
v
˙
2
R
{
w
b
q
t
n
+
Δ
t
2
}
⊤
(
a
m
t
n
−
b
a
)
+
g
]
k
4
=
[
p
˙
4
v
˙
4
]
=
[
v
0
+
Δ
t
v
˙
3
R
{
w
b
q
t
n
+
Δ
t
}
⊤
(
a
m
t
n
−
b
a
)
+
g
]
\begin{aligned} \mathbf{v}_{0} &= \mathbf{v}_{t_{n}} \\ k_{1} &= \begin{bmatrix} \dot{\mathbf{p}}_{1} \\ \dot{\mathbf{v}}_{1} \end{bmatrix} = \begin{bmatrix} \mathbf{v}_{0} \\ \mathbf{R} \{ {}^b_w q_{{t_n}} \}^\top (\mathbf{a}_{m_{t_n}} - \mathbf{b}_a) + \mathbf{g} \end{bmatrix} \\ k_{2} &= \begin{bmatrix} \dot{\mathbf{p}}_{2} \\ \dot{\mathbf{v}}_{2} \end{bmatrix} = \begin{bmatrix} {\mathbf{v}}_{0} + \frac{\Delta t}{2} \dot{\mathbf{v}}_{1} \\ \mathbf{R} \{ {}^b_w q_{{{t_n} + \frac{\Delta t}{2}}} \}^\top (\mathbf{a}_{m_{t_n}} - \mathbf{b}_a) + \mathbf{g} \end{bmatrix} \\ k_{3} &= \begin{bmatrix} \dot{\mathbf{p}}_{3} \\ \dot{\mathbf{v}}_{3} \end{bmatrix} = \begin{bmatrix} {\mathbf{v}}_{0} + \frac{\Delta t}{2} \dot{\mathbf{v}}_{2} \\ \mathbf{R} \{ {}^b_w q_{{{t_n} + \frac{\Delta t}{2}}} \}^\top (\mathbf{a}_{m_{t_n}} - \mathbf{b}_a) + \mathbf{g} \end{bmatrix} \\ k_{4} &= \begin{bmatrix} \dot{\mathbf{p}}_{4} \\ \dot{\mathbf{v}}_{4} \end{bmatrix} = \begin{bmatrix} {\mathbf{v}}_{0} + \Delta t \dot{\mathbf{v}}_{3} \\ \mathbf{R} \{ {}^b_w q_{{{t_n} + \Delta t}} \}^\top (\mathbf{a}_{m_{t_n}} - \mathbf{b}_a) + \mathbf{g} \end{bmatrix} \end{aligned}
v0k1k2k3k4=vtn=[p˙1v˙1]=[v0R{wbqtn}⊤(amtn−ba)+g]=[p˙2v˙2]=[v0+2Δtv˙1R{wbqtn+2Δt}⊤(amtn−ba)+g]=[p˙3v˙3]=[v0+2Δtv˙2R{wbqtn+2Δt}⊤(amtn−ba)+g]=[p˙4v˙4]=[v0+Δtv˙3R{wbqtn+Δt}⊤(amtn−ba)+g]
[ q t n + Δ t p t n + Δ t v t n + Δ t ] = [ w b q t n + Δ t p t n + Δ t 6 ( p ˙ 1 + 2 p ˙ 2 + 2 p ˙ 3 + p ˙ 4 ) v t n + Δ t 6 ( v ˙ 1 + 2 v ˙ 2 + 2 v ˙ 3 + v ˙ 4 ) ] \begin{bmatrix} \mathbf{q}_{{t_n} + \Delta t} \\ \mathbf{p}_{{t_n} + \Delta t} \\ \mathbf{v}_{{t_n} + \Delta t} \end{bmatrix} = \begin{bmatrix} {}^b_w \mathbf{q}_{{{t_n} + \Delta t}} \\ \mathbf{p}_{{t_n}} + \frac{\Delta t}{6} \left( \dot{\mathbf{p}}_{1} + 2 \dot{\mathbf{p}}_{2} + 2 \dot{\mathbf{p}}_{3} + \dot{\mathbf{p}}_{4} \right) \\ \mathbf{v}_{{t_n}} + \frac{\Delta t}{6} \left( \dot{\mathbf{v}}_{1} + 2 \dot{\mathbf{v}}_{2} + 2 \dot{\mathbf{v}}_{3} + \dot{\mathbf{v}}_{4} \right) \end{bmatrix} qtn+Δtptn+Δtvtn+Δt = wbqtn+Δtptn+6Δt(p˙1+2p˙2+2p˙3+p˙4)vtn+6Δt(v˙1+2v˙2+2v˙3+v˙4)
二、OpenVINS RK4积分
输入
t
n
t_n
tn和
t
n
+
1
t_{n+1}
tn+1时刻的角速度和加速度测量值,计算角加速度和加加速度(jerk)
α
=
(
ω
m
t
n
+
1
−
b
g
)
−
(
ω
m
t
n
−
b
g
)
Δ
t
j
=
(
a
m
t
n
+
1
−
b
a
)
−
(
a
m
t
n
−
b
a
)
Δ
t
\boldsymbol{\alpha} = \frac{(\boldsymbol{\omega}_{m_{t_{n+1}}} - \mathbf{b}_g) - (\boldsymbol{\omega}_{m_{t_{n}}} - \mathbf{b}_g)}{\Delta t} \\ \mathbf{j} = \frac{(\mathbf{a}_{m_{t_{n+1}}} - \mathbf{b}_a) - (\mathbf{a}_{m_{t_{n}}} - \mathbf{b}_a)}{\Delta t} \\
α=Δt(ωmtn+1−bg)−(ωmtn−bg)j=Δt(amtn+1−ba)−(amtn−ba)
姿态使用JPL四元数表示,姿态积分时有一个trick,积分并不是从
t
n
t_n
tn时刻的姿态开始的,而是从0姿态开始
v
0
=
v
t
n
q
0
=
w
b
q
t
n
Δ
q
0
=
[
0
0
0
1
]
k
1
=
[
Δ
q
˙
1
p
˙
1
v
˙
1
]
=
[
1
2
Ω
(
ω
m
t
n
−
b
g
)
Δ
q
0
v
0
R
{
Δ
q
0
⊗
q
0
}
⊤
(
a
m
t
n
−
b
a
)
−
g
]
Δ
q
1
=
norm
(
Δ
q
0
+
Δ
t
2
Δ
q
˙
1
)
k
2
=
[
Δ
q
˙
2
p
˙
2
v
˙
2
]
=
[
1
2
Ω
(
ω
m
t
n
−
b
g
+
Δ
t
2
α
)
Δ
q
1
v
0
+
Δ
t
2
v
˙
1
R
{
Δ
q
1
⊗
q
0
}
⊤
(
a
m
t
n
−
b
a
+
Δ
t
2
j
)
−
g
]
Δ
q
2
=
norm
(
Δ
q
0
+
Δ
t
2
Δ
q
˙
2
)
k
3
=
[
Δ
q
˙
3
p
˙
3
v
˙
3
]
=
[
1
2
Ω
(
ω
m
t
n
−
b
g
+
Δ
t
2
α
)
Δ
q
2
v
0
+
Δ
t
2
v
˙
2
R
{
Δ
q
2
⊗
q
0
}
⊤
(
a
m
t
n
−
b
a
+
Δ
t
2
j
)
−
g
]
Δ
q
3
=
norm
(
Δ
q
0
+
Δ
t
Δ
q
˙
3
)
k
4
=
[
Δ
q
˙
4
p
˙
4
v
˙
4
]
=
[
1
2
Ω
(
ω
m
t
n
−
b
g
+
Δ
t
α
)
Δ
q
3
v
0
+
Δ
t
v
˙
3
R
{
Δ
q
3
⊗
q
0
}
⊤
(
a
m
t
n
−
b
a
+
Δ
t
j
)
−
g
]
\begin{aligned} \mathbf{v}_{0} &= \mathbf{v}_{t_{n}} \\ \mathbf{q}_0 &= {}^b_w \mathbf{q}_{t_n} \\ \Delta \mathbf{q}_0 &= \begin{bmatrix} 0 & 0 & 0 & 1 \end{bmatrix} \\ k_{1} &= \begin{bmatrix} \dot{\Delta \mathbf{q}}_{1} \\ \dot{\mathbf{p}}_{1} \\ \dot{\mathbf{v}}_{1} \end{bmatrix} = \begin{bmatrix} \frac{1}{2} \boldsymbol{\Omega}(\boldsymbol{\omega}_{m_{t_{n}}} - \mathbf{b}_g) \Delta \mathbf{q}_0 \\ \mathbf{v}_0 \\ \mathbf R \{\Delta \mathbf{q}_0 \otimes \mathbf{q}_0 \}^\top (\mathbf{a}_{m_{t_{n}}} - \mathbf{b}_a) - \mathbf{g} \end{bmatrix} \\ \Delta \mathbf{q}_1 &= \text{norm} \left( \Delta \mathbf{q}_0 + \frac{\Delta t}{2} \dot{\Delta \mathbf{q}}_{1} \right) \\ k_{2} &= \begin{bmatrix} \dot{\Delta \mathbf{q}}_{2} \\ \dot{\mathbf{p}}_{2} \\ \dot{\mathbf{v}}_{2} \end{bmatrix} = \begin{bmatrix} \frac{1}{2} \boldsymbol{\Omega}(\boldsymbol{\omega}_{m_{t_{n}}} - \mathbf{b}_g + \frac{\Delta t}{2} \boldsymbol{\alpha}) \Delta \mathbf{q}_1 \\ \mathbf{v}_0 + \frac{\Delta t}{2} \dot{\mathbf{v}}_{1} \\ \mathbf R \{ \Delta \mathbf{q}_1 \otimes \mathbf{q}_0 \}^\top (\mathbf{a}_{m_{t_{n}}} - \mathbf{b}_a + \frac{\Delta t}{2} \mathbf{j}) - \mathbf{g} \end{bmatrix} \\ \Delta \mathbf{q}_2 &= \text{norm} \left( \Delta \mathbf{q}_0 + \frac{\Delta t}{2} \dot{\Delta \mathbf{q}}_{2} \right) \\ k_{3} &= \begin{bmatrix} \dot{\Delta \mathbf{q}}_{3} \\ \dot{\mathbf{p}}_{3} \\ \dot{\mathbf{v}}_{3} \end{bmatrix} = \begin{bmatrix} \frac{1}{2} \boldsymbol{\Omega}(\boldsymbol{\omega}_{m_{t_{n}}} - \mathbf{b}_g + \frac{\Delta t}{2} \boldsymbol{\alpha}) \Delta \mathbf{q}_2 \\ \mathbf{v}_0 + \frac{\Delta t}{2} \dot{\mathbf{v}}_{2} \\ \mathbf R \{ \Delta \mathbf{q}_2 \otimes \mathbf{q}_0 \}^\top (\mathbf{a}_{m_{t_{n}}} - \mathbf{b}_a + \frac{\Delta t}{2} \mathbf{j}) - \mathbf{g} \end{bmatrix} \\ \Delta \mathbf{q}_3 &= \text{norm} \left( \Delta \mathbf{q}_0 + \Delta t \dot{\Delta \mathbf{q}}_{3} \right) \\ k_{4} &= \begin{bmatrix} \dot{\Delta \mathbf{q}}_{4} \\ \dot{\mathbf{p}}_{4} \\ \dot{\mathbf{v}}_{4} \end{bmatrix} = \begin{bmatrix} \frac{1}{2} \boldsymbol{\Omega}(\boldsymbol{\omega}_{m_{t_{n}}} - \mathbf{b}_g + \Delta t \boldsymbol{\alpha}) \Delta \mathbf{q}_3 \\ \mathbf{v}_0 + \Delta t \dot{\mathbf{v}}_{3} \\ \mathbf R \{ \Delta \mathbf{q}_3 \otimes \mathbf{q}_0 \}^\top (\mathbf{a}_{m_{t_{n}}} - \mathbf{b}_a + \Delta t \mathbf{j}) - \mathbf{g} \end{bmatrix} \end{aligned}
v0q0Δq0k1Δq1k2Δq2k3Δq3k4=vtn=wbqtn=[0001]=
Δq˙1p˙1v˙1
=
21Ω(ωmtn−bg)Δq0v0R{Δq0⊗q0}⊤(amtn−ba)−g
=norm(Δq0+2ΔtΔq˙1)=
Δq˙2p˙2v˙2
=
21Ω(ωmtn−bg+2Δtα)Δq1v0+2Δtv˙1R{Δq1⊗q0}⊤(amtn−ba+2Δtj)−g
=norm(Δq0+2ΔtΔq˙2)=
Δq˙3p˙3v˙3
=
21Ω(ωmtn−bg+2Δtα)Δq2v0+2Δtv˙2R{Δq2⊗q0}⊤(amtn−ba+2Δtj)−g
=norm(Δq0+ΔtΔq˙3)=
Δq˙4p˙4v˙4
=
21Ω(ωmtn−bg+Δtα)Δq3v0+Δtv˙3R{Δq3⊗q0}⊤(amtn−ba+Δtj)−g
[ q t n + Δ t p t n + Δ t v t n + Δ t ] = [ norm ( Δ q 0 + Δ t 6 ( Δ q ˙ 1 + 2 Δ q ˙ 2 + 2 Δ q ˙ 3 + Δ q ˙ 4 ) ) ⊗ w b q t n p t n + Δ t 6 ( p ˙ 1 + 2 p ˙ 2 + 2 p ˙ 3 + p ˙ 4 ) v t n + Δ t 6 ( v ˙ 1 + 2 v ˙ 2 + 2 v ˙ 3 + v ˙ 4 ) ] \begin{bmatrix} \mathbf{q}_{{t_n} + \Delta t} \\ \mathbf{p}_{{t_n} + \Delta t} \\ \mathbf{v}_{{t_n} + \Delta t} \end{bmatrix} = \begin{bmatrix} \text{norm} \left( \Delta \mathbf{q}_0 + \frac{\Delta t}{6} \left( \dot{\Delta \mathbf{q}}_{1} + 2 \dot{\Delta \mathbf{q}}_{2} + 2 \dot{\Delta \mathbf{q}}_{3} + \dot{\Delta \mathbf{q}}_{4} \right) \right) \otimes {}^b_w \mathbf{q}_{{t_n}} \\ \mathbf{p}_{{t_n}} + \frac{\Delta t}{6} \left( \dot{\mathbf{p}}_{1} + 2 \dot{\mathbf{p}}_{2} + 2 \dot{\mathbf{p}}_{3} + \dot{\mathbf{p}}_{4} \right) \\ \mathbf{v}_{{t_n}} + \frac{\Delta t}{6} \left( \dot{\mathbf{v}}_{1} + 2 \dot{\mathbf{v}}_{2} + 2 \dot{\mathbf{v}}_{3} + \dot{\mathbf{v}}_{4} \right) \end{bmatrix} qtn+Δtptn+Δtvtn+Δt = norm(Δq0+6Δt(Δq˙1+2Δq˙2+2Δq˙3+Δq˙4))⊗wbqtnptn+6Δt(p˙1+2p˙2+2p˙3+p˙4)vtn+6Δt(v˙1+2v˙2+2v˙3+v˙4)