[Ros2] load a .yaml file in cpp program
In ROS2, Is there a way to load a .yaml file in cpp program to set the parameters into node.
Currentlly (in ROS2) we can load .yaml
file either commandLine i.e. ros2 run pkg_name nodename __params:=:<path>/test.yaml
Or through python launch pkg as below.
yaml file test.yaml
:
nodename:
ros__parameters:
name: aaa
type: bbb
params:
param1: 10.0
param2: xyz
.launch.py
file test.launch.py
:
def generate_launch_description():
parameters_file_dir = pathlib.Path(__file__).resolve().parent
parameters_file_path = parameters_file_dir / 'test.yaml'
os.environ['FILE_PATH'] = str(parameters_file_dir)
test_node = launch_ros.actions.Node(
package='pkg_name', node_executable='file_executable_name', node_name='nodename,
output='screen',
parameters=[
parameters_file_path,
str(parameters_file_path),
[EnvironmentVariable(name='FILE_PATH'), os.sep, 'test.yaml'],
],
)
return LaunchDescription([
test_node,
launch.actions.RegisterEventHandler(
event_handler=launch.event_handlers.OnProcessExit(
target_action=test_node,
on_exit=[launch.actions.EmitEvent(event=launch.events.Shutdown())],
)),
])
I am looking similar way to load .yaml in cpp program to get/set perameters in a particular node?