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

Revision history [back]

If you have multiple other nodes that need map data on a irregular, relatively low rate, on-demand basis, it likely is a good idea to use service calls. This way, bandwidth and CPU (for serialization) are only consumed when needed and (depending on the actual scenario) map data can be more up-to-date than when using the last published map data.

I think it´ s pretty hard to state a general rule, as there are multiple factors playing a role here:

  1. Service calls for example can´t be recorded with rosbag, which can be a disadvantage when trying to understand interaction in a complex system of nodes.
  2. A single service call has higher delay and consumed bandwidth when compared to a single publication on a topic, but using service calls can mean that only single queries are required as opposed to a "stream" on a topic.

  3. Service clients know when a service call fails, while a topic callback not getting triggered will generally happen silently.

See also this Q/A for a general discussion of the matter.

Also, if you publish map data for debugging, it makes sense to put all work related to that in a block that checks if anyone is actually subscribing:

if (map_publisher_.getNumSubscribers() > 0){

  nav_msgs::OccupancyGrid grid_map;

  //Do work/fill grid_map here

  map_publisher_.publish(grid_map);
}

This way, there´ s only any real work done when there is at least one subscriber (for example rviz).