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

Why ROS messages do not inherit from a base class??

asked 2014-12-19 06:25:45 -0600

Tsirif gravatar image

Hello there!

I am a software engineer and I try to design a general message-type-agnostic multiple socket node interface that wraps a NodeHandle and also i have the demand to make it able to change these dynamically on the runtime using an interface that we have developed. This inteface, named StateClient, is implemented by someone who wants to hear about state changes in the system. A StateServer is announcing to all subscribers the state change and to which state we are entering, in order for nodes that are StateClients to change behaviour on the runtime. An example of what i want to do:

Suppose that our system works properly being in state 2. Our example node is the system NodeExample and is subscribed to some concrete topics of concrete message types, publishes other concrete message types to concrete topics and also uses a concrete method of processing the input data to transform them into output data in a functional way, such as when processing raw data in order to detect something or to transform them. Then let's say that state changes to state 3. In this state i want to change the postprocessing of the data in order to form a different output message type that will be delivered to a different topic. In state 4, i may want to change my subscriber options instead and subscribe plus to another topic of some type and change naturally the preprocessing of the input data.

I find this task extremely difficult because of the way ROS messages are implemented. If ROS messages inherited from a base class things would be easier because all subscribers would then refer to that base message type and i could easily with a bridge pattern define the concrete message type on runtime. ROS messages are not implemented like this unfortunately, so i try to find a solution using template metaprogramming (using boost.variant??) or function-binding to some dynamic language, such as python (with boost.python).

Long story short: How come ROS messages do not inherit from a standard common base container? How could one implement something like that (dynamically change the types being used in our node's interface with the system)? Note that i want to build something that is agnostic both to type and the number of input or output messages.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-03-02 18:04:05 -0600

tfoote gravatar image

ROS used to have messages with a common base class. Switching to templated messages made things faster and enabled custom datatypes with custom serialization.

You can find the relevant changelog here: The behaviour has been moved into templated traits.

Some of the in process reviews are linked from there to here and here

There are techniques to operate on the data as @Wolf points out. Shape Shifter is an example of how to work with messages without fully knowing their type.

edit flag offensive delete link more

answered 2014-12-19 06:51:28 -0600

Wolf gravatar image

I am not 100% sure I completely understood what you intent to do, but I think your basic intent is to subscribe to a message of which you do not know the type (at least at compile time, maybe in your lib-part even not at runtime). If so maybe it'd be of interest for you how this is done in topic_tools/throttle:

There a message is subscribed (and republished) without knowing its type. This is achieved by a class called ShapeShifter that exposes type getter / md5sum getter etc. for an arbitrary message type:

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2014-12-19 06:25:45 -0600

Seen: 3,055 times

Last updated: Mar 02 '15