激光雷达标定(坐标系转换)

1. 旋转矩阵

  • 由于激光雷达获取的点云数据的坐标是相对于激光雷达坐标系的,为了使车最终得到的点云数据坐标是在车坐标系下的,我们需要对点云中每一个点的坐标进行坐标转换。
  • 首先是需要对坐标系进行旋转变换,先以二维平面的单位向量坐标转换为例,假设两坐标系中的旋转矩阵为R,旋转角度为 θ \theta θ,点P在 x 1 o y 1 x_1oy_1 x1oy1坐标(车坐标系)下的坐标为 ( x 1 , y 1 ) (x_1,y_1) (x1,y1);点P在 x 2 o y 2 x_2oy_2 x2oy2坐标(激光雷达坐标系)下的坐标为 ( x 2 , y 2 ) (x_2,y_2) (x2,y2),已知点在激光雷达坐标系下的坐标 ( x 2 , y 2 ) (x_2,y_2) (x2,y2),可以由以下的坐标系的转换关系得到 ( x 1 , y 1 ) (x_1,y_1) (x1,y1)

旋转矩阵R:将点P在旋转后的坐标系下的坐标转换为旋转前的坐标系下的坐标

[ x 1 y 1 ] = R [ x 2 y 2 ] (1) \begin{bmatrix} x_1\\y_1 \end{bmatrix} =R\begin{bmatrix} x_2\\y_2 \end{bmatrix} \tag{1} [x1y1]=R[x2y2](1)
在这里插入图片描述

图1 二维坐标系转换
  • 根据旋转角度 θ \theta θ,由上图1可得 x 1 x_1 x1 y 1 y_1 y1为:
    x 1 = x 2 c o s θ − y 2 s i n θ y 1 = x 2 s i n θ + y 2 c o s θ (2) x_1=x_2cos\theta-y_2sin\theta\\ y_1=x_2sin\theta+y_2cos\theta \tag{2} x1=x2cosθy2sinθy1=x2sinθ+y2cosθ(2)
  • 由此可以得出以下的坐标转换矩阵等式:
    [ x 1 y 1 ] = [ c o s θ , − s i n θ s i n θ , c o s θ ] [ x 2 y 2 ] (3) \begin{bmatrix} x_1\\y_1 \end{bmatrix} =\begin{bmatrix} cos\theta,-sin\theta\\ sin\theta,cos\theta\\ \end{bmatrix} \begin{bmatrix} x_2\\y_2 \end{bmatrix} \tag{3} [x1y1]=[cosθ,sinθsinθ,cosθ][x2y2](3)
  • 旋转矩阵R即为:
    R = [ c o s θ , − s i n θ s i n θ , c o s θ ] (4) R =\begin{bmatrix} cos\theta,-sin\theta\\ sin\theta,cos\theta\\ \end{bmatrix} \tag{4} R=[cosθ,sinθsinθ,cosθ](4)
  • 由二维推广至三维,由右手定则可以想象在上图1中的O点处有一条垂直于XOY平面指向屏幕的的Z轴:
    在这里插入图片描述
图2 航向角转换
  • 那么上述的二维空间内的坐标旋转便可推广至三维空间中绕z轴的旋转,旋转角度 θ \theta θ便是欧拉角中的航向角(也称偏航角yaw),由于旋转前后z轴没有发生变换,上述公式(3)可以写为以下形式:
    [ x 1 y 1 z 1 ] = [ c o s θ − s i n θ 0 s i n θ c o s θ 0 0 0 1 ] [ x 2 y 2 z 2 ] (5) \begin{bmatrix} x_1\\y_1\\z_1 \end{bmatrix} =\begin{bmatrix} cos\theta&-sin\theta&0\\ sin\theta&cos\theta&0\\ 0&0&1\\ \end{bmatrix} \begin{bmatrix} x_2\\y_2\\z_2 \end{bmatrix} \tag{5} x1y1z1 = cosθsinθ0sinθcosθ0001 x2y2z2 (5)
  • 由此可得航向角(也称偏航角yaw)旋转矩阵 R y a w R_{yaw} Ryaw为:
    R y a w = [ c o s θ − s i n θ 0 s i n θ c o s θ 0 0 0 1 ] (6) R_{yaw}=\begin{bmatrix} cos\theta&-sin\theta&0\\ sin\theta&cos\theta&0\\ 0&0&1\\ \end{bmatrix} \tag{6} Ryaw= cosθsinθ0sinθcosθ0001 (6)
    在这里插入图片描述
图3 俯仰角转换
  • 由上述公式(6)同理可以推导出绕坐标轴y轴旋转 β \beta β(俯仰角pictch)的公式如下:
    [ x 1 y 1 z 1 ] = [ c o s β 0 s i n β 0 1 0 − s i n β 0 c o s β ] [ x 2 y 2 z 2 ] (7) \begin{bmatrix} x_1\\y_1\\z_1 \end{bmatrix} =\begin{bmatrix} cos\beta&0&sin\beta\\ 0&1&0\\ -sin\beta&0&cos\beta\\ \end{bmatrix} \begin{bmatrix} x_2\\y_2\\z_2 \end{bmatrix} \tag{7} x1y1z1 = cosβ0sinβ010sinβ0cosβ x2y2z2 (7)
  • 由此可得俯仰角pictch旋转矩阵 R p i c t c h R_{pictch} Rpictch为:
    R p i t c h = [ c o s β 0 s i n β 0 1 0 − s i n β 0 c o s β ] (8) R_{pitch}=\begin{bmatrix} cos\beta&0&sin\beta\\ 0&1&0\\ -sin\beta&0&cos\beta\\ \end{bmatrix} \tag{8} Rpitch= cosβ0sinβ010sinβ0cosβ (8)
    在这里插入图片描述
图4 横滚角转换
  • 也可以推导出绕坐标轴x轴旋转 γ \gamma γ(横滚角roll)的公式如下:
    [ x 1 y 1 z 1 ] = [ 1 0 0 0 c o s γ − s i n γ 0 s i n γ c o s γ ] [ x 2 y 2 z 2 ] (9) \begin{bmatrix} x_1\\y_1\\z_1 \end{bmatrix} =\begin{bmatrix} 1&0&0\\ 0&cos\gamma&-sin\gamma\\ 0&sin\gamma&cos\gamma\\ \end{bmatrix} \begin{bmatrix} x_2\\y_2\\z_2 \end{bmatrix} \tag{9} x1y1z1 = 1000cosγsinγ0sinγcosγ x2y2z2 (9)
  • 由此可得横滚角roll旋转矩阵 R r o l l R_{roll} Rroll为:
    R r o l l = [ 1 0 0 0 c o s γ − s i n γ 0 s i n γ c o s γ ] (10) R_{roll}=\begin{bmatrix} 1&0&0\\ 0&cos\gamma&-sin\gamma\\ 0&sin\gamma&cos\gamma\\ \end{bmatrix} \tag{10} Rroll= 1000cosγsinγ0sinγcosγ (10)
  • 按照不同的顺序对坐标轴进行旋转可以得到不同的旋转矩阵R,R共有六种形式,分别为
    R = R y a w R p i t c h R r o l l   R = R y a w R r o l l R p i t c h R = R p i t c h R y a w R r o l l   R = R p i t c h R y a w R r o l l R = R r o l l R p i t c h R y a w   R = R r o l l R y a w R p i t c h (11) R=R_{yaw}R_{pitch}R_{roll} \ R=R_{yaw}R_{roll}R_{pitch}\\ R=R_{pitch}R_{yaw}R_{roll} \ R=R_{pitch}R_{yaw}R_{roll}\\ R=R_{roll}R_{pitch}R_{yaw} \ R=R_{roll}R_{yaw}R_{pitch} \tag{11} R=RyawRpitchRroll R=RyawRrollRpitchR=RpitchRyawRroll R=RpitchRyawRrollR=RrollRpitchRyaw R=RrollRyawRpitch(11)
  • 按照欧拉角的测量方式,每次旋转按照车底盘坐标系的坐标轴进行旋转(即外旋),外旋旋转矩阵是左乘矩阵,即按照X-Y-Z的顺序进行旋转的话,得到的旋转矩阵是 R = R Z R Y R X R=R_ZR_YR_X R=RZRYRX,通过测量的得到的欧拉角的角度值就可以计算出对应的旋转矩阵。

外旋(左乘):每次旋转绕固定轴旋转
内旋(右乘):每次旋转绕自身旋转后的轴旋转


2. 平移矩阵

已知激光雷达相对于车坐标原点的三维坐标x,y,z,可以得到激光雷达与车坐标系的平移矩阵为:
T = [ x y z ] (12) T=\begin{bmatrix} x\\y\\z \end{bmatrix} \tag{12} T= xyz (12)
在这里插入图片描述

图5 三维坐标系转换

3. 坐标系的转换

根据上述计算得到的旋转矩阵R和平移矩阵T。设车坐标下点的坐标为 ( x c , y c , z c ) (x_c,y_c,z_c) (xc,yc,zc)激光雷达下点的坐标为 ( x l , y l , z l ) (x_l,y_l,z_l) (xl,yl,zl)即最终的变换形式为:
[ x c y c z c ] = R [ x l y l z l ] + T (13) \begin{bmatrix} x_c \\ y_c\\ z_c \end{bmatrix} =R\begin{bmatrix} x_l \\ y_l\\ z_l \end{bmatrix} +T \tag{13} xcyczc =R xlylzl +T(13)


4. 坐标转换代码

  • 构造旋转平移矩阵对点云中的点进行转换
//坐标变换将激光雷达坐标系下的点转换到小车坐标系下
void MainWindow::changePoint(pcl::PointCloud<pcl::PointXYZ>::Ptr lidarCloud,
                 pcl::PointCloud<pcl::PointXYZ>::Ptr carCloud,
                 double yaw,double pitch,double roll,double x,double y,double z)
{
    Eigen::Matrix4f transform=Eigen::Matrix4f::Identity();
    Eigen::Matrix4f transformYaw;
    Eigen::Matrix4f transformPitch;
    Eigen::Matrix4f transformRoll;
    
    //航向角
    transformYaw<<cos(yaw),-sin(yaw),0,0,\
            sin(yaw),cos(yaw),0,0,\
            0,0,1,0,\
            0,0,0,1;
    //俯仰角
    transformPitch<<cos(pitch),0,sin(pitch),0,\
            0,1,0,0,\
            -sin(pitch),0,cos(pitch),0,\
            0,0,0,1;
    //横滚角
    transformRoll<<1,0,0,0,\
            0,cos(roll),-sin(roll),0,\
            0,sin(roll),cos(roll),0,\
            0,0,0,1;
            
    //旋转矩阵
    transform=transformRoll*transformPitch*transformYaw;
    
    //平移矩阵
    transform(0,3)=x;
    transform(1,3)=y;
    transform(2,3)=z;
    
    //坐标转换
    pcl::transformPointCloud(*lidarCloud,*carCloud,transform);
}
  • 6
    点赞
  • 61
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值