ROS订阅topic生成点云包转换为pcd文件在rviz中显示

 1、将 topic 发布的的信息打包,保存位置为当前目录的 out.bag

rosbag record -O out /kinect2/qhd/points

2、创建文件夹,将文件保存在文件夹内,将 .bag 数据转换为 .pcd

rosrun pcl_ros bag_to_pcd   
rosrun pcl_ros bag_to_pcd out.bag /kinect2/qhd/points ./pcd

3、创建 cpp 文件

include
#include
#include
#include
#include //which contains the required definitions to load and store point clouds to PCD and other file formats.
 
main (int argc, char **argv)
{
  ros::init (argc, argv, "UandBdetect");
  ros::NodeHandle nh;
  ros::Publisher pcl_pub = nh.advertise ("pcl_output1", 1);
  pcl::PointCloud cloud;
  sensor_msgs::PointCloud2 output;
  pcl::io::loadPCDFile ("/home/lucifr/code/voxel_grid/table_scene_lms400.pcd", cloud);
  //Convert the cloud to ROS message
  pcl::toROSMsg(cloud, output);
  output.header.frame_id = "odom1";//this has been done in order to be able to visualize our PointCloud2 message on the RViz visualizer
  ros::Rate loop_rate(1);
  while (ros::ok())
  {
    pcl_pub.publish(output);
    ros::spinOnce();
    loop_rate.sleep();
  }
  return 0;
}

4、修改CMakeList.txt 和 package.xml文件

  catkin
  roscpp
  rospy
  std_msgs
  pcl_ros
  sensor_msgs

  roscpp
  rospy
  std_msgs
  pcl_ros
  sensor_msgs

  roscpp
  rospy
  std_msgs
  pcl_ros
  sensor_msgs
find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  pcl_ros
  sensor_msgs
)

add_executable(${PROJECT_NAME}_node src/pcd2rviz1.cpp)

target_link_libraries(${PROJECT_NAME}_node
  ${catkin_LIBRARIES}
)

5、编译

6、运行节点

rosrun collisiondetection collisiondetection_node

ROS订阅topic生成点云包转换为pcd文件在rviz中显示_第1张图片

 

你可能感兴趣的:(ROS订阅topic生成点云包转换为pcd文件在rviz中显示)