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

how to read a rosbag in python?

asked 2022-04-12 02:52:24 -0600

Question gravatar image

Hi,

So I want to read a rosbag with the help of a python script. The rosbag contains many topics but I am mainly interested in reading the "sensor_msgs/Pointcloud2" messages. I have found 2 libraries such as "rosbags" and "bagpy" but I am not sure which one is the best to use. Does anyone have some advice or experience with these two libraries?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-04-12 09:08:26 -0600

FurkanEdizkan gravatar image

Below code is from official wiki and clearly explains what needs to be done to get bag data with python. Hope it helps!

import rosbag
bag = rosbag.Bag('test.bag')
for topic, msg, t in bag.read_messages(topics=['chatter', 'numbers']):
    print(msg)
bag.close()
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-04-12 02:52:24 -0600

Seen: 2,911 times

Last updated: Apr 12 '22