Conversation
| if (std::filesystem::path(bag_filename).extension() == ".mcap") { | ||
| bag_reader_->open(rosbag2_storage::StorageOptions{bag_filename,"mcap"}, | ||
| rosbag2_cpp::ConverterOptions{"cdr", "cdr"}); | ||
| } else { | ||
| bag_reader_->open(bag_filename); | ||
| } |
There was a problem hiding this comment.
Hm, shouldn't the rosbag2 API be figuring this out for us? If we have to do this, I consider it a problem with that API and we should fix it there.
There was a problem hiding this comment.
I simply followed the rosbag2_cpp open function documentation which explicitly states that it assumes sqlite3 storage backend when using the path only overload:
https://github.com/ros2/rosbag2/blob/0c7c352222a08470211232453dab9749ab405201/rosbag2_cpp/include/rosbag2_cpp/reader.hpp#L64-L78
/**
- Opens an existing bagfile and prepare it for reading messages.
- The bagfile must exist.
- This must be called before any other function is used.
- \note This will open URI with the default storage options
- using sqlite3 storage backend
- using no converter options, storing messages with the incoming serialization format
- \sa rmw_get_serialization_format.
- For specifications, please see \sa open, which let's you specify
- more storage and converter options.
- \param storage_uri URI of the storage to open.
**/
void open(const std::string & uri);
And the Foxglove documentation which says to specify the StorageOptions and ConverterOptions (for python):
Reading from MCAP
The rosbag2_storage_mcap plugin works seamlessly with the existing rosbag2_py API for reading messages out of bags, so your rosbag2 scripts will continue to work with minimal changes. Just specify “mcap” as your storage ID when opening a bag file:
reader.open(
rosbag2_py.StorageOptions(uri=input_bag, storage_id="mcap"),
rosbag2_py.ConverterOptions(
input_serialization_format="cdr", output_serialization_format="cdr"
),
)
Without thinking much.
But if you think we can add automatic detection of the mcap storage_id based of the file extension directly in the rosbag2 API, I will happily do a PR (for the cpp part)
There was a problem hiding this comment.
Note that a manual flag has to be used for ros2 bag play usage with MCAP too:
$ ros2 bag play -s mcap path/to/your_recording.mcap
The MCAP format for bags is gaining popularity, see: https://foxglove.dev/blog/announcing-the-mcap-storage-plugin-for-ros2
This simplistic PR adds the possibility of using a MCAP format bag to the offline node.
You will have to install the MCAP rosbag pluggin for it to work though:
$ sudo apt install ros-$ROS_DISTRO-rosbag2-storage-mcap