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

How to remap a topic to sub namespaces

asked 2013-04-09 11:07:00 -0600

thebyohazard gravatar image

updated 2013-07-24 06:57:10 -0600

Let's say I have a node, io_node, that provides a service, service, and publishes on a topic, topic. I also have nodes of type client_node and client_node2 (both named client_node) that use service and subscribe to topic. The client_nodes are in two different namespaces, a and b for various reasons.

So rosnode list would show:

/io_node
/a/client_node
/b/client_node

The problem is that I can't get remapping to work with my launch files no matter where I put the remap tags. I want the two client nodes to subscribe to /topic and use /service, but they subscribe to their namespace instead (for example, /a/client_node subscribes /a/topic and tries to use /a/service).

rostopic list shows

/topic
/a/topic
/b/topic

Here's one version of the top level launch file:

<launch>
   <include file=$(find io_node)/launch/io.launch"/>

   <group>
     <remap from="topic" to="a/topic"/>
     <include file=$(find client_node)/launch/client.launch" ns="a"/>
   </group>

   <group>
     <remap from="topic" to="b/topic"/>
     <include file=$(find client_node2)/launch/client.launch" ns="b"/>
   </group>
</launch>

And here's a client.launch (client_node2 is similar):

<launch>
        <node pkg="client_node" name="client_node" type="client_node" output="screen" respawn="true"/>
</launch>

The whole top level launch file is going to be used in yet another launch file, with multiple instances of the three nodes being used in one system only with different namespaces, so I don't think I can use global namespaces. I've tried

  • putting the ns tag in a group tag in the client launch files
  • putting the ns tag in the launch tag in the client launch files and putting ns in the node tag
  • putting the ns tag in the group tag in the top level launch file
  • putting the remap tag in the node tag in the client launch file
  • putting the remap tag in the group tag in the client launch file
  • changing the remap to be from="a/topic" to="topic"

What am I missing here?

EDIT

Guess I should say that I filed an enhancement request. In the meantime, my quick fix was to ditch the namespaces and use the names client_node_a and client_node_b to make them both in the same namespace, and thus both able to use /topic. This isn't really the solution I wanted, though, and isn't really all that flexible...

I tried Boris's suggestion, too, and it works, but I have a bunch of launch files that makes argument passing tedious.

edit retag flag offensive close merge delete

Comments

I recently came across this same problem, I don't know the best fix, but just want to say I think the lack of functionality here (I would venture to say "bug") makes it really hard to scale larger projects without some kind of name collision.

tfurf gravatar image tfurf  ( 2013-07-24 06:29:31 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2013-04-09 19:07:42 -0600

updated 2016-02-16 10:42:14 -0600

lucasw gravatar image

Looks like if you specify a path to a topic without leading / the whole string is treated as a topic name and obviously cannot be found. So remapping from foo to bar will work, but baz/foo to bar will not.

Specifying the absolute path to the topic to be remapped solves it, i.e. remapping from /baz/foo to bar will result in /baz/bar and from /baz/foo to /bar gives /bar.

P.S. Honestly remapping is a very confusing technique and I personally prefer to specify topic names as node parameters.

edit flag offensive delete link more

Comments

I would do that, but the launch file I called top-level won't really be top-level in the future. It will be used multiple times, each instance launched in another namespace. So /alpha/topic, /beta/topic and so on, and I don't know how many there will be or what their names will be. Thanks though.

thebyohazard gravatar image thebyohazard  ( 2013-04-10 03:27:17 -0600 )edit

Maybe using arguments is the only way then, I mean <arg> tags with corresponding $(arg) calls.

Boris gravatar image Boris  ( 2013-04-10 03:49:46 -0600 )edit
0

answered 2014-09-29 17:06:37 -0600

thebyohazard gravatar image

I haven't the time to look into it too deeply right now, but at ROSCON2014, we got a preview of ROS 2.0, and amongst the awesome new features mentioned was "topic aliasing" which seemed to me to be just what we need right here. So be sure to check out the video and the ROS2 page if you have more time than I.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2013-04-09 11:07:00 -0600

Seen: 11,382 times

Last updated: Feb 16 '16