Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ros1 mcap record and playback #4

Open
lucasw opened this issue Oct 27, 2023 · 9 comments
Open

ros1 mcap record and playback #4

lucasw opened this issue Oct 27, 2023 · 9 comments

Comments

@lucasw
Copy link
Owner

lucasw commented Oct 27, 2023

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 foxglove/mcap#461 (comment))

@lucasw
Copy link
Owner Author

lucasw commented Oct 28, 2023

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
Copy link
Owner Author

lucasw commented Oct 28, 2023

@lucasw
Copy link
Owner Author

lucasw commented Oct 28, 2023

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
Copy link
Owner Author

lucasw commented Oct 28, 2023

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
Copy link
Owner Author

lucasw commented Oct 28, 2023

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
Copy link
Owner Author

lucasw commented Oct 29, 2023

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

@lucasw
Copy link
Owner Author

lucasw commented Aug 23, 2024

Have rust based mcap record all in mcap_tools: https://github.com/lucasw/mcap_tools/blob/main/mcap_tools/src/mcap_record.rs

But next thing is to make https://github.com/lucasw/ros_one2z/blob/main/one2z/scripts/ros1_play_mcap.py be able to compute md5sums from the message definition without using known message types, after that can duplicate in rust in mcap_tools.

Try running this standalone, print out what the stripped down message definition looks like then duplicate in the mcap player:
https://github.com/ros/genmsg/blob/noetic-devel/src/genmsg/gentools.py#L58-L89

Can I just run these tests like this?

pytest -rP src/genmsg/test/test_genmsg_gentools.py::test_compute_md5_text

Need to copy ros_comm/test/test_roslib_comm/test/md5tests into install location (because disabled test packages when doing the base install) -> no just make a new devel workspace with only ros_comm in it, run tests from there.

Log.msg:

byte DEBUG=1
byte INFO=2
byte WARN=4
byte ERROR=8
byte FATAL=16
std_msgs/Header header
  uint32 seq
  time stamp
  string frame_id
byte level
string name
string msg
string file
string function
uint32 line
string[] topics

The sub message Header is replaced with the hash of that type, then the md5sum of this cleaned string is performed:

'byte DEBUG=1\nbyte INFO=2\nbyte WARN=4\nbyte ERROR=8\nbyte FATAL=16\n2176decaecbce78abc3b96ef049fabed header\nbyte level\nstring name\nstring msg\nstring file\nstring function\nuint32 line\nstring[] topics'
rosmsg md5 Log
[rosgraph_msgs/Log]: acffd30cd6b6de30f120938c17c593fb

@lucasw
Copy link
Owner Author

lucasw commented Aug 23, 2024

example _full_text message definition

Header header
string child_frame_id
geometry_msgs/PoseWithCovariance pose
geometry_msgs/TwistWithCovariance twist
================================================================================
MSG: std_msgs/Header
uint32 seq
time stamp
string frame_id
================================================================================
MSG: geometry_msgs/PoseWithCovariance
Pose pose
float64[36] covariance
================================================================================
MSG: geometry_msgs/Pose
Point position
Quaternion orientation
================================================================================
MSG: geometry_msgs/Point
float64 x
float64 y
float64 z
================================================================================
MSG: geometry_msgs/Quaternion
float64 x
float64 y
float64 z
float64 w
================================================================================
MSG: geometry_msgs/TwistWithCovariance
Twist twist
float64[36] covariance
================================================================================
MSG: geometry_msgs/Twist
Vector3  linear
Vector3  angular
================================================================================
MSG: geometry_msgs/Vector3
float64 x
float64 y
float64 z

Need to create a dictionary of md5sums, but with placeholder text to substitute other md5sums of sub types

@lucasw
Copy link
Owner Author

lucasw commented Aug 24, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant