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

[Ros2] load a .yaml file in cpp program

asked 2019-01-28 02:56:38 -0600

rohit_agrawal1 gravatar image

updated 2019-01-28 03:08:00 -0600

gvdhoorn gravatar image

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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-07-19 14:28:27 -0600

batty gravatar image

This git issue addresses this feature.

There's no direct solution but you can use the rcl parser and map function to read the yaml in and reset the parameters. For an example code the ZED2 ROS2 node uses this method. See the file zed-ros2-wrapper/zed_wrapper/src/zed_wrapper_container.cpp. I haven't fully gone through that code, but they definitely use the rcl parser to read in parameters from a yaml programatically.

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2019-01-28 02:56:38 -0600

Seen: 4,334 times

Last updated: Jan 28 '19