ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Recursive message definition in ROS2

asked 2023-01-09 15:00:19 -0600

jbarry gravatar image

Hi,

Is it possible to create a recursive message type in ROS2? E.g.: message Node.msg int64 id my_msgs/Node neighbors

This is currently causing compiler errors in ROS2 Humble for me but I was wondering if there was a flag or something I could use?

For more context, I'm working on writing a protobuf to ROS converter (which has generally been straightforward). However protobuf allows recursive messages and message loops (e.g. message A references message B which references message A). Figuring out a ROS equivalent to this if ROS doesn't allow recursive messages is going to be tricky!

Thanks! -Jenny

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2023-01-10 12:40:15 -0600

fmrico gravatar image

updated 2023-01-10 12:41:48 -0600

No. It is not possible, sorry. I made the same question here:

https://github.com/ros2/rosidl_typesu...

edit flag offensive delete link more

Comments

Ah thanks! I googled a bunch but didn't find that. I wonder if pointing out that that solution isn't good for message loops would increase its likelihood of being added someday...

jbarry gravatar image jbarry  ( 2023-01-10 12:50:48 -0600 )edit
1

answered 2023-01-10 02:52:47 -0600

Hi,

To my understanding message definitions are used to generate POD structures. A recursive definition would generate an infinite structure, e.g. in C++ :

struct Node
{
  Node neighbor;
};

Note that an array of Node should do the trick but it seems it does not compile either, though the C++ version is fine:

struct Node
{
  std::vector<Node> neighbors;
};

In your case one could suggest an array of id's to represent the neighbors of the node.

edit flag offensive delete link more

Comments

Unfortunately this doesn't help in my case. I'm writing a tool to automatically convert protobuf messages to ROS messages. I don't know the content of the messages ahead of time and can't change it. Protobuf allows recursive message definitions (presumably their implemention involves pointers for C++) but ROS messages with recursive definitions don't compile because they appear not to be able to forward declare. I can work around this using byte strings but if there's a way to tell the compiler to forward declare the message type that would be easier.

jbarry gravatar image jbarry  ( 2023-01-10 08:03:46 -0600 )edit

Question Tools

3 followers

Stats

Asked: 2023-01-09 15:00:19 -0600

Seen: 349 times

Last updated: Jan 10 '23