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

How do we remap all of the input and ouput topics from a node in a systematic way?

asked 2020-05-31 10:44:46 -0500

Britsk gravatar image

updated 2020-05-31 21:10:13 -0500

The probIem I am facing is that I am using a package with the following launch file:

<launch>
        <node pkg="mypackage" type="task_A" name="task_A_node" output="screen">
        </node>

        <node pkg="mypackage" type="task_B" name="task_B_node" output="screen">
        </node>
</launch>

And when running rqt_graph, one will get the following graph:

/input -> /task_A_node -> {/internal_topic1, /internal_topic2}-> /task_B_node -> {/output1, /output2}

Here the topic names "/input", "/internal_topic1", "/internal_topic2", "/output_1", "/output_2" have been hardcoded in the program by the author of the package. There are actually a lot more topics so it's actually quite complicated to modify the code to parameterize the naming of the input/output topics.

Now that I want to run two instances of this program in paralel as black boxes, each with its own input like this:

<launch>
       <!-- group 1 -->
       <group>
           <node pkg="mypackage" type="task_A" name="task_A_node1" output="screen">
           </node>
           <node pkg="mypackage" type="task_B" name="task_B_node1" output="screen">
           </node>
      </group>

      <!-- group 2 -->
      <group>
           <node pkg="mypackage" type="task_A" name="task_A_node2" output="screen">
           </node>
           <node pkg="mypackage" type="task_B" name="task_B_node2" output="screen">
           </node>
      </group>
</launch>

Now the issue is taht if I don't remap the topics, the input and output of group 1 and group 2 will be mixed. So the way I was thinking to work around this is to remap all topics related to the each instance to the same name with a suffix, for example:

<launch>
       <!-- group 1 -->
       <group>
           <node pkg="mypackage" type="task_A" name="task_A_node1" output="screen">
               <remap from="/input" to="/input_group1">
               <remap from="/internal_topic1" to="/internal_topic1_group1">
               <remap from="/internal_topic2" to="/internal_topic2_group1">
           </node>

           <node pkg="mypackage" type="task_B" name="task_B_node1" output="screen">
               <remap from="/internal_topic1" to="/internal_topic1_group1">
               <remap from="/internal_topic2" to="/internal_topic2_group1">
               <remap from="/output1" to="/output1_group1">
               <remap from="/output2" to="/output2_group1">
           </node>
      </group>

      <!-- group 2 -->
      <group>
           <node pkg="mypackage" type="task_A" name="task_A_node2" output="screen">
               <remap from="/input" to="/input_group2">
               <remap from="/internal_topic1" to="/internal_topic1_group2">
               <remap from="/internal_topic2" to="/internal_topic2_group2">
           </node>
           <node pkg="mypackage" type="task_B" name="task_B_node2" output="screen">
               <remap from="/internal_topic1" to="/internal_topic1_group2">
               <remap from="/internal_topic2" to="/internal_topic2_group2">
               <remap from="/output1" to="/output1_group2">
               <remap from="/output2" to="/output2_group2">
           </node>
      </group>
</launch>

So I want to ask if there is anyway to quickly remap all topics that come in and out of a node to something with the same name but with a suffix MORE EFFECIENTLY, other than having to do that one by one like I did above?

Thanks!

Edit: clarifying the issue with examples.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-05-31 12:12:21 -0500

gvdhoorn gravatar image

updated 2020-05-31 12:49:51 -0500

So I want to ask if there is anyway to quickly remap all topics that come in and out of a node to something with the same name but with a suffix

It wouldn't be a suffix, but a prefix, but perhaps you could namespace the nodes (look at the ns attribute in the Attributes section)?

We don't call that remapping any more, but in a sense, the end result is the same.


Edit: after your edit: you'd want to add a ns attribute to your group elements. See the group docs, Attributes. Then remove all the remap elements from your nodes.

edit flag offensive delete link more

Comments

Thanks for your suggestion on the ns attribute. Though this only adds the prefix to the node names. The topics are still under the global namespace / as they have been hardcoded, especially the supposedly internal ones.

Britsk gravatar image Britsk  ( 2020-05-31 13:08:20 -0500 )edit

Then that would be a problem with the way the nodes are implemented. If the topic names have been made fully resolved (ie: global, start with a /) then they cannot be namespaced.

If that's the case, I'm afraid there is no other way than manually remapping everything.

That's actually exactly why you don't want to use global/absolute names.

gvdhoorn gravatar image gvdhoorn  ( 2020-05-31 15:11:18 -0500 )edit

Are these publicly available nodes? If so, could you link us to them?

gvdhoorn gravatar image gvdhoorn  ( 2020-05-31 15:11:45 -0500 )edit

Sure, it's the lio-mapping nodes from the HKUST team here

Britsk gravatar image Britsk  ( 2020-05-31 21:12:52 -0500 )edit

Yes, those nodes advertise(..) absolute/global topic names. Those cannot be namespaced.

I would suggest to log an issue with the maintainers/developers to get this fixed.

In the meantime, you could perhaps remove all the leading / from the topic names in a fork and test whether everything still works (other nodes could assume topics are global, and non-global topics could make them unable to subscribe).

Without fixing those topic names, namespacing will never work.

gvdhoorn gravatar image gvdhoorn  ( 2020-06-01 04:36:28 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2020-05-31 10:44:46 -0500

Seen: 399 times

Last updated: May 31 '20