zoukankan      html  css  js  c++  java
  • ROS 可视化(一): 发布PointCloud2点云数据到Rviz

    1. 相关依赖
    package.xml 需要添加对 pcl_ros 包的依赖

    2. CMakeLists.txt

    find_package(PCL REQUIRED)
    include_directories(include${PCL_INCLUDE_DIRS})
    link_directories(${PCL_LIBRARY_DIRS})
    add_executable(pcl_create src/pcl_create.cpp)
    target_link_libraries(pcl_create ${catkin_LIBRARIES} ${PCL_LIBRARIES}) 
    

     2. 测试代码

    #include <ros/ros.h>
    #include <pcl/point_cloud.h>
    #include <pcl_conversions/pcl_conversions.h>
    #include <sensor_msgs/PointCloud2.h>
    
    main (int argc, char **argv)
    {
        ros::init (argc, argv, "pcl_create");
    
        ros::NodeHandle nh;
        ros::Publisher pcl_pub = nh.advertise<sensor_msgs::PointCloud2> ("pcl_output", 1);
        pcl::PointCloud<pcl::PointXYZ> cloud;
        sensor_msgs::PointCloud2 output;
    
        // Fill in the cloud data
        cloud.width  = 100;
        cloud.height = 1;
        cloud.points.resize(cloud.width * cloud.height);
    
        for (size_t i = 0; i < cloud.points.size (); ++i)
        {
            cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
            cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
            cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
        }
    
        //Convert the cloud to ROS message
        pcl::toROSMsg(cloud, output);
        output.header.frame_id = "odom";
    
        ros::Rate loop_rate(1);
        while (ros::ok())
        {
            pcl_pub.publish(output);
            ros::spinOnce();
            loop_rate.sleep();
        }
    
        return 0;
    }
    
  • 相关阅读:
    Sphinx Search 学习 (一)
    求两个字符串最长子串的LCS算法 C语言实现(简短的实现函数)
    DPDK17.02入门手册
    DPDK2.1开发者手册4-7
    DPDK2.1开发者手册3-4
    DPDK2.1开发者手册1-2
    DPDK2.1 linux上开发入门手册
    深度优先搜索-linux上浅显易懂的例子
    多线程的电影
    数据对齐与代码优化笔记
  • 原文地址:https://www.cnblogs.com/lvchaoshun/p/9961112.html
Copyright © 2011-2022 走看看