Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The actual measurement of a laser scanner is the distance. So ideally you should be able to go through the code of the driver and publish that data into a custom message. Performance wise, that is the best option.

However, let me give you a simpler solution.

For your reference, this is the PointCloud2 message definition. Essentially, the large array data contains x,y,z location of the points in the point cloud. All you need to do is to parse the data array, obtain x,y,z for each point and then calculate the euclidean distance where (0,0,0) is the location of the sensor / frame.

The parsing logic is simple. Your message has height 1, width 811 and point_step 16. You can verify the numbers by checking

width*point_step == row_step*height

The fields give you information about parsing the data. Each group of 16 numbers in the array data gives you x,y,z and intensity for a single point in the point cloud. First 1-4 numbers represent x as a 32 bit float, 5-8 represents y, 9-12 represents z, 13-16 represents the intensity. All you then need to do is convert the data to 32 bit float in little endian.

Libraries should exist where all this is done. However, if you are into reinventing the wheel or couldn't find one, this will get you home.