ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A

ROS2 C based dynamic typesupport example?

[This is a cross-post from ROS answers on request from the ROS Answers Administrator]

I’m pretty new to ROS and still a bit overwhelmed :slight_smile: 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 :frowning: It seems hard to find an example :frowning:

Can anyone point at an example or describe the general idea to walk over a message?

Thanks — Jan


We have a simple library that can do this. Let me find out of we can release it yet.

1 Like

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.

If you are going to write a guide/tutorial for this, please do so on GitHub - ros2/ros2_documentation: ROS 2 docs repository (which gets rendered to We aren’t using the wiki for ROS 2 documentation. Thanks!