I’m pretty new to ROS and still a bit overwhelmed I’m studying the options for a successor of rosprolog for ros2. Based on the rclpy code is wasn’t that hard to use rcl and rmw and get the library initialized and a node created. Somewhat harder was to subscribe to a topic. Eventually I managed to figure out I could dynamically load the C based .so file that defines the messages for a package, find the right function and call it to get the rosidl_message_type_support_t instance. So far so good.
The next challenge is to actually assemble or decompose a message. I think the rosidl API dealing with dynamic message (de) serialization is the most appropriate approach. As a dynamically typed language the extra overhead of walking over the types using runtime switches is probably smaller than the cost to convert the raw byte data into the format using inside Prolog anyway.
So, I’m trying to get my head around using dynamic type support to walk over a message and create a message. I have a hard time figuring out where to start though It seems hard to find an example
Can anyone point at an example or describe the general idea to walk over a message?
Here we go. This repository contains code that uses dynamic type introspection to translate messages between the in-memory representation and a YAML representation. It can go both directions, and all it requires is that you provide the compiled shared library that contains the type support for the messages you want to deal with. For message types distributed with ROS these libraries are already provided. The functions in this code should show you how to dynamically manage types. Feel free to ask if there’s something you don’t understand.
It doesn’t do services or actions (yet), but the principle is the same since each part of a service or action is just a message.
Thanks a lot! In the meanwhile I figured out most of the stuff needed to receive messages. There are still some open ends and I didn’t even start sending messages. This will surely help and hopefully will also help others.
Should this question and solution be documented in the wiki? It strikes me that this may not be an immediately obvious solution, and someone in future may want to do the same thing.
I think it is a bit too early. If all works out (which seems likely), I’m happy to write some text to get people started a little quicker on this than I did. I’m so new to the ROS2 design that I may have missed a design document that would have made this all a lot easier though.
Hi,
Thank you for providing the great library. I’ve modified the conversion_cpp in examples to create a callback for LaserScan msg and tested it. However, I’m encountering a “Memory allocation failed: std::bad_alloc” error at the line “const std::string yaml_string = dynmsg::yaml_to_string(yaml_msg);”. What would be the best way to proceed?