0
votes

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

1
What do you want to do with the 2D data? Use it as-is for 2D purposes or for example combine multiple scans into a 3D scan?anderas
@anderas The latter, combine multiple scans into a 3D scanW01
Assuming that you are using a 2D scanner on a PTU (or a similar setup): Do you have the current orientation of the PTU at each scan?anderas
@anderas I have it mounted on top of a robot's head. I'm planning on changing pitch in small increments to change orientation. Since the laser scanner covers 270* degrees, I probably wont need to change yaw.W01

1 Answers

2
votes

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];
}