ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

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

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

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

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

Weasfas gravatar image

Hi @electrophod

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

<?xml version="1.0"?>

  <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 nodes that works in global namespace -->

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


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



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 -0500 )edit

@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 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



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

Seen: 66 times

Last updated: Jul 08 '21