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

roslaunch - namespace substitution within group tags

asked 2016-03-16 00:13:14 -0600

BSBingham gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-03-16 01:54:36 -0600

mgruhler gravatar image

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.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-03-16 00:13:14 -0600

Seen: 12,244 times

Last updated: Mar 16 '16