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

Maps, is it better to publish on a topic or use a service and have other nodes request a map?

asked 2013-08-30 08:38:38 -0500

jgilsenan gravatar image

updated 2014-01-28 17:17:47 -0500

ngrennan gravatar image

Hello all,

So I have a question regarding the publishing and subscribing to maps.

I have a simple mapping node which creates an nav_msgs/OccupancyGrid map of a robots environment built using LIDAR data. I currently have it written so that it both publishes the map on a ros topic and provides a service which clients call to get a map. As of now, only one other node I am running subscribes to the map topic (other than rviz of course for visualization, but this won't be used when the robot is actually running, except for debugging purposes).

The node that uses the map is a dstarlite global navigator, which I have written so that it can either subscribe to the map topic or call the service to get the map when needed (which, due to the nature of the code making it run slower than the rest of the running nodes, is far less often than the map is published).

My question is: which would be better to use the client-service setup or the publish-subscribe setup?

By better I mean more efficient/less expensive.

In addition I should note that right now, in the development stage of writing the mapping node, I also have it performing several other tasks in addition to publishing inflated obstacle maps. These tasks are to generate/publish both laser scan messages from the existing map to account for the limited angular range (which optimally would occur at a higher frequency) and to generate/publish a laser scan message with an Ego-kinematic space filter applied. If it turns out that the client/service setup is more efficient, then I was simply going to create another client node to also perform these tasks.

Thank you in advance for your help, I apologize for my long-windedness and if I have not exactly followed proper post formats, this is my first post on here and I'm still learning!

edit retag flag offensive close merge delete

Comments

This is a good post.

Thomas D gravatar image Thomas D  ( 2013-08-30 12:24:12 -0500 )edit

I personal guess (and as it's just a guess I add a comment instead of an answer) is that publish/subscribe must be less expensive, as services imply both request and response, but the difference must be minimal.

jorge gravatar image jorge  ( 2013-08-30 17:18:24 -0500 )edit

But I think the important point is whether the client needs to know if all went ok and/or must wait for the map to be ready. Those things are provided by a service. Publish/subscribe is a looser relationship, where the publisher don't mind at all about how their messages are used.

jorge gravatar image jorge  ( 2013-08-30 17:22:31 -0500 )edit

Hope I'm not telling bullshit.... Please someone correct me of I'm wrong!

jorge gravatar image jorge  ( 2013-08-30 17:24:36 -0500 )edit

The one benefit I have noticed is that since everything is still in the development phase, and I haven't yet been able to perfectly sync all of my nodes for publishing/subscribing, this eliminates the need to check for "fresh" data since it returns false if a response was not received.

jgilsenan gravatar image jgilsenan  ( 2013-08-31 05:10:19 -0500 )edit

1 Answer

Sort by » oldest newest most voted
8

answered 2013-09-02 02:32:00 -0500

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).

edit flag offensive delete link more

Comments

1

One advantage of topics is that the map is published, whenever it changes. If your software needs to react on that, service calls won't work as they are triggered by the client.

dornhege gravatar image dornhege  ( 2013-09-02 03:11:41 -0500 )edit

Very true, I´m pretty sure there are a few more nuances I have missed :)

Stefan Kohlbrecher gravatar image Stefan Kohlbrecher  ( 2013-09-02 21:20:16 -0500 )edit

Question Tools

4 followers

Stats

Asked: 2013-08-30 08:38:38 -0500

Seen: 2,678 times

Last updated: Sep 02 '13