rosbag2 icon indicating copy to clipboard operation
rosbag2 copied to clipboard

Add additional examples for reading ROSBag data and serialized messages

Open MaxFleur opened this issue 1 year ago • 5 comments

Description

Currently, the ROSBag2 examples contain three different examples for writing data to a ROSBag via C++ or Python. However, there are no specific examples of reading data from ROSBags (neither for the standard reader or the sequential reader). In addition, the writing examples do not show how to serialize various messages before writing them to a bag file. Inside the file under rosbag2_tests/test/rosbag2_tests/test_rosbag2_cpp_api.cpp, there are test cases for reading data and also for the message serialization. These helped me when using the ROSBag2 API, but in my opinion, a better idea is to create dedicated examples, because the unit tests should be meant solely for testing.

Completion Criteria

  • Example for reading ROSBag data using a simple reader (rosbag2_cpp::Reader)
  • Example for reading ROSBag data using a sequential reader (rosbag2_cpp::SequentialReader)
  • Example for writing ROSBag data using serialized messages (rclcpp::SerializedMessage and rclcpp::Serialization<>)

MaxFleur avatar Aug 22 '23 12:08 MaxFleur

This one covers reading: https://docs.ros.org/en/rolling/Tutorials/Advanced/Reading-From-A-Bag-File-CPP.html

Unfortunately, if the topic name is the wrong topic type than what is attempted to deserialize to, then there is a crash.

Ryanf55 avatar Feb 16 '24 18:02 Ryanf55

IMO we could have rosbag2_examples_<lang>::SimpleBagPlayer and https://docs.ros.org/en/rolling/Tutorials/Advanced/Reading-From-A-Bag-File-CPP.html link it as an example.

This seems good-first-issue, probably we can tag this issue with help-wanted? 😄

fujitatomoya avatar Feb 16 '24 19:02 fujitatomoya

Yea.

The existing tutorial can be improved to make sure the new code prevents exceptions thrown in RMW by trying to deserialize the wrong message type and making assumptions about what's in the bag.

https://github.com/ANYbotics/grid_map/issues/401 ^ See here for info and the associated PR for the fix.

Ryanf55 avatar Feb 16 '24 19:02 Ryanf55

I want to take a look at this. @MichaelOrlov Do you mind assigning this to me ?

sangteak601 avatar Feb 28 '24 18:02 sangteak601

@sangteak601 Thank you for being willing to help with this. You have got it :wink:

MichaelOrlov avatar Feb 28 '24 23:02 MichaelOrlov