[ros-users] Node Handle details
Jeremy Leibs
leibs at willowgarage.com
Tue Dec 21 18:06:18 UTC 2010
On Tue, Dec 21, 2010 at 8:46 AM, joan_perez <jnperez at iri.upc.edu> wrote:
>
> Hi all,
>
> I have a few questions related to node handles which I believe have not
> been
> asked before. For what I have seen, there are many different ways of using
> node handles. I could not find the answers in the
> http://www.ros.org/wiki/roscpp/Overview/NodeHandles wiki nor in any
> previous topic.
>
> 1- It is better to have a single node handle for all topics in a node, or
> it
> is more appropriate to use a node handle per topic?
>
Generally, a single node handle is fine. The only time people typically
want to create extra nodehandles is to push a group of topics into a
namespace. e.g. all the outgoing image topics into a "camera" namespace.
But even then, all topics in the same namespace can make use of the same
nodehandle.
>
> 2- Related to these question, should I declare node handles as member class
> attributes or just as function variables? I have even seen node handles
> created on a function call.
>
In the grand scheme of things, nodehandles, are fairly cheap, but they are
certainly not free to create. Member class attributes is almost certainly
the way to go. I would avoid creating a new node handle in any function
that is called in a loop. But if the function is only being called once by
your main function, there's no reason the node handle has to be part of a
class.
>
> 3- Should I better use node handle's namespace rather than node namespace?
>
>
I'm not sure what you mean by this. The default nodehandle is in the
namespace of the node. Nodehandle namespaces should only be used to push
things down further.
> 4- Which is the main purpose of the private node handle (the one with
> private namespace "~")? It is meant to be used only for the parameter
> server?
>
This has never been terribly well specified, and different people will give
you different opinions. The rule of thumb has been to use the node private
namespace for very specific things that are only relevant to your node.
Configuration parameters is one of the best examples of this. You can, of
course, publish topics there, but it doesn't fit well within the notion of
"anonymous publish-subscribe" since it means any subscriber needs to know
the name of your node to listen to it. The key here is that nodes should
really never be looking inside the private namespace of another node.
>
> 5- Is there any additional feature (apart from queuing relative namespace)
> for specifying a node handle as child from the other?
>
Managing relative namespaces is all that nodehandles are good for. When you
make one nodehandle the child of another, all it does is append its
namespace onto the namespace of its parent.
Hope that helps,
--Jeremy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ros.org/pipermail/ros-users/attachments/20101221/2a59e976/attachment-0003.html>
More information about the ros-users
mailing list