Open lucasw opened 8 months ago
The python example may be a better guide to what to do in C++ than the C++ examples:
https://github.com/foxglove/mcap/blob/main/python/mcap-ros1-support/mcap_ros1/writer.py#L64-L69
then find in the C++ the equivalent of message.__class__._full_text.encode()
Or the mcap convert written in go is a good place to look for how it handles ros1 messages.
Replace this Bag
with mcap::McapWriter
https://github.com/lucasw/ros_comm/blob/salsa_noetic_aggregated/tools/rosbag/include/rosbag/recorder.h#L163
Symlink to mcap includes for now, $DEST is ~/other/install
~/other/install/include$ ln -s ~/other/src/mcap/cpp/mcap/include/mcap
catkin build one2z -DCMAKE_CXX_FLAGS=-I$DEST/include
https://github.com/facontidavide/ros_msg_parser
Does the ros message definition exist for live topics, not just in bags or mcaps? Where is it? This package suggests that it does, so any node could subscribe to anything and figure out the message contents.
If it doesn't, why not store the definition in the topic somehow, or on a the parameter server (or similar)? Could see if that works in Zenoh.
Have an example storing internally created ros1 Float64 messages into an mcap in C++, but will change to a subscriber (of type shapeshifter) next, then look at adapting rosbag recorder
https://github.com/lucasw/ros_one2z/blob/main/one2z/src/mcap_recorder.cpp
catkin build one2z -DCMAKE_CXX_FLAGS=-I$DEST/include && rosrun one2z msg_to_mcap; mcap info test.mcap
I was thinking there was something more special about message definitions like this:
mcap::Schema stdMsgsString("std_msgs/Float64", "ros1msg", ros::message_traits::Definition<std_msgs::Float64>::value());
But I think the string returned by value()
can be anything as long as it matches the decoder on the other side- core mcap doesn't care.
Subscribe to any (one) topic and put that into an mcap https://wiki.ros.org/ros_type_introspection/Tutorials/GenericTopicSubscriber
Probably modifying the rosbag source https://github.com/lucasw/ros_comm/tree/salsa_noetic_aggregated/tools/rosbag/src is the way to go, but before that make a minimally featured standalone C++ executable to record and play back at least from preset topics and types.
https://github.com/foxglove/mcap/tree/main/cpp#including-in-your-project - just copy headers in, probably what ros2 bag does? Sort of, the cmake pulls mcap files off the internet while building (puts them in
build/mcap_vendor/_deps/mcap-src
)- the files needed are all in https://github.com/foxglove/mcap/tree/main/cpp/mcap/include/mcaphttps://github.com/lucasw/ros_one2z/blob/main/one2z/scripts/ros1_play_mcap.py has mcap bag playback from rospy (while skipping deserialization and re-serialization)
(TODO compare ros1_play_mcap.py to https://github.com/foxglove/mcap/issues/461#issuecomment-1302804105)