ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Hi @icywhite!
I think that your question involves many steps. You will probably have to:
velodyne_msgs/VelodyneScan
messages from a bag filevelodyne_msgs/VelodyneScan
messages to sensor_msgs/PointCloud2
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.
To read from a bag file we can follow http://wiki.ros.org/rosbag/Code%20API 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
bag.close()
In the example above, the topics chatter
and numbers
are being read from the test.bag
file.
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.
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]
Cheers.