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

How do I dereference a namespace name in my launch file ?

asked 2021-07-08 03:56:32 -0600

electrophod gravatar image

I want to use the name of my namespace in my launch file, to do some more things, but for that, I would have to dereference my namespace name in the launch file like we dereference arguments using $(arg argument_name)

Any idea how this can be done?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-07-08 05:54:20 -0600

Weasfas gravatar image

Hi @electrophod

How about using the Group option that provides the XML launch. Like so:

<?xml version="1.0"?>
<launch>

  <arg name="ns0" default="ares"/> <!-- Namespace 0 -->
  <arg name="ns1" default="ares"/> <!-- Namespace 1 -->

  <!-- Group namespace 0 Nodes -->
  <group ns="$(arg ns0)">
    <!-- Include nodes that works in namespace 0 -->
    <include...>
    ...
    </include>
  </group>

  <!-- Include nodes that works in global namespace -->
  <include...>
  ...
  </include>

  <!-- Group namespace 1 Nodes -->
  <group ns="$(arg ns1)">
    <!-- Include nodes that works in namespace 1 -->
    <include...>
    ...
    </include>
  </group>

</launch>

And call it like this:

roslaunch package my_launch.launch ns0:=namespace_0 ns1:=namespace_1

I do not know if that is exactly what you want, if it not the case I will update the answer.

edit flag offensive delete link more

Comments

1

In my experience, it is rarely necessary to parameterize the namespace string. If you use the <group> tag, the namespaces will naturally nest, without the developer doing anything further.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-07-08 10:27:32 -0600 )edit
1

@Mike Scheutzow I guess so, but maybe it is an interesting way of organizing your worspaces, for intance let us imagine that we need to work with a fleet of vehicles which is lanched and controlled concurrently with the same architecture.

Weasfas gravatar image Weasfas  ( 2021-07-08 13:28:35 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2021-07-08 03:56:32 -0600

Seen: 157 times

Last updated: Jul 08 '21