Ask Your Question
0

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

Comments

Take a look at this prior answer: https://answers.ros.org/question/2497...

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

Also please take a look at this package rosbag_direct_write

https://github.com/osrf/rosbag_direct...

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

And for Python take a look at bagpythere is a good article https://rahulbhadani.medium.com/readi...

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

1 Answer

Sort by ยป oldest newest most voted
1

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

Comments

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

2 followers

Stats

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

Seen: 86 times

Last updated: Dec 17 '21