0
$\begingroup$

Ubuntu 22.04, ROS 2 Humble

Hi, I am following the official tutorial to pass arguments to a cpp node via a python launch file

https://docs.ros.org/en/humble/How-To-Guides/Launch-file-different-formats.html

My launch file is as follows

import os

# https://docs.ros.org/en/humble/How-To-Guides/Launch-file-different-formats.html
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, LogInfo
from launch.actions import IncludeLaunchDescription
from launch.actions import GroupAction
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from launch.substitutions import TextSubstitution
from launch_ros.actions import Node
from launch_ros.actions import PushRosNamespace

from ament_index_python.packages import get_package_share_directory #* Required to get YAML file


# Define path to package
home_directory = os.path.expanduser("~")
path_to_orbslam3_pck = home_directory + "/" + "ros2_ws/src/orb_slam3_ros2"

# Build global paths
voc_path = os.path.join(path_to_orbslam3_pck, 'orb_slam3/Vocabulary/ORBvoc.txt.bin')
settings_path = os.path.join(path_to_orbslam3_pck, 'orb_slam3/config/Monocular/')

# https://roboticscasual.com/tutorial-ros2-launch-files-all-you-need-to-know/#cmd-line-args-hand-over

def generate_launch_description():
    ld = LaunchDescription()

    # If you want to load some YAML files
    # config_robot1 = os.path.join(
    #     get_package_share_directory('my_launcher'), #* Nothing fancy here, this is how the syntax goes
    #     'config',
    #     'params.yaml'
    # )

    # voc_file_launch_arg = DeclareLaunchArgument(
    #         "voc_file",
    #         default_value=TextSubstitution(text=voc_path),
    #         # description='Path to the Vocabulary file for ORB-SLAM3',
    #     ),
    
    # settings_file_path_launch_arg = DeclareLaunchArgument(
    #         "settings_file_path",
    #         default_value=TextSubstitution(text=settings_path),
    #         #description='Path to the Vocabulary file for ORB-SLAM3',
    #     ),
    
    settings_file_name_launch_arg = DeclareLaunchArgument(
            "settings_file_name",
            default_value=TextSubstitution(text='file_not_set'), # EuRoC, TUM2
            # description='Settings file name i.e. EuoRoC, TUM2 etc',
        ),


    robot0_vslam_node = Node(
        package="orb_slam3_ros2", # Remember, the (,) are very important
        executable="agent0",
        name = "robot0_vslam",
        # # if you have a namespace, use this tutorial to add it https://www.youtube.com/watch?v=wY8MrBGVxYA
        #parameters=[config_robot1] # when using YAML configuration files
        
        #* List with tuples
        parameters=[
                    {"agent_name_arg": 'robot0'}, 
                    #{"voc_file_arg": LaunchConfiguration('voc_file')},
                    #{"settings_file_path_arg": LaunchConfiguration('settings_file_path')},
                    {"settings_file_name_arg": LaunchConfiguration('settings_file_name')}
        ] # When setting individual parameters, set it as a tuple
    )

    # https://answers.ros.org/question/382167/is-it-possible-to-have-a-conditional-in-a-launch-file-using-declarelaunchargument/

    #ld.add_action(voc_file_launch_arg)
    #ld.add_action(settings_file_path_launch_arg)
    ld.add_action(settings_file_name_launch_arg)
    ld.add_action(robot0_vslam_node) # This adds the node to the description

    return ld 

This code builds without any issue. To make the testing simpler, I am only trying to pass one argument to my CPP node to see if it receives it.

However, when I try running this command

ros2 launch my_launcher my_app_launch.py settings_file_name:="TUM2"

I am getting this following error

[ERROR] [launch]: Caught exception in launch (see debug for traceback): 'tuple' object has no attribute 'describe_sub_entities'

Note that, I had tried returning LaunchDescription in the following way

return LaunchDescription([
    launch_args,
    node
])

Both gives the error shown above.

My questions are the following

  1. What is `describe_sub_entities' in context of the above problem?
  2. What changes are required to get the desired behavior?

Thanks @Mechazo11

$\endgroup$

1 Answer 1

2
$\begingroup$

I think the problem is the trailing comma on your launch arg declaration:

settings_file_name_launch_arg = DeclareLaunchArgument(
            "settings_file_name",
            default_value=TextSubstitution(text='file_not_set'), # EuRoC, TUM2
            # description='Settings file name i.e. EuoRoC, TUM2 etc',
        ), #<<< trailing comma here 

Instead of the expected launch object, which would have a .describe_sub_entities() method, you're then passing a one-element tuple to the launch system:

(settings_file_name_launch_arg, )

$\endgroup$
1
  • $\begingroup$ the error went away but the node did not start.Will get back to you once I look into it a bit further. Thank you for explaining the issue with the describe_sub_entities() problem. $\endgroup$ Commented Dec 18, 2023 at 22:55

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.