Search code examples
c++rospoint-cloudslidar

Add distance field : [x,y,z,distance] from VLP-16 using ROS or velodyne driver


Velodyne lidars publish PointCloud2 messages with the fields containing :

  • x, type : float32
  • y, type : float32
  • z, type : float32
  • intensity, type : float32
  • ring, type : uint16
  • time, type : float32

However, I need to add distance field(output points with distance) because I needed this field as a research purpose.

Is it possible to write a node or adapt the velodyne driver to output points with that field? If so, could you possibly tell me how to achieve that?

Any help is much appreciated. Thanks:)


Solution

  • The best solution is not to change the velodyne driver, but since you're using ros, to leverage all the ecosystem tools built in. For example, the velodyne publishes a sensor_msgs/PointCloud2 topic. Then internally, using C++, ROS treats any PointCloud2 msg into any PCL pointcloud type. If you're doing serious processing of pointclouds, don't re-invent the wheel (but worse), try solving the problem with tools from PCL. Use it's pre-built filters (ex ground plane filter) and prebuilt segmentation tools (ex could Euclidean Cluster Extraction solve your problem?). Additionally, some of these PCL tools are pre-wrapped in ros, to use from the launch file if you want!

    Otherwise you could use PCL to add a distance parameter, by choosing the pointcloud type in ros as of type pcl::PointWithRange or pcl::PointWithViewpoint. I don't think it'll autocompute that variable, but you can iterate through the points and compute it yourself, and the memory for it will already be allocated and localized.