Skip to content

Conversation

Rahul-K-A
Copy link

@Rahul-K-A Rahul-K-A commented Aug 30, 2025

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: [Draft]Add structured parameter support rclpy#1494
  2. Companion rcl PR: [Draft]Add structured parameter support rcl#1254
  3. Compantion rcl_interfaces PR: Add structured parameter support  rcl_interfaces#183

@Rahul-K-A
Copy link
Author

Tagging this as a draft, because Im yet to add in tests/ apply linter. Once done,will remove the draft tag. Maintainers are welcome to start reviewing it in the meantime

@Rahul-K-A Rahul-K-A changed the title Add structured parameter support [Draft]Add structured parameter support Aug 30, 2025
@Rahul-K-A
Copy link
Author

Tagging this as a draft, because Im yet to add in tests/ apply linter. Once done,will remove the draft tag. Maintainers are welcome to start reviewing it in the meantime

@alsora
Copy link
Collaborator

alsora commented Sep 6, 2025

CI for all the PRs involved

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

Copy link
Contributor

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uncrustify is failing. You might need to run

ament_uncrustify --reformat <filenames or directory>

Comment on lines +165 to +167
as_yaml() const;


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
as_yaml() const;
as_yaml() const;

Comment on lines 127 to +130
explicit ParameterValue(const std::vector<std::string> & string_array_value);


/// Generate a parameter value with type PARAMETER_YAML
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
explicit ParameterValue(const std::vector<std::string> & string_array_value);
/// Generate a parameter value with type PARAMETER_YAML
explicit ParameterValue(const std::vector<std::string> & string_array_value);
/// Generate a parameter value with type PARAMETER_YAML


template<ParameterType type>
constexpr
typename std::enable_if<type == ParameterType::PARAMETER_YAML, const YAML::Node>::type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include <type_traits>

<package format="2">
<name>rclcpp</name>
<version>30.1.0</version>
<version>30.0.0</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't change this number manually. Restore

Comment on lines 444 to +446
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

#include <string>
#include <utility>
#include <vector>
#include "yaml-cpp/yaml.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move above <rcl_yaml_param_parser/parser.h> and use <>

Comment on lines +471 to +474
}


RCLCPP_LOCAL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
RCLCPP_LOCAL
}
RCLCPP_LOCAL


RCLCPP_LOCAL
/// Pulled from Question 78243576 from Stack Overflow
void __traverse_node_and_change_value(YAML::Node & root, const std::vector<std::string>& path, rclcpp::ParameterValue value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lines < 100 characters

@asherikov
Copy link

hi, exposing third party library API (yaml-cpp) as a part of ROS api is not a good idea.

@Rahul-K-A
Copy link
Author

Rahul-K-A commented Sep 15, 2025

Hi @asherikov , yaml-cpp is used by ROS2 on all platforms, as per my knowledge, since it's a dependency of rclcpp itself (yaml_cpp_vendor is just a wrapper). In that sense I do not consider it foreign to the ROS ecoyststem

@asherikov
Copy link

API dependency has more implications, e.g., a change in yaml-cpp API would imply a change in ROS2 public API affecting all user code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants