ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

reading VelodyneScan from bagfile - offline

asked 2017-12-22 05:17:08 -0500

icywhite gravatar image

I am trying to read a bagfile containing multiple velodyne data. I want to do this preferably without rosbag play as sometimes from my prev experience due to computation issues it may skip reading a node and lose than info.

so now, I have a rosbag file, containing VelodyneScan msgs from a v64 topic I am using python2. from past few hours googling and figuring out on my own, i understand that it contains a main header and then subheader and data in perhaps uint32 format.

Lets say i read a message - msg for topic, msg, t in bag.read_messages()

msg.header is:
seq: 6309 stamp: secs: 1513822001 nsecs: 291831017 frame_id: velodyne

msg.packets is a list len = 579 type( msg.packets[0]) = < class 'tmpbWvooI._velodyne_msgs__VelodynePacket'>

Thus there are 579 such packets. One way i could read the data is to go through one by one and append a np.arr with the data i am reading. Even if i do that, how do i get X Y Z data from it? will it always be X1 Y1 Z1 X2 Y2 Z2 and so on? my first packet doesnt even have 3x numbers.. but that could be because it saved the remaining in following packets. But there should be a prebuild method to do this right?

How can I read the data from a VelodyneScan in python (using ros and cv2) WITHOUT using rosbag play to listen to a different node.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-12-22 10:54:08 -0500

Hi @icywhite!

I think that your question involves many steps. You will probably have to:

  1. Read the velodyne_msgs/VelodyneScan messages from a bag file
  2. Convert those velodyne_msgs/VelodyneScan messages to sensor_msgs/PointCloud2
  3. Read X, Y, Z values from PointCloud

You probably could extract X Y Z directly from the velodyne_msgs/VelodyneScan, but I'm not sure how to do that, then let's see by converting to PontoCloud2.

1. Reading a bag file

To read from a bag file we can follow that has the following example:

import rosbag
bag = rosbag.Bag('test.bag')
for topic, msg, t in bag.read_messages(topics=['chatter', 'numbers']):
    print msg

In the example above, the topics chatter and numbers are being read from the test.bag file.

2. Converting velodyne_msgs/VelodyneScan messages to sensor_msgs/PointCloud2

To convert Velodyne messages to PointCloud, you can take a look at the velodyne_pointcloud package.

Or if you want to convert manually by yourself, you can take a look on the function processScan that converts velodyne_msgs::VelodyneScan to PointCloud.

3. Read XYZ from PointCloud2

To read XYZ from PointClouds, you could use the example below that is shown in another question:

import sensor_msgs.point_cloud2
for point in sensor_msgs.point_cloud2.read_points(msg, skip_nans=True):
            pt_x = point[0]
            pt_y = point[1]
            pt_z = point[2]


edit flag offensive delete link more

Question Tools


Asked: 2017-12-22 05:17:08 -0500

Seen: 3,486 times

Last updated: Dec 22 '17