nav_msgs/Odometry和geometry_msgs/Pose2D 类型比较与转化

nav_msgs/Odometry和geometry_msgs/Pose2D 类型比较与转化_第1张图片nav_msgs/Odometry和geometry_msgs/Pose2D 类型比较与转化_第2张图片nav_msgs/Odometry和geometry_msgs/Pose2D 类型比较与转化_第3张图片看到geometry_msgs/Pose2D的类型很简单,所以要把ICP发布的这个里程计信息转化成nav_msgs/Odometry

原代码:

    if (publish_pose_)
    {
      // unstamped Pose2D message
      geometry_msgs::Pose2D::Ptr pose_msg;
      pose_msg = boost::make_shared<geometry_msgs::Pose2D>();
      pose_msg->x = f2b_.getOrigin().getX();
      pose_msg->y = f2b_.getOrigin().getY();
      pose_msg->theta = tf::getYaw(f2b_.getRotation());
      pose_publisher_.publish(pose_msg);
    }

改后:

// An highlighted block
      if (publish_pose_)
      {
        // unstamped Pose2D message
        nav_msgs::Odometry::Ptr pose_msg;
        pose_msg = boost::make_shared<nav_msgs::Odometry>();
        pose_msg.header.stamp = ros::Time(time);
        pose_msg.header.frame_id = "world";
        pose_msg.child_frame_id = "base_link";
        pose_msg.pose.pose.position.x = f2b_.getOrigin().getX();
        pose_msg.pose.pose.position.y = f2b_.getOrigin().getY();
        pose_msg.pose.orientation.z = tf::getYaw(f2b_.getRotation());
        pose_msg.pose.covariance = {1, 0, 0, 0, 0, 0,  
                        0, 1, 0, 0, 0, 0,  
                        0, 0, 1, 0, 0, 0,  
                        0, 0, 0, 99999, 0, 0, 
                        0, 0, 0, 0, 99999, 0,  
                        0, 0, 0, 0, 0, 99999};  
        pose_publisher_.publish(pose_msg);
      }

看似没问题。但是编译后报错:
nav_msgs/Odometry和geometry_msgs/Pose2D 类型比较与转化_第4张图片
改一下:

// An highlighted block
if (publish_pose_)
      {
        // unstamped Pose2D message
        nav_msgs::Odometry pose_msg;
        //pose_msg = boost::make_shared();
        pose_msg.header.stamp = ros::Time(time);
        pose_msg.header.frame_id = "world";
        pose_msg.child_frame_id = "base_link";
        pose_msg.pose.pose.position.x = f2b_.getOrigin().getX();
        pose_msg.pose.pose.position.y = f2b_.getOrigin().getY();
        pose_msg.pose.pose.orientation.z = tf::getYaw(f2b_.getRotation());
        pose_msg.pose.covariance = {1, 0, 0, 0, 0, 0,  
                        0, 1, 0, 0, 0, 0,  
                        0, 0, 1, 0, 0, 0,  
                        0, 0, 0, 99999, 0, 0, 
                        0, 0, 0, 0, 99999, 0,  
                        0, 0, 0, 0, 0, 99999};  
        pose_publisher_.publish(pose_msg);
      }

现在不报错了。把话题名和类型改成/odom和nav_msgs::Odometry

你可能感兴趣的:(ROS)