Question

I've been researching for a while now on creating a point cloud from laser scans, but I'm running into a few issues:

First of all, PCL doesn't have io support for hokuyo lasers, so I'm planning on using the hokuyoaist library for that.

The main problem I have is how to convert from 2D laser data to a point cloud (pointcloud2) so I can work with the PCL library. I am aware of some packages in ROS that do this, but I really don't want to get near to ROS doing this.

Thanks in advance,

Marwan

Was it helpful?

Solution

You could use something like (untested, but should get you going):

#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <vector>

// Get Hokuyo data
int numberOfDataPoints = 0; // you need to fill this
std::vector<double> hokuyoDataX,hokuyoDataY;
for(int i=0;i<numberOfDataPoints;i++)
{
    hokuyoDataX.push_back(...); // you need to fill this for the x of point i
    hokuyoDataY.push_back(...); // you need to fill this for the y of point i
}

// Define new cloud object
pcl::PointCloud<pcl::PointXY>::Ptr cloud (new pcl::PointCloud<pcl::PointXY>);
cloud->is_dense = true; // no NaN and INF expected. 
cloud->width = hokuyoDataX.size();
cloud->height = 1;
cloud->points.resize(hokuyoDataX.size());
// Now fill the pointcloud
for(int i=0; i<hokuyoDataX.size(); i++)
{
    cloud->points[i].x = hokuyoDataX[i];
    cloud->points[i].y = hokuyoDataY[i];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top