0
$\begingroup$

Rosanswers logo

I'm working on a multiple robot application and am trying to develop a clean launch file. I have multiple blocks of XML in my launch file that look like...

<group ns="r1">
  <include file="$(find mypack)/launch/robot.launch">
    <arg name="namespace" value="r1" /> 
  </include>
</group>

I need to pass the namespace to the robot.launch file explicitly (long story). I don't like it that I have to input the "r1" value twice. It would be more pleasing if I could use substitution to assign a value to the namespace argument so that I only had to define the "r1" value once. Something like...

<group ns="r1">
  <include file="$(find mypack)/launch/robot.launch">
    <arg name="namespace" value="$(arg ns)" /> 
  </include>
</group>

I tried to have an argument before the group tag that I reassigned each time, but that caused errors. Evidently I can't reassign arguments.

Any creative thoughts much appreciated.


Originally posted by BSBingham on ROS Answers with karma: 108 on 2016-03-16

Post score: 3

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Well, what should work is the following:

  • have your robot.launch as it is

  • a robot_ns.launch with the following in it:

      <arg name="my_ns"/>
      <group ns="$(arg my_ns)">
            <include file="$(find mypack)/launch/robot.launch">
              <arg name="namespace" value="$(arg my_ns)" /> 
          </include>
      </group>
    
  • and then, in the top-level launch file, do the following:

      <include file="$(find mypack)/launch/robot_ns.launch">
          <arg name="my_ns" value="r1" /> 
      </include>
    
      <include file="$(find mypack)/launch/robot_ns.launch">
          <arg name="my_ns" value="r2" /> 
      </include>
    

You then don't reassign arguments (which you actually cannot) and you only have to write the namespaces out once.

I guess you could also have this in just one launch file, if your robot.launch could handle an empty namespace argument with the group tags correctly.


Originally posted by mgruhler with karma: 12390 on 2016-03-16

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.