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

Confusion regarding 'arg' heirarchy in launch files

asked 2020-11-15 15:13:03 -0500

updated 2020-11-15 17:56:34 -0500

I have a launch file named launch_one.launch. It looks like this -

<?xml version="1.0" encoding="UTF-8"?>


    <include file="$(find husky_description)/launch/description.launch" >
        <arg name="laser_enabled" default="$(optenv laser_enabled 1)"/>
        <arg name="realsense_enabled" default="$(optenv realsense_enabled)"/>
        <arg name="urdf_extras" default="$(optenv urdf_extras)"/>

    <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" />  


The description.launch file look like this -


  <arg name="robot_namespace" default="/"/>
  <arg name="laser_enabled" default="$(optenv HUSKY_LMS1XX_ENABLED false)"/>
  <arg name="realsense_enabled" default="$(optenv HUSKY_REALSENSE_ENABLED false)"/>
  <arg name="urdf_extras" default="$(optenv HUSKY_URDF_EXTRAS)"/>

  <param name="robot_description" command="$(find xacro)/xacro '$(find husky_description)/urdf/husky.urdf.xacro'
    robot_namespace:=$(arg robot_namespace)
    laser_enabled:=$(arg laser_enabled)
    realsense_enabled:=$(arg realsense_enabled)
    urdf_extras:=$(arg urdf_extras)
    " />


Assumption - There are no environment variables named laser_enabled and HUSKY_LMS1XX_ENABLED in my system.

I run roslaunch launch_one.launch in a new terminal window. I have 2 queries -

  • Which of the two launch files (launch_one.launch or description.launch) would dictate the final value of the arg laser_enabled in the shell environment? Would it be equal to 1 (as dictated by launch_one.launch) or would it be equal to 0 (as dictated by description.launch) ?

  • How can I check the value of the arg laser_enabled through the terminal? I know that I can do that by running the command printenv. However, I can't take that route because the terminal window is already occupied by the currently running roslaunch file. I tried to open a new tab in the same terminal window and ran the command printenv. It didn't return any variable named laser_enabled.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-11-17 10:02:57 -0500

JackB gravatar image

If I understand everything correctly:

1) The value of the args in launch_one.launch will be passed to description.launch and replace the default values there. So laser_enabled should be equal to 1 (assuming optenv doesn't find anything)

2) If laser_enabled is really an existing environmental variable (that isn't specifically set in the terminal you launch in) then you should be able to find it using printenv in a new terminal. If it isn't there, then you may want to check if it really exists at all. Also it is good practice (well idk if its good, but it is at least standard) to name environmental variables in all caps. So your line should be:

<arg name="laser_enabled" default="$(optenv LASER_ENABLED 1)"/>

This makes it more clear what is going on. To answer your question "How can I check the value of the arg laser_enabled through the terminal?" -- because you are loading it as a ROS parameter in description.launch, in another terminal run rosparam get laser_enabled it should return you the value.

edit flag offensive delete link more

Question Tools



Asked: 2020-11-15 15:13:03 -0500

Seen: 234 times

Last updated: Nov 17 '20