rclcpp icon indicating copy to clipboard operation
rclcpp copied to clipboard

[Draft]Add structured parameter support

Open Rahul-K-A opened this issue 4 months ago • 6 comments

Description

Adds additional API that allows the user to access structured YAML parameters as a YAML::Node (part of yaml-cpp in rclcpp. Original GSOC proposal can be found here Essentially, given a parameter YAML file such as

<node>:
  ros__parameters:
    passenger_size:
      min:
        x: 0.6
        y: 0.4
        z: 0.17
      max:
        x: 0.850
        y: 0.65
        z: 0.47

In the code, the user can declare a structured yaml parameter as

this->declare_parameter("passenger_size", YAML::Node(""));

And get access to all the elements under passenger_size as

YAML::Node passenger_size = this->get_parameter("passenger_size").as_yaml();

They can then access individual fields using the standard dict() syntax

double max_x = passenger_size['max']['x'];
double_min_x = passenger_size['min']['x'];

Users can also now set yaml parameters through the ros2 CLI. The syntax is very similar to the one already used for setting messages. For example:

ros2 param set <node> passenger_size "{min: {x : 0.1, y: 0.2, z: 0.3}, max: [1, 2, "hello"] }"

will change passenger size as

min:
  x: 0.1
  y: 0.2
  z: 0.3
max:
  - 1
  - 2
  - hello

Fixes # (issue)

Is this user-facing behavior change?

Yes, it adds an additional parameter type that they can use. None of the existing parameter types are affected. Support for existing namespaced parameters is not affected. If required users will still be able to access individual namespaced parameters such as passenger_size.min.x, passenger_size.max.x, etc.

Did you use Generative AI?

No.

Additional Information

  1. Companion rclpy PR: https://github.com/ros2/rclpy/pull/1494
  2. Companion rcl PR: https://github.com/ros2/rcl/pull/1254
  3. Compantion rcl_interfaces PR: https://github.com/ros2/rcl_interfaces/pull/183

Rahul-K-A avatar Aug 30 '25 13:08 Rahul-K-A