lucasw / ros_one2z

Similar node graphs in vanilla ros1 and ros2 and also zenoh, focus on localhost using python but also C++ and maybe rust
BSD 3-Clause "New" or "Revised" License
4 stars 0 forks source link

ros1 mcap record and playback #4

Open lucasw opened 8 months ago

lucasw commented 8 months ago

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/mcap

https://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)

lucasw commented 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.

lucasw commented 8 months ago

Replace this Bag with mcap::McapWriter https://github.com/lucasw/ros_comm/blob/salsa_noetic_aggregated/tools/rosbag/include/rosbag/recorder.h#L163

lucasw commented 8 months ago

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
lucasw commented 8 months ago

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.

lucasw commented 8 months ago

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.

https://mcap.dev/spec#schema-op0x03

https://mcap.dev/spec/registry#ros1-1

lucasw commented 8 months ago

Subscribe to any (one) topic and put that into an mcap https://wiki.ros.org/ros_type_introspection/Tutorials/GenericTopicSubscriber