相对参考系(Reference frame)由其处于另一参考系的坐标系(Coordinate)原点的位置(Position)和方向(Orientation)定义,并将该参考系称为父参考系(Parent frame)。
我们将所有参考系的父参考系称为全局参考系,全局参考系通常被认为是静态的,通常在SLAM中第一帧的会被默认为全局参考系。
我们将位置(Position)和方向(Orientation)合并定义为位姿(Pose)。
以下是对上述关系的数学符号定义约定:
在2D中,平移向量为 t = ( a , b ) \mathbf{t} =(a,b) t=(a,b),而旋转量 Φ \mathbf{\Phi} Φ定义为θ,
B = [ t θ ] ∈ R 3 B=\left[\begin{array}{l} \mathbf{t} \\ \theta \end{array}\right] \in \mathbb{R}^{3} B=[tθ]∈R3
在2D中,平移向量为 t = ( a , b , c ) \mathbf{t} =(a,b,c) t=(a,b,c),而旋转量 Φ \mathbf{\Phi} Φ则有许多种形式,例如欧拉角、四元数、旋转矩阵。为了表述的完整与方便这里统一采用四元数, q = [ q w , q x , q y , q z ] T \mathbf{q} =[qw, qx, qy, qz] ^{T} q=[qw,qx,qy,qz]T
B = [ t q ] ∈ R 7 , ∥ q ∥ = 1 B=\left[\begin{array}{l} \mathbf{t} \\ \mathbf{q} \end{array}\right] \in \mathbb{R}^{7}, \quad\|\mathbf{q}\|=1 B=[tq]∈R7,∥q∥=1
3Blue1Brown介绍四元数
一个刚体参照系中的点或向量是可以通过坐标变换运算在另一个坐标系中表达的。例如,在某个刚体B中相对与全局参考系为: B = ( t , Φ ) \mathit{B}=(\mathbf{t},\mathbf{\Phi}) B=(t,Φ),而其上的一个点或向量则表述为:
p = R { Φ } p B + t v = R { Φ } v B \begin{array}{l} \mathbf{p}=\mathbf{R}\{\boldsymbol{\Phi}\} \mathbf{p}_{B}+\mathbf{t} \\ \mathbf{v}=\mathbf{R}\{\boldsymbol{\Phi}\} \mathbf{v}_{B} \end{array} p=R{Φ}pB+tv=R{Φ}vB
反推关系为:
p B = R { Φ } ⊤ ( p − t ) p B = R { Φ } ⊤ p \begin{array}{l} \mathbf{p}_{B}=\mathbf{R}\{\boldsymbol{\Phi}\}^{\top}(\mathbf{p}-\mathbf{t}) \\ \mathbf{p}_{B}=\mathbf{R}\{\boldsymbol{\Phi}\}^{\top} \mathbf{p} \end{array} pB=R{Φ}⊤(p−t)pB=R{Φ}⊤p
注意点:这里, R { Φ } \mathbf{R}\left\{\mathbf{\Phi}\right\} R{Φ}是与方向 Φ \mathbf{\Phi} Φ有关的旋转矩阵。它的表达式取决于空间维度(2D或3D)表达方式。
在二维世界中, R { θ } \mathbf{R}\left\{θ\right\} R{θ}是与旋转角θ相关的旋转矩阵:
R { θ } = [ cos θ − sin θ sin θ cos θ ] \mathbf{R}\{\theta\}=\left[\begin{array}{cc} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{array}\right] R{θ}=[cosθsinθ−sinθcosθ]
在三维世界中, R { q } \mathbf{R}\left\{q\right\} R{q}是与四元数q相关的旋转矩阵:
R { q } = [ q w 2 + q x 2 − q y 2 − q z 2 2 ( q x q y − q w q z ) 2 ( q x q z + q w q y ) 2 ( q x q y + q w q z ) q w 2 − q x 2 + q y 2 − q z 2 2 ( q y q z − q w q x ) 2 ( q x q z − q w q y ) 2 ( q y q z + q w q x ) q w 2 − q x 2 − q y 2 + q z 2 ] \mathbf{R}\{\mathbf{q}\}=\left[\begin{array}{ccc} q_{w}^{2}+q_{x}^{2}-q_{y}^{2}-q_{z}^{2} & 2\left(q_{x} q_{y}-q_{w} q_{z}\right) & 2\left(q_{x} q_{z}+q_{w} q_{y}\right) \\ 2\left(q_{x} q_{y}+q_{w} q_{z}\right) & q_{w}^{2}-q_{x}^{2}+q_{y}^{2}-q_{z}^{2} & 2\left(q_{y} q_{z}-q_{w} q_{x}\right) \\ 2\left(q_{x} q_{z}-q_{w} q_{y}\right) & 2\left(q_{y} q_{z}+q_{w} q_{x}\right) & q_{w}^{2}-q_{x}^{2}-q_{y}^{2}+q_{z}^{2} \end{array}\right] R{q}=⎣⎡qw2+qx2−qy2−qz22(qxqy+qwqz)2(qxqz−qwqy)2(qxqy−qwqz)qw2−qx2+qy2−qz22(qyqz+qwqx)2(qxqz+qwqy)2(qyqz−qwqx)qw2−qx2−qy2+qz2⎦⎤
首先我们假设一个移动机器人的相对参考系为R,并安装了一个相机,其相对坐标系为S,相机相对于移动机器人的相对参考系为: S R S_{\mathit{R} } SR。
类似于向量的相加,我们定义 ⊕ \oplus ⊕为参考系相加。例如,我们将R和 S R S_{\mathit{R} } SR相加得到S:
而将 ⊖ \ominus ⊖定义为参考系相减。例如,我们将S和R相减得到 S R S_{\mathit{R} } SR:
其中S、R和 S R S_{\mathit{R} } SR已知:
则根据以上的公式,在已知其中两个的情况下可以推导出另一个。
S = [ t S θ S ] = [ t R + R { θ R } t R S θ R + θ R S ] S R = [ t R S θ R S ] = [ R { θ R } ⊤ ( t S − t R ) θ S − θ R ] \begin{aligned} S &=\left[\begin{array}{l} \mathbf{t}_{S} \\ \theta_{S} \end{array}\right]=\left[\begin{array}{c} \mathbf{t}_{R}+\mathbf{R}\left\{\theta_{R}\right\} \mathbf{t}_{R S} \\ \theta_{R}+\theta_{R S} \end{array}\right] \\ S_{R} &=\left[\begin{array}{l} \mathbf{t}_{R S} \\ \theta_{R S} \end{array}\right]=\left[\begin{array}{c} \mathbf{R}\left\{\theta_{R}\right\}^{\top}\left(\mathbf{t}_{S}-\mathbf{t}_{R}\right) \\ \theta_{S}-\theta_{R} \end{array}\right] \end{aligned} SSR=[tSθS]=[tR+R{θR}tRSθR+θRS]=[tRSθRS]=[R{θR}⊤(tS−tR)θS−θR]
注意点:S是相对全局参考系,因此 t R S \mathbf{t} _{RS} tRS(S相对R的位置)需要先乘以 R { θ R } \mathbf{R}\left\{θ_{R}\right\} R{θR}转换到全局参考系。这里请参照上图仔细想,谁相对于谁旋转!!!
S = [ t S q S ] = [ t R + R { q R } t R S q R ⊗ q R S ] S R = [ t R S q R S ] = [ R { q R } ⊤ ( t S − t R ) q R ∗ q S ] \begin{aligned} S &=\left[\begin{array}{c} \mathbf{t}_{S} \\ \mathbf{q}_{S} \end{array}\right]=\left[\begin{array}{c} \mathbf{t}_{R}+\mathbf{R}\left\{\mathbf{q}_{R}\right\} \mathbf{t}_{R S} \\ \mathbf{q}_{R} \otimes \mathbf{q}_{R S} \end{array}\right] \\ S_{R} &=\left[\begin{array}{c} \mathbf{t}_{R S} \\ \mathbf{q}_{R S} \end{array}\right]=\left[\begin{array}{r} \mathbf{R}\left\{\mathbf{q}_{R}\right\}^{\top}\left(\mathbf{t}_{S}-\mathbf{t}_{R}\right) \\ \mathbf{q}_{R}^{*} \mathbf{q}_{S} \end{array}\right] \end{aligned} SSR=[tSqS]=[tR+R{qR}tRSqR⊗qRS]=[tRSqRS]=[R{qR}⊤(tS−tR)qR∗qS]