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

How to set up meta launch file in ROS2? (the proper way and with namespaces)

asked 2022-07-12 10:48:44 -0500

dave gravatar image

Dear ROS community,

I am working on a project where I want to have a single launch file that starts all sub-modules. I have a launch file for each sub-module already as this makes it easier to test them individually. So I want to have a launch file that calls other launch files instead of executables directly. From what I understand, this is called a meta launch file right?

I already figured out a solution but when I compare it with other projects on GitHub such as Turtlebot 3 or the Hustky on their foxy-devel branch, my solution looks different and I wonder if I am doing it "the proper way"?

My current solution is the following:

from launch_ros.substitutions import FindPackageShare

from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import PathJoinSubstitution, TextSubstitution


def generate_launch_description():

    return LaunchDescription([
        IncludeLaunchDescription(
            PythonLaunchDescriptionSource([
                PathJoinSubstitution([
                    FindPackageShare('leorover_realsense'),
                    'launch',
                    'd455_launch.py'
                ])
            ]),
        ),
        IncludeLaunchDescription(
            PythonLaunchDescriptionSource([
                PathJoinSubstitution([
                    FindPackageShare('leorover_imu_filter'),
                    'launch',
                    'imu_filter.launch.py'
                ])
            ]),
        ),
        IncludeLaunchDescription(
            PythonLaunchDescriptionSource([
                PathJoinSubstitution([
                    FindPackageShare('leorover_rtabmap'),
                    'launch',
                    'realsense_d455.launch.py'
                ])
            ]),
        )
    ])

Also, I would like to know how I can launch all these nodes under the same namespace in ROS2 since I will run the same launch meta launch file on different (identical) robots and they should not have namespace collisions. I could only find solutions with launch files that call directly executable like the following:

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, SetEnvironmentVariable
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node  

def generate_launch_description():
parameters=[{
    'frame_id':'realsense_camera_link',
    'imu_topic':'/rtabmap/imu'
}]

remappings=[
    ('rgb/image', '/realsense_camera/color/image_raw'),
    ('rgb/camera_info', '/realsense_camera/color/camera_info'),
    ('depth/image', '/realsense_camera/depth/image_rect_raw')]

return LaunchDescription([

# Nodes to launch
Node(
    package='my_robot', 
    executable='my_node2', 
    output='screen',
            namespace="my_namespace",
    parameters=parameters,
    remappings=remappings),

Node(
    package='my_robot', 
    executable='my_node2', 
    output='screen',
            namespace="my_namespace",
    parameters=parameters,
    remappings=remappings,
    arguments=['-d']),
])

I could not find an example of how to apply the namespace on the meta launch file and I don't know if my meta launch file is done the proper way like this. Any input on this would be highly appreciated.

With kind regards, Dave vdMeer

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2022-07-13 03:05:23 -0500

dave gravatar image

I think I have a fairly good answer now which I found in the official documentation, a bit hidden in my oppinion.

Here is the link: https://docs.ros.org/en/foxy/Tutorial...

And here is my solution:

import os

from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.actions import GroupAction
from launch_ros.actions import PushRosNamespace

ROBOT_NAMESPACE="leorover"

def generate_launch_description():
    leorover_realsense_node = IncludeLaunchDescription(
        PythonLaunchDescriptionSource([os.path.join(
            get_package_share_directory('leorover_realsense'), 'launch'),
            '/d455_launch.py'])
    )
    leorover_imu_filter_node = IncludeLaunchDescription(
        PythonLaunchDescriptionSource([os.path.join(
            get_package_share_directory('leorover_imu_filter'), 'launch'),
            '/imu_filter.launch.py'])
    )
    leorover_rtabmap_node = IncludeLaunchDescription(
        PythonLaunchDescriptionSource([os.path.join(
            get_package_share_directory('leorover_rtabmap'), 'launch'),
            '/realsense_d455.launch.py'])
    )

    bringup_with_namespace = GroupAction(
        actions=[
            PushRosNamespace(ROBOT_NAMESPACE),
            leorover_realsense_node,
            leorover_imu_filter_node,
            leorover_rtabmap_node
        ]
    )

    return LaunchDescription([
    bringup_with_namespace
    ])

Any comments and tips to further improve it would be appreciated. But with that, I think I answered my own question. Sorry for bothering anyone and I hope this actually helps other people that could not find the solution right away.

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2022-07-12 10:48:44 -0500

Seen: 161 times

Last updated: Jul 13 '22