[ROS2] How do you load a yaml config file to a Composable Node?
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 ...
@Andreas Ziegler: please only post answers when actually answering a question.
ROS Answers is an instance of AskBot, which is similar to Stack Overflow, and works best with a 1-to-1 ratio of answers and questions.
To interact with answerers, post comments under their answers, or edit your own question text.
I've merged your non-answer with your question for you, but please keep it in mind for next time.
@gvdhoorn: Thanks for fixing my mess. My intention was to add another comment as I'm used to from GitHub or StackOverflow rather than answering my question but the only button I found was the "Answer button".
You should have a add a comment button/link under the answer you want to respond to.
I haven't gone beyond the demos for composable nodes yet, I'm not sure if there is a difference.