0
$\begingroup$

Rosanswers logo

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)


Originally posted by camilo.chiang on ROS Answers with karma: 46 on 2021-11-05

Post score: 0


Original comments

Comment by osilva on 2021-11-05:
Take a look at this prior answer: https://answers.ros.org/question/249757/reading-large-rosbag/

Comment by osilva on 2021-11-05:
Also please take a look at this package rosbag_direct_write

https://github.com/osrf/rosbag_direct_write/blob/master/README.md

Comment by osilva on 2021-11-05:
And for Python take a look at bagpy there is a good article https://rahulbhadani.medium.com/reading-ros-messages-from-a-bagfile-in-python-b006538bb520

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.

Originally posted by camilo.chiang with karma: 46 on 2021-12-17

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by osilva on 2021-12-17:
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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.