0
$\begingroup$

Rosanswers logo

I would like to create a map of a topic name to a template function that constructs a message in the context of publishing to a topic. Essentially I would be following the pattern described in this SO post.

However, the caveat is that the objects need to share a parent class. I was looking at the header files and it doesn't seem to be the case, but perhaps there is something that I don't see.

Is there a shared parent class for all messages?


Originally posted by cpagravel on ROS Answers with karma: 156 on 2017-03-30

Post score: 3

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Yes, for Python code, see https://github.com/ros/genpy/blob/cb07134e084a4fb6099de5cefcbb6b9a7f666cf5/src/genpy/message.py#L269

No, for C++ code, see https://github.com/ros/gencpp/blob/90a850954f7dec3d7274b4fc36d35b1fe6676b22/scripts/msg.h.template#L62


Originally posted by Dirk Thomas with karma: 16276 on 2017-03-30

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by cpagravel on 2017-03-30:
That's what I gathered as well from looking at the header files, but I had hoped I overlooked something. Is there a way to change this without breaking anything?

Comment by Dirk Thomas on 2017-03-30:
Well, you could change the C++ template locally and rebuild all of ROS from source to utilize it. But your code using that would be incompatible with "normal" ROS packages.

Comment by cpagravel on 2017-03-30:
Can I suggest this for the future ROS versions? It's a small change to make.

Comment by Dirk Thomas on 2017-03-30:
Please see why a base class has been removed in the first place: http://answers.ros.org/question/199829/why-ros-messages-do-not-inherit-from-a-base-class/

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.