ros2 / ros2/rclcpp

Priority of the different mechanisms to initialize ROS 2 parameters

Open
#2,408 2 comments 1 reaction 1 assignee View on GitHub

@clalancette is already working on this.

Since Jan 25, 2024.

Dominant language
C++
Stars
805
Forks
564
Avg merge
1d 17h
Merged PRs (30d)
27

Description

Half-way between a bug report and a feature request (i.e. imo the current behavior is not correct, i would be ok with changing it or with providing utilities to live with it).

Currently there are a ton of ways to set ROS 2 parameters at startup.

  • the value can be set via --ros-args command line arguments
  • the value can be set in the yaml file
  • the value can be set using rclcpp::NodeOptions().append_parameter_override() and passed to the node constructor
  • the value can be set when declaring the parameter

IMO these approaches should have the priority as I ordered them.
However, that's not the case and the rclcpp::NodeOptions().parameter_overrides() has the highest priority.
This seems very strange to me.

Consider the following use-case: I have a ROS 2 node, implemented in its own library. This node declares a parameter with a "reasonable default value".
This happens inside the library, the node has no idea in which application it will be used.
Then I have two C++ applications that want to use this node. These may be very different applications and they may want to use a different default value for the parameter, so they set it via rclcpp::NodeOptions.
Lastly, a user who wants to quickly modify a parameter, they may want to use the yaml file, but they can't and they are forced to modify the C++ code and rebuild the application.

Ideas that I discarded:

  • the default value declared in the library may make no sense at all for an application, so the C++ code must be able to indicate a new default. Creating a derived class and overriding the function that declares the parameters seems a lot of work and doesn't scale well with the number of parameters and applications using them.
  • I don't like passing parameters via command line using --ros-args: If you have component nodes, you are going to have a lot of nodes in the same executable and I want to set a parameter only in 1 node.

Possible solutions:

  • change the priority order, and have yaml file take precedence over the rclcpp::NodeOptions
  • add a C++ utility to "override a parameter only if it's not present in the yaml"

Thoughts?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.