Skip to content

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

@matemat13

Description

@matemat13

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...

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions