Robotics StackExchange | Archived questions

Confusion regarding 'arg' heirarchy in launch files

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

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

<launch> 

    <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)"/>
    </include>

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

</launch>

The description.launch file look like this -

<launch>

  <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)
    " />

</launch>

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 -

Asked by skpro19 on 2020-11-15 16:13:03 UTC

Comments

Answers

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.

Asked by JackB on 2020-11-17 11:02:57 UTC

Comments