Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

ROS message types do not have behavior associated with them; they are containers of the message header and payload. I've found it useful to design most of my nodes using message-passing rather than services, unless synchronous execution is required.

Generally the main node code extracts the message parameters and delegates to real classes for the work. The main node code, which may also be a class, handles the ROS communication. I've found it useful to leave ROS out of the classes that do the work, making them easier to unit test.

The ROS C++ style guide does not give specific guidance, but the Python style guide agrees with my comments above.

In response to your specific questions:

  1. I am designing real C++ classes to implement the behaviors. Generally I'm using message passing in the main node code to communicate with other nodes, rather than exposing services. The messages have no behavior, so code cannot "call messages".

  2. The node is the object exposed to the outside world. You can think of messages as method invocations, but they have specific semantics different from normal member functions: subscriber callbacks operate in their own thread, and they get a single parameter, the message received.