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

Revision history [back]

ROS allows multiple publishers on the same topic. So, you could have two subscribers (in the same or different nodes) to different topics that each publish a velocity command on the same topic. Your "priority logic" would need to be smart enough to prevent publishing conflicting messages at the same time, to avoid confusing other nodes.

To accomplish the "message priority" functionality, you could also have a higher-level "gateway" node that listens to both nodes and decides which messages to publish on to the rest of ROS. I'm thinking something like the joint state publisher source_list functionality.

See a similar question here where @Ben_S warns against the difficulties with synchronization in the above approach. His suggestion is to, instead, have the higher-priority task subscribe to messages from the lower-priority task and decide whether to re-publish the low-priority messages or replace them with internally-generated high-priority messages.

click to hide/show revision 2
add subscriber-callback info

ROS allows multiple publishers on the same topic. So, you could have two subscribers (in the same or different nodes) to different topics that each publish a velocity command on the same topic. Your "priority logic" would need to be smart enough to prevent publishing conflicting messages at the same time, to avoid confusing other nodes.

To accomplish the "message priority" functionality, you could also have a higher-level "gateway" node that listens to both nodes and decides which messages to publish on to the rest of ROS. I'm thinking something like the joint state publisher source_list functionality.

See a similar question here where @Ben_S warns against the difficulties with synchronization in the above approach. His suggestion is to, instead, have the higher-priority task subscribe to messages from the lower-priority task and decide whether to re-publish the low-priority messages or replace them with internally-generated high-priority messages.


Edit:
ROS provides several methods to control how Subscriber Callbacks are processed, as described here. By default, all callbacks are processed by a single thread in the same order as the incoming messages are received. It is possible to use multiple threads (with different priority levels) to process the incoming messages, by assigning them to different Callback Queues as described in the above link.

This may be more complex than is required for your application, though. It may be easiest to use the callback functions to store the latest result from each subscriber in globally-accessible variables for your node, then use a separate thread to examine both messages and decide what to publish.