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.
Asked by arsonist on 2019-03-10 14:30:36 UTC
Answers
I think I'm understanding your question correctly. You would like to publish all of the same topics in the different nodelets, but not step on each other - so you'd like to publish to a sub-namespace? I had the same issue and I figured out a workaround. I created a base namespace that all nodelets would belong to and then remapped that namespace to a sub-namespace for each nodelet that needed it.
<launch>
<group ns="my_sensors">
<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">
<remap from="/my_sensors" to="/my_sensors/ld1" />
</node>
<node pkg="nodelet" type="nodelet" name="my_nodelet2" args="load MyNodelet nodelet_manager">
<remap from="/my_sensors" to="/my_sensors/ld2" />
</node>
</group>
</launch>
All of your publications will change to the sub-namespace, but not the subscriptions.
Hope this helps
Asked by codhur_jones on 2019-06-21 12:49:31 UTC
Comments
can you run
rostopic list
after running your launch file and then cp the result?Asked by Dyson sphere on 2019-03-11 01:41:51 UTC
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.Asked by mgruhler on 2019-03-11 02:16:48 UTC
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?
Asked by arsonist on 2019-03-15 09:37:17 UTC
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.Asked by mgruhler on 2019-03-18 07:19:27 UTC
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.Asked by arsonist on 2019-03-23 08:28:07 UTC
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.Asked by arsonist on 2019-03-23 09:53:04 UTC