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

merging of launch files

asked 2018-08-31 18:16:01 -0500

debonair gravatar image

updated 2018-09-04 12:13:15 -0500

I have 2 launch files which are launching same node but one launches with namespace and other with no namespace. how do I combine both of them? is it possible to make namespace argument optional ?

launch_file1 :

<node pkg="node_pkg" type="node_type" name="node_name" >


<node pkg="node_pkg" type="node_type" name="node_name" args="load pkg_name/classname" ns="$(arg namespace)">

so i am launching same node with no_namespace and with namespace.

<node pkg="node_pkg" type="node_type" name="node_name"   if="$(arg use_namespace)" ns="$(arg namespace)">

so i combined both launch files with above line in one single launch file. and i am using use_namespace to specify whether i want to launch node with namespace or not. but now it is launching nodes with onyl namespace my understanding from above line is just use ns if, "if" condition is satisfied and launch it with <node pkg="node_pkg" type="node_type" name="node_name"

edit retag flag offensive close merge delete


It is not clear what you want to achieve. Do you want your nodes to be in the same namespace/no namespace? Namespace is an optional attribute. If @gvdhoorn 's answer is what you were looking for accept it, otherwise elaborate on "combine".

Reamees gravatar image Reamees  ( 2018-09-03 04:05:27 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-09-01 01:49:46 -0500

gvdhoorn gravatar image

Namespace attributes cannot be empty, so it's not directly possible to make something like that optional I believe.

Something like this might work:

  • first launch file:

      <arg name="use_namespace" default="false" />
      <include file="other.launch"     if="$(arg use_namespace)" ns="my_ns" />
      <include file="other.launch" unless="$(arg use_namespace)" />
  • second launch file (just an example):

      <param name="la" value="123" />
edit flag offensive delete link more


what should be my other.launch file contain? just launch node? and we don't specify namespace there?

debonair gravatar image debonair  ( 2018-09-04 11:49:28 -0500 )edit

what should be my other.launch file contain? just launch node?

whatever you want it to contain. Could launch nodes, include other launch files, everything.

and we don't specify namespace there?


the first launch file essentially "pushes" the other launch file down into a ns.

gvdhoorn gravatar image gvdhoorn  ( 2018-09-04 12:00:46 -0500 )edit

is it possible to combine include code with if condition in your answer.

debonair gravatar image debonair  ( 2018-09-04 12:18:55 -0500 )edit

I had to write node launch code <node pkg> with params twice. one with if tag and one with unless tag. i was trying to find out way to avoid writing params twice.

debonair gravatar image debonair  ( 2018-09-04 12:31:23 -0500 )edit

Which you can do, if you follow my approach.

The "second launch file" has all the nodes without a ns. If you start that, nothing will be in a namespace.

The "first launch file" starts the second but in a namespace. Don't start the second launch file: no namespace.

No need to duplicate.

gvdhoorn gravatar image gvdhoorn  ( 2018-09-04 12:33:07 -0500 )edit

great. Thanks so much!

debonair gravatar image debonair  ( 2018-09-04 13:15:55 -0500 )edit

Question Tools



Asked: 2018-08-31 18:16:01 -0500

Seen: 892 times

Last updated: Sep 04 '18