ROS namespaces
Hello!
I have the problem which I guess is connected with my not understanding ROS namespaces issue good enough. I tried to google the problem, but I can't even articulate the correct question, so here am I.
I want the same nodelet to be started twice, and the following variant works:
<launch>
<node pkg="nodelet" type="nodelet" name="nodelet_manager" args="manager"/>
<node pkg="nodelet" type="nodelet" name="my_main" args="load MyMain nodelet_manager"/>
<node pkg="nodelet" type="nodelet" name="my_nodelet1" args="load MyNodelet nodelet_manager"/>
<node pkg="nodelet" type="nodelet" name="my_nodelet2" args="load MyNodelet nodelet_manager"/>
</launch>
Nodelets subscribe for a topic /sensors/sensor1, which is being advertised by a MyMain nodelet.
Now I need my nodelets to be in different namespaces in order to use params for each particular nodelet further.
I tried the following, it launches without any problem, but there are no subscriptions for /sensors/sensor1. MyMain is in global namespace and I don't understand what is the problem for my nodelets to subscribe for MyMains topic /sensors/sensor1.
<launch>
<node pkg="nodelet" type="nodelet" name="nodelet_manager" args="manager"/>
<node pkg="nodelet" type="nodelet" name="my_node" args="load MyNode nodelet_manager"/>
<group ns="ld1">
<node pkg="nodelet" type="nodelet" name="my_nodelet1" args="load MyNodelet nodelet_manager"/>
</group>
<group ns="ld2">
<node pkg="nodelet" type="nodelet" name="my_nodelet2" args="load MyNodelet nodelet_manager"/>
</group>
</launch>
I would be very gratefull if someone explained what is wrong with my code and how to fix it.
can you run
rostopic list
after running your launch file and then cp the result?If your nodelets are implemented as is most common, i.e. your subscribers are something along the line of
nh = ros::NodeHandle(); sub_ = nh.subscribe<TYPE>("sensors/sensor1", ...);
your node subscribes always to topics relative to the nodes namespace. Thus, after putting them in a group, the nodelet would subscribe to
/ld1/sensors/sensor1
. You can simply add aremap
to thenode
tags in your launch file to solve this.If it is published under
/ld1/sensors/sensor1
should not I at least see this topic in rostopic list? I see only/sensors/sensor1
topics which have publishers but no subscribers. Moreover, I tried adding ramap inside node tags in such manner:I tried to put remap outside of namespaces
But nothing worked. How should it be done correctly?
Yes, you should.
So, where are the topics of your nodes ending up? Please post the output of
rosnode info
/your/node/let`.from
is how the topic is specified in your publisher/subscriber. Take care of leading slashes.to
is what it should be in the ROS system.There are no /nodelet_manager/bond subscriptions and publications. The same with /ld2/my_nodelet2.
Moreover, my nodelets within the namespaces fail after several seconds with "bond broken" error, while everything is alright with them, when there are no namespace. The difference is only in
<group ns="ld">
tag surrounding the node tag.I have my nodelet implemented in such way, if it is important:
nh = getMTNodeHandle();
distanceSub = nh.subscribe("sensors/sensor1", ...)
I tried writing
nh = ros::NodeHandle();
and it stopped crashing, but it still does not have any/nodelet_manager/bond
publications or subscriptions, as a nodelet outside of any namepace does.