[ros-users] Node Handle details

joan_perez jnperez at iri.upc.edu
Tue Dec 21 23:52:07 UTC 2010


Thanks for your complete answers, they will surely help me to develop a
more coherent code.

Node handles can be used in so many ways, that sometimes you can not
distinguish which is the most appropriate solution for each case.

Getting into details:
>
>
> These are good questions and good answers, maybe worth adding to the
> wiki somewhere:
>
I am sure Jeremy's answers may help people to better understand node
handle use and specification.

> On Tue, Dec 21, 2010 at 12:06 PM, Jeremy Leibs <leibs at willowgarage.com>
> wrote:
>>
>>
>> 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.
>>
I get it, if there is no extra overhead, I can manage with a single node
handle unless I want to push down a topic.

>>>
>>> 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.
>>
I was just wondering what happened to the previously created topics once
the node handle was destroyed. I see once the topic is created, it does
not need the node handle anymore.

>>>
>>> 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.
>>
I use ros::init() to specify the node namespace. What I expected is that
namespace to appear on every single topic/service created in that node,
but for some reason that was not happening. To retrieve and append the
node namespace to the topic/service name, I use the following line:
pub =
node_handle_.advertise<msg>(ros::names::append(ros::this_node::getName(),
"port_name"), 100);

What I wanted to compare was that solution against this one:
my_nh("nh_namespace");
pub = my_nh.advertise<msg>("port_name", 100);

In both cases, I obtain something like: /domain/topic, and I was wondering
which was the appropriate/common way to resolve it.

>>>
>>> 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.
>>
I see. I certainly need to play a bit more with the private namespace to
really understand it properly.

>>>
>>> 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.
>
Pretty clear as well.


Thanks again for all the detailed answers.
>
> --
>  joq
> _______________________________________________
> ros-users mailing list
> ros-users at code.ros.org
> https://code.ros.org/mailman/listinfo/ros-users
>
>
> ______________________________________
> View message @
> http://ros-users.122217.n3.nabble.com/Node-Handle-details-tp2126850p2127452.html
>
> To unsubscribe from Node Handle details, visit
> http://ros-users.122217.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=2126850&code=am5wZXJlekBpcmkudXBjLmVkdXwyMTI2ODUwfDE4ODQ4Nzc2NDQ=


-- 
View this message in context: http://ros-users.122217.n3.nabble.com/Node-Handle-details-tp2126850p2128732.html
Sent from the ROS-Users mailing list archive at Nabble.com.



More information about the ros-users mailing list