Ask Your Question

Rosbag + python: reading single message

asked 2021-11-05 11:18:41 -0500

camilo.chiang gravatar image

updated 2021-11-05 11:19:41 -0500

Good day. Is there any way to read a single message from a rosbag without iterating as is today possible with a txt file (in ROS1, no ROS2)? The point is to "remember" what in the rosbag file was already read it so is : 1. Easier to multiprocess 2. avoid loops and faster

Thanks in advance! (Using python3 + rosbag)

edit retag flag offensive close merge delete


Take a look at this prior answer:

osilva gravatar image osilva  ( 2021-11-05 19:23:33 -0500 )edit

Also please take a look at this package rosbag_direct_write

osilva gravatar image osilva  ( 2021-11-05 19:34:21 -0500 )edit

And for Python take a look at bagpythere is a good article

osilva gravatar image osilva  ( 2021-11-05 19:42:35 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2021-12-17 09:24:36 -0500

camilo.chiang gravatar image

updated 2021-12-17 09:25:23 -0500

as @osilva mention bagpy is the best way to do it out of the box, but is extremely inefficient as basically bagpy will create files for each of your messsages (image if you are working with LiDAR data...)

  • The more efficient alternative is to create a thread that read the bag and your main thread just take the messages from the queue when they are necessary.
edit flag offensive delete link more


Glad you found an answer. It would be great if you share a snippet of the code for others to benefit in the future. Thank you

osilva gravatar image osilva  ( 2021-12-17 12:34:02 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2021-11-05 11:18:41 -0500

Seen: 86 times

Last updated: Dec 17 '21