Maps, is it better to publish on a topic or use a service and have other nodes request a map?
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!
This is a good post.
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.
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.
Hope I'm not telling bullshit.... Please someone correct me of I'm wrong!
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.