ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROS namespaces

asked 2019-03-10 14:30:36 -0500

arsonist gravatar image

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.

edit retag flag offensive close merge delete

Comments

can you run rostopic list after running your launch file and then cp the result?

Dyson sphere gravatar image Dyson sphere  ( 2019-03-11 01:41:51 -0500 )edit
1

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 a remap to the node tags in your launch file to solve this.

mgruhler gravatar image mgruhler  ( 2019-03-11 02:16:48 -0500 )edit

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:

<group ns="ld1">
    <node pkg="nodelet" type="nodelet" name="my_nodelet2" args="load MyNodelet nodelet_manager">
    <remap from="/ld1/sensors/sensor1" to="/sensors/sensor1"/>
</group>

I tried to put remap outside of namespaces

...
 </group>
<remap from="/ld1/sensors/sensor1" to="/sensors/sensor1"/>

But nothing worked. How should it be done correctly?

arsonist gravatar image arsonist  ( 2019-03-15 09:37:17 -0500 )edit

If it is published under /ld1/sensors/sensor1 should not I at least see this topic in rostopic list?

Yes, you should.

I see only /sensors/sensor1 topics which have publishers but no subscribers.

So, where are the topics of your nodes ending up? Please post the output of rosnode info/your/node/let`.

How should it be done correctly?

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.

mgruhler gravatar image mgruhler  ( 2019-03-18 07:19:27 -0500 )edit

There are no /nodelet_manager/bond subscriptions and publications. The same with /ld2/my_nodelet2.

Node [/ld1/my_nodelet1]
Publications: 
 * /rosout [rosgraph_msgs/Log]

Subscriptions: None

Services: 
 * /ld1/my_nodelet1/get_loggers
 * /ld1/my_nodelet1/set_logger_level

contacting node http://10.0.40.32:54486/ ...
Pid: 7407
Connections:
 * topic: /rosout
    * to: /rosout
    * direction: outbound
    * transport: TCPROS

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.

arsonist gravatar image arsonist  ( 2019-03-23 08:28:07 -0500 )edit

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.

arsonist gravatar image arsonist  ( 2019-03-23 09:53:04 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-06-21 12:49:31 -0500

codhur_jones gravatar image

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

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-03-10 14:30:36 -0500

Seen: 1,327 times

Last updated: Mar 10 '19