How to remap a topic to sub namespaces
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.
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.
Related question: http://answers.ros.org/question/12105/can-i-access-the-absolute-or-parent-namespace-of-a-node-from-within-a-launch-file/
With a temporary workaround: http://answers.ros.org/question/12105/can-i-access-the-absolute-or-parent-namespace-of-a-node-from-within-a-launch-file/?answer=68866#post-id-68866