How to set up meta launch file in ROS2? (the proper way and with namespaces)
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