Converting raw HDL-32e packets to Pointclouds in Rospy

asked 2017-07-19 15:48:16 -0500

abrooks9944 gravatar image

I am attempting to convert raw velodyne (inside of a rosbag) data to a point cloud. I'd like to do this directly in Python, because there is a lot of pre/post processing done on other pieces of the data (e.g. I'm working with other things in addition to the lidar) and it would make my code much more seamless.

All of my data is prepackaged so that when I read it from the bag, I get a series of scans; each scan holds a full rotation of data from the velodyne (e.g. if the Velodyne takes X scans in the time of one rotation, that data will be X by 1206).

Does anyone know of any ways to convert raw velodyne data into a PointCloud structure that I can retrieve X/Y/Z coordinates from? I was thinking something along the lines of the following.

def raw_to_pointcloud(velodyne_raw):
    <SOME CONVERSION HERE TO TAKE RAW DATA TO sensor_msgs.point_cloud2>
    for point in pc2.read_points(velodyne_raw, field_names = ('x', 'y', 'z')):
         print(point[0], point[1], point[2]) #just to check if things actually worked

for topic, message, timestamp in bag.read_messages(topics = ['velodyne_packets']):
    pointCloud = raw_to_pointcloud(message.packets)

I am very new to ros, but I haven't seen much support for this specific conversion. Any advice would be appreciated.

edit retag flag offensive close merge delete


Are you aware of the Velodyne drivers for the HDL-32? They take the raw packets and output data in the PointCloud2 format, which may save you some time and effort.

M@t gravatar image M@t  ( 2017-07-19 18:26:48 -0500 )edit

Thanks for the response! I am aware of the Velodyne drivers, but wasn't sure how useful they would be because my data is already recorded in a rosbag, I don't have access to rviz since I am working on this project remotely, and my project is entirely Python.

abrooks9944 gravatar image abrooks9944  ( 2017-07-19 20:19:25 -0500 )edit

The drivers will convert the data to the PointCloud2 format, which you may find useful if you haven't got something to do that for you yet. As for extracting XYZ information, take at this question

M@t gravatar image M@t  ( 2017-07-20 21:10:49 -0500 )edit

... and this one. Hopefully one of these will help you out, or at least point you in the right direction.

M@t gravatar image M@t  ( 2017-07-20 21:11:58 -0500 )edit