Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

ROS2 lauch with yaml config parameters example

I would like to pass parameters to a composable node from a yaml config file. I searched on the web I saw that there were multiple bugs. Unfortunately I couldn't find any current example. I would be glad if someone could let me know, where I can find something. I would like to know the correct format in the yaml file and how to load it with "parameters=[get_package_share_directory('my_package')+"/config/my_config.yaml"]"

ROS2 lauch with yaml config parameters example

I would like to pass parameters to a composable node from a yaml config file. I searched on the web I saw that there were multiple bugs. Unfortunately I couldn't find any current example. example.

I would be glad if someone could let me know, where I can find something. I would like to know know:

  • the correct format in the yaml file and file
  • how to load it with "parameters=[get_package_share_directory('my_package')+"/config/my_config.yaml"]"

    parameters=[get_package_share_directory('my_package')+"/config/my_config.yaml"]

ROS2 lauch with yaml config parameters example

I would like to pass parameters to a composable node from a yaml config file. I searched on the web I saw that there were multiple bugs. Unfortunately I couldn't find any current example.

I would be glad if someone could let me know, where I can find something. I would like to know:

  • the correct format in the yaml file
  • how to load it with parameters=[get_package_share_directory('my_package')+"/config/my_config.yaml"]

Edit: @johnconn: Unfortunately this doesn't work for me. Could it be that the config has to look different when I use a ComposableNode instead of a normal Node?

My launch file is now

import os.path
import launch
from launch_ros.actions import ComposableNodeContainer
from launch_ros.descriptions import ComposableNode
from launch.substitutions import LaunchConfiguration
from ament_index_python import get_package_share_directory


def generate_launch_description():
    """Generate launch description with multiple components."""

    # config the serial number and base frame id of each camera
    d435_base_frame_id = LaunchConfiguration('base_frame_id', default='d435_link')
    d435_serial_no = LaunchConfiguration('serial_no', default='825312073597')

    d435i_base_frame_id = LaunchConfiguration('base_frame_id', default='d435i_link')
    d435i_serial_no = LaunchConfiguration('serial_no', default='845112070204')

    print(get_package_share_directory('safety-field-intrusion-detector-ros')+"/config/d435.yaml")

    container = ComposableNodeContainer(
            node_name='safety_field_intrusion_detection',
            node_namespace='',
            package='rclcpp_components',
            node_executable='component_container',
            composable_node_descriptions=[
                ComposableNode(
                    package='realsense_ros',
                    node_plugin='realsense::RealSenseNodeFactory',
                    node_name='d435',
                    #node_name='realsense',
                    node_namespace='realsense',
                    parameters=[
                        #get_package_share_directory('safety-field-intrusion-detector-ros')+"/config/d435.yaml"
                        os.path.join(get_package_share_directory('safety-field-intrusion-detector-ros'), 'config', 'd435.yaml')
                        #{'serial_no': d435_serial_no,
                        # 'base_frame_id': d435_base_frame_id}
                    ]
                ),
                ComposableNode(
                    package='realsense_ros',
                    node_plugin='realsense::RealSenseNodeFactory',
                    node_name='d435i',
                    #node_name='realsense',
                    node_namespace='realsense',
                    parameters=[
                        #get_package_share_directory('safety-field-intrusion-detector-ros')+"/config/d435i.yaml"
                        os.path.join(get_package_share_directory('safety-field-intrusion-detector-ros'), 'config', 'd435i.yaml')
                        #{'serial_no': d435i_serial_no,
                        # 'base_frame_id': d435i_base_frame_id}
                    ]
                ),
                ComposableNode(
                    package='safety-field-intrusion-detector-ros',
                    node_plugin='SafetyFieldIntrusionDetectorBaseNode',
                    node_name='safety_field_intrusion_detector',
                    parameters=[
                        get_package_share_directory('safety-field-intrusion-detector-ros')+"/config/params.yaml"
                ])
            ],
            output='screen',
    )

    return launch.LaunchDescription([container])

and my config files

realsense/d435:
  ros__parameters:
    serial_no: 825312073597 # d435
    base_frame_id: d435_link
    align_depth: true
    enable_pointcloud: false
    dense_pointcloud: false
    color0:
      enabled: true
      resolution: [640,480]
      fps: 30
    depth0:
      enabled: true
      resolution: [640,480]
      fps: 30
    infra1:
      enabled: false
      resolution: [640,480]
      fps: 30
    infra2:
      enabled: false
      resolution: [640,480]
      fps: 30

and

realsense/d435i:
  ros__parameters:
    serial_no: 845112070204 # d435i
    base_frame_id: d435i_link
    align_depth: true
    enable_pointcloud: false
    dense_pointcloud: false
    color0:
      enabled: true
      resolution: [640,480]
      fps: 30
    depth0:
      enabled: true
      resolution: [640,480]
      fps: 30
    infra1:
      enabled: false
      resolution: [640,480]
      fps: 30
    infra2:
      enabled: false
      resolution: [640,480]
      fps: 30
    accel0:
      enabled: true
    gyro0:
      enabled: true

when I launch it, I get the following errors:

ros2 launch safety-field-intrusion-detector-ros safety_field_detector.launch.py
[INFO] [launch]: All log files can be found below /home/mtr/.ros/log/2020-04-06-08-25-32-985607-UP2-board-6505
[INFO] [launch]: Default logging verbosity is set to INFO
/home/mtr/ros/safety_field_detector_ws/install/safety-field-intrusion-detector-ros/share/safety-field-intrusion-detector-ros/config/d435.yaml
[INFO] [component_container-1]: process started with pid [6516]
[ERROR] [launch_ros.actions.load_composable_nodes]: Failed to load node 'd435' of type 'realsense::RealSenseNodeFactory' in container '/safety_field_intrusion_detection': Component constructor threw an exception
[INFO] [launch_ros.actions.load_composable_nodes]: Loaded node '' in container '/safety_field_intrusion_detection'
[component_container-1] [WARN] [rcl]: Namespace not remapped to a fully qualified name (found: realsense)
[component_container-1] [ERROR] [safety_field_intrusion_detection]: Component constructor threw an exception
[component_container-1] [WARN] [rcl]: Namespace not remapped to a fully qualified name (found: realsense)
[ERROR] [launch_ros.actions.load_composable_nodes]: Failed to load node 'd435i' of type 'realsense::RealSenseNodeFactory' in container '/safety_field_intrusion_detection': Component constructor threw an exception
[component_container-1] [ERROR] [safety_field_intrusion_detection]: Component constructor threw an exception
[INFO] [launch_ros.actions.load_composable_nodes]: Loaded node '' in container '/safety_field_intrusion_detection'
[component_container-1] [WARN] [rcl.logging_rosout]: Publisher already registered for provided node name. If this is due to multiple nodes with the same name then all logs for that logger name will go out over the existing publisher. As soon as any node with that name is destructed it will unregister the publisher, preventing any further logs for that name from being published on the rosout topic.
[INFO] [launch_ros.actions.load_composable_nodes]: Loaded node '/safety_field_intrusion_detection' in container '/safety_field_intrusion_detection'