Skip to content

Instantly share code, notes, and snippets.

@prerakmody
Last active February 28, 2018 15:11
Show Gist options
  • Save prerakmody/92008ee0a8358af0337f8bb72da72f2e to your computer and use it in GitHub Desktop.
Save prerakmody/92008ee0a8358af0337f8bb72da72f2e to your computer and use it in GitHub Desktop.
Reading a ROS (Robot Operating System) datadump (.rosbag) for Velodyne LIDAR pakets
"""
Installing Rosbag
- http://wiki.ros.org/lunar/Installation
RosBag Python API
- http://wiki.ros.org/rosbag/Cookbook
- http://wiki.ros.org/rosbag/Code%20API
ROS : Velodyne PointCloud
- to convert velodyne_msgs/VelodyneScan messages to sensor_msgs/PointCloud2
- https://answers.ros.org/question/278052/reading-velodynescan-from-bagfile-offline/
Useful commands
- rosbag info --yaml <bagname>.bag
Data
- https://github.com/udacity/self-driving-car/tree/master/datasets/CHX
"""
import rosbag
"""
bag = rosbag.Bag('data_original.bag')
for (topic, msg, t) in bag.read_messages(topics=['/velodyne_packets']):
print (topic, msg, t)
break
"""
"""
with rosbag.Bag('data__velodyne_packets.bag', 'w') as outbag:
for i, (topic, msg, t) in enumerate(bag.read_messages(topics=['/velodyne_packets'])):
outbag.write(topic, msg, t)
"""
bag = rosbag.Bag('data__velodyne_packets.bag')
for i, (topic, msg, t) in enumerate(bag.read_messages()):
# print (topic, msg, t)
print ('Topic : ', topic, ' || Time : ',t, ' || msg.header.seq : ',msg.header.seq, ' || msg.header.frame_id : ', msg.header.frame_id)
print ('Packet Count : ', len(msg.packets))
print ('======')
for j, packet in enumerate(msg.packets):
print ('Ts : ', packet.stamp, ' || Len : ', len(packet.data))
break
break
bag.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment