Skip to content

rclcpp::Node::get_parameter overloads undocumented inconsistent behavior #2795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
matemat13 opened this issue Apr 7, 2025 · 1 comment · Fixed by #2822
Closed

rclcpp::Node::get_parameter overloads undocumented inconsistent behavior #2795

matemat13 opened this issue Apr 7, 2025 · 1 comment · Fixed by #2822
Assignees
Labels
bug Something isn't working

Comments

@matemat13
Copy link

Operating System:

Ubuntu 24.04

ROS version or commit hash:

jazzy (from apt)

RMW implementation (if applicable):

No response

RMW Configuration (if applicable):

No response

Client library (if applicable):

rclcpp

'ros2 doctor --report' output

ros2 doc --report
/opt/ros/jazzy/lib/python3.12/site-packages/ros2doctor/api/__init__.py: 162: UserWarning: Fail to call PackageReport class functions.

   NETWORK CONFIGURATION
inet         : 127.0.0.1
inet4        : ['127.0.0.1']
inet6        : ['::1']
netmask      : 255.0.0.0
device       : lo
flags        : 73<RUNNING,LOOPBACK,UP>
mtu          : 65536
inet         : 192.168.1.109
inet4        : ['192.168.1.109']
ether        : d8:43:ae:0f:cd:73
inet6        : ['fe80::da43:aeff:fe0f:cd73%enp8s0']
netmask      : 255.255.255.0
device       : enp8s0
flags        : 4163<RUNNING,BROADCAST,MULTICAST,UP>
mtu          : 1500
broadcast    : 192.168.1.255
inet         : 192.168.1.143
inet4        : ['192.168.1.143']
ether        : 14:ac:60:26:e7:37
inet6        : ['fe80::cd82:9627:3deb:edf0%wlp15s0']
netmask      : 255.255.255.0
device       : wlp15s0
flags        : 4163<RUNNING,BROADCAST,MULTICAST,UP>
mtu          : 1500
broadcast    : 192.168.1.255

   PLATFORM INFORMATION
system           : Linux
platform info    : Linux-6.11.0-19-generic-x86_64-with-glibc2.39
release          : 6.11.0-19-generic
processor        : x86_64

   QOS COMPATIBILITY LIST
compatibility status    : No publisher/subscriber pairs found

   RMW MIDDLEWARE
middleware name    : rmw_fastrtps_cpp

   ROS 2 INFORMATION
distribution name      : jazzy
distribution type      : ros2
distribution status    : active
release platforms      : {'debian': ['bookworm'], 'rhel': ['9'], 'ubuntu': ['noble']}

   TOPIC LIST
topic               : none
publisher count     : 0
subscriber count    : 0

Steps to reproduce issue

Create a subnode with a subnamespace, use it declare and set a parameter, and then try to get the parameter using the different overloads of the get_parameter() method.
Example:

  auto subnode = node->create_sub_node("subnode");
  subnode->declare_parameter("param_name", 5);

  std::cout << subnode->get_parameter("param_name").get_value<int>() << std::endl;

  rclcpp::Parameter param;
  subnode->get_parameter("param_name", param);
  std::cout << param.get_value<int>() << std::endl;

  int param_int;
  subnode->get_parameter("param_name", param_int);
  std::cout << param_int << std::endl;

  std::cout << subnode->get_parameter_or("param_name", 666) << std::endl;

  subnode->get_parameter_or("param_name", param_int, 666);
  std::cout << param_int << std::endl;

Expected output:

5
5
5
5
5

Actual output:

5
5
1
666
666

:'(

Expected behavior

All the overrides of the method get_parameter() and get_parameter_or() should behave consistently, and not sometimes try to prepend the subnode namespace and sometimes not.

Actual behavior

The override

template <typename ParameterT>
bool rclcpp::Node::get_parameter (const std::string& name, ParameterT& parameter) const

and both variants of get_parameter_or() call the extend_name_with_sub_namespace() function that modifies the name of the parameter. The rest of the methods (including set_parameter() and declare_parameter()) do not. This behavior is not documented, it is inconsistent, and it cost me a lot of debugging time.

Additional information

I think the root of the problem is that the implementation of subnodes is only half finished, leading to bugs and unexpected behavior like this. It's as if somebody simply committed and pushed his WIP code when in the middle of implementing subnodes. Subnode parameters in ROS2 are almost never namespaced, which makes it hard to solve conflicting parameter names.

The short-term solution is to remove the call to extend_name_with_sub_namespace() (which btw. seems to be broken or at the least not behaving as in ROS1 w.r.t. the /, . and ~ special symbols).

I think the correct solution however would be to finish implementing subnodes also for parameters... and finish writing the documentation...

@matemat13 matemat13 added the bug Something isn't working label Apr 7, 2025
@fujitatomoya
Copy link
Collaborator

@matemat13 thanks for posting the issue.

this is obviously bug and inconsistent behavior that confuses user application.

IMO, it should never call extend_name_with_sub_namespace on subordinate node either, because all the parameters belong the node instance, even with subordinate node. on the other hand, all the endponts such as publisher, subscription, service server/client, action server/client should extended with extend_name_with_sub_namespace on the creation. (as far as i check, create_generic_client is missing to call extend_name_with_sub_namespace.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants