ROS中通过欧拉角进行坐标变换

   //先计算车辆在大地坐标下的初始时刻的roll,pitch,yaw(车辆到大地)
   if(count==0){
        tf::Quaternion orientation;
        tf::quaternionMsgToTF(GnssInitMsg->pose.orientation, orientation);
        tf::Matrix3x3(orientation).getRPY(first_roll, first_pitch, first_yaw);

        first_x = GnssInitMsg->pose.position.x;
        first_y = GnssInitMsg->pose.position.y;
        first_z = GnssInitMsg->pose.position.z;

        count=1;
        ROS_INFO_STREAM_ONCE("get first r , p ,y !!");
    }
    //将车辆在大地坐标系的位置转化到车辆初始时刻的坐标系下
    double roll, pitch, yaw;
    tf::Quaternion orientation;
    tf::quaternionMsgToTF(GlobalVehicleMsg->pose.pose.orientation, orientation);
    tf::Matrix3x3(orientation).getRPY(roll, pitch, yaw);
    
    double x0=GlobalVehicleMsg->pose.pose.position.x - first_x;
    double y0=GlobalVehicleMsg->pose.pose.position.y - first_y;
    double z0=GlobalVehicleMsg->pose.pose.position.z - first_z;

    double xl1 = x0;
    double yl1 = y0 * cos(-first_roll) - z0 * sin(-first_roll);
    double zl1 = y0 * sin(-first_roll) + z0 * cos(-first_roll);

    double xl2 = zl1 * sin(-first_pitch) + xl1 * cos(-first_pitch);
    double yl2 = yl1;
    double zl2 = zl1 * cos(-first_pitch) - xl1 * sin(-first_pitch);

    double xl3 = xl2 * cos(-first_yaw) - yl2 * sin(-first_yaw);
    double yl3 = xl2 * sin(-first_yaw) + yl2 * cos(-first_yaw);
    double zl3 = zl2;
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值