zoukankan      html  css  js  c++  java
  • pcl点云与ros之间的数据类型转换

    一、基础数据类型

    pcl::PointCloud<pcl::PointXYZ> pcl的点云

    pcl::PCLPointCloud2 pcl的第二种点云

    sensor_msgs::PointCloud2 ROS中的点云

    sensor_msgs::PointCloud ROS中的点云

     二、转换函数

    1. sensor_msgs::PCLPointCloud2 <=> pcl::PCLPointCloud2

    void pcl_conversions::toPCL(const sensor_msgs::PointCloud2 &, pcl::PCLPointCloud2 &)

    void pcl_conversions::moveFromPCL(const pcl::PCLPointCloud2 &, const sensor_msgs::PointCloud2 &);

    2. pcl::PCLPointCloud2 <=> pcl::PointCloud<pcl::PointXYZ>

    void pcl::fromPCLPointCloud2(const pcl::PCLPointCloud2 &, pcl::PointCloud<pointT> &);

    void pcl::toPCLPointCloud2(const pcl::PointCloud<pointT> &, pcl::PCLPointCloud2 &);

    3. sensor_msgs::PCLPointCloud2 <=> pcl::PointCloud<pcl::PointXYZ>

    void pcl::fromROSMsg(const sensor_msgs::PointCloud2 &, pcl::PointCloud<T> &);

    void pcl::toROSMsg(const pcl::PointCloud<T> &, sensor_msgs::PointCloud2 &);

    4. sensor_msgs::PointCloud2 <=> sensor_msgs::PointCloud

    static bool sensor_msgs::convertPointCloudToPointCloud2(const sensor_msgs::PointCloud & input,sensor_msgs::PointCloud2 & output);

    static bool sensor_msgs::convertPointCloud2ToPointCloud(const sensor_msgs::PointCloud2 & input,sensor_msgs::PointCloud & output);

    三、实例

            pcl::PointCloud<PointT> mls_points;
            sensor_msgs::PointCloud2 cloud_final;
            pcl::toROSMsg(mls_points,cloud_final);
    
    
            std::vector<double> angles_after,ranges_after;
            // Iterate through pointcloud
            for (sensor_msgs::PointCloud2ConstIterator<float> iter_x(cloud_final, "x"),
              iter_y(cloud_final, "y"), iter_z(cloud_final, "z");
              iter_x != iter_x.end(); ++iter_x, ++iter_y, ++iter_z)
            {
    
              double range = hypot(*iter_x, *iter_y);
              double angle = atan2(*iter_y, *iter_x);
              angles_after.push_back(angle);
              ranges_after.push_back(range);
            }
            sensor_msgs::LaserScan msg;
            msg.header = scan_msg->header;
            msg.angle_min       = scan_msg->angle_min;
            msg.angle_max       = scan_msg->angle_max;
            msg.angle_increment = scan_msg->angle_increment;
            msg.time_increment  = scan_msg->time_increment; // 0.00002469;
            msg.range_min       = scan_msg->range_min;
            msg.range_max       = scan_msg->range_max;
            msg.ranges.resize(ranges.size());
            for(int i=0;i<msg.ranges.size();i++)
            {
                msg.ranges[i]=ranges[i];
            }





  • 相关阅读:
    MySQL Explain详解
    sql查询:存在A表而不在B表中的数据
    mybatis处理集合、数组参数使用in查询
    mysql日期范围查找(两个日期之间的记录)
    MYSQL查询数据表中某个字段包含某个数值
    springboot+jpa分页(Pageable+Page)
    MySQL单表能存储多少条数据?
    nosql几种热门数据库的优缺点及应用场景
    MySQL百万级数据分页查询及优化
    Redis cluster群集操作
  • 原文地址:https://www.cnblogs.com/zx-hit/p/13819612.html
Copyright © 2011-2022 走看看