ros2 / ros2/rclcpp

Function template version of declare_parameter does not work with uint32_t and uint64_t

Open
#1,743 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug report

Required Info:

  • Operating System:
    • Linux Mint 20.1 (based on Ubuntu 20.04)
  • Installation type:
    • ROS 2 Galactic Geochelone Debian packages for Ubuntu Focal
  • Version or commit hash:
    • Latest Galactic Geochelone
  • DDS implementation:
    • default one shipped with the Debian package -> Cyclone DDS
  • Client library (if applicable):
    • rclcpp
Steps to reproduce issue

The minimal (non)working example is based on the tutorial for Using parameters in a class (C++):

#include <rclcpp/rclcpp.hpp>
#include <chrono>
#include <string>
#include <functional>

using namespace std::chrono_literals;

class ParametersClass: public rclcpp::Node
{
  public:
    ParametersClass()
      : Node("parameter_node")
    {
      this->declare_parameter<int8_t>("this_int_works1", 1);
      this->declare_parameter<int16_t>("this_int_works2", 1);
      this->declare_parameter<int32_t>("this_int_works3", 1);
      this->declare_parameter<int64_t>("this_int_works4", 1);

      this->declare_parameter<uint8_t>("this_uint_works1", 1);
      this->declare_parameter<uint16_t>("this_uint_works1", 1);
      this->declare_parameter<uint32_t>("this_uint_does_not_work1", 1);
      this->declare_parameter<uint64_t>("this_uint_does_not_work2", 1);
    }
};

int main(int argc, char** argv)
{
  rclcpp::init(argc, argv);
  rclcpp::spin(std::make_shared<ParametersClass>());
  rclcpp::shutdown();
  return 0;
}
cmake_minimum_required(VERSION 3.8)
project(cpp_parameters)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)

add_executable(parameter_node src/cpp_parameters_node.cpp)
ament_target_dependencies(parameter_node rclcpp)

install(TARGETS
  parameter_node
  DESTINATION lib/${PROJECT_NAME}
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # uncomment the line when a copyright and license is not present in all source files
  #set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # uncomment the line when this package is not in a git repo
  #set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
Expected behavior

I'd expect that all of the above version of declare_parameter would work.

Actual behavior

All versions except the ones for uint32_t and uint64_t are working. It says call of overloaded ‘ParameterValue(const unsigned int&)’ is ambiguous:

In file included from /opt/ros/galactic/include/rclcpp/node.hpp:1315,
                 from /opt/ros/galactic/include/rclcpp/executors/single_threaded_executor.hpp:28,
                 from /opt/ros/galactic/include/rclcpp/executors.hpp:22,
                 from /opt/ros/galactic/include/rclcpp/rclcpp.hpp:156,
                 from /<path>/param_test/cpp_parameters/src/cpp_parameters_node.cpp:1:
/opt/ros/galactic/include/rclcpp/node_impl.hpp: In instantiation of ‘auto rclcpp::Node::declare_parameter(const string&, const ParameterT&, const ParameterDescriptor&, bool) [with ParameterT = unsigned int; std::string = std::__cxx11::basic_string<char>; rcl_interfaces::msg::ParameterDescriptor = rcl_interfaces::msg::ParameterDescriptor_<std::allocator<void> >]’:
/<path>/param_test/cpp_parameters/src/cpp_parameters_node.cpp:21:70:   required from here
/opt/ros/galactic/include/rclcpp/node_impl.hpp:205:15: error: call of overloaded ‘ParameterValue(const unsigned int&)’ is ambiguous
  205 |       rclcpp::ParameterValue(default_value),
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /opt/ros/galactic/include/rclcpp/parameter.hpp:26,
                 from /opt/ros/galactic/include/rclcpp/node_interfaces/node_parameters_interface.hpp:28,
                 from /opt/ros/galactic/include/rclcpp/node.hpp:54,
                 from /opt/ros/galactic/include/rclcpp/executors/single_threaded_executor.hpp:28,
                 from /opt/ros/galactic/include/rclcpp/executors.hpp:22,
                 from /opt/ros/galactic/include/rclcpp/rclcpp.hpp:156,
                 from /<path>/param_test/cpp_parameters/src/cpp_parameters_node.cpp:1:
/opt/ros/galactic/include/rclcpp/parameter_value.hpp:94:12: note: candidate: ‘rclcpp::ParameterValue::ParameterValue(double)’
   94 |   explicit ParameterValue(const double double_value);
      |            ^~~~~~~~~~~~~~
/opt/ros/galactic/include/rclcpp/parameter_value.hpp:91:12: note: candidate: ‘rclcpp::ParameterValue::ParameterValue(float)’
   91 |   explicit ParameterValue(const float double_value);
      |            ^~~~~~~~~~~~~~
/opt/ros/galactic/include/rclcpp/parameter_value.hpp:88:12: note: candidate: ‘rclcpp::ParameterValue::ParameterValue(int64_t)’
   88 |   explicit ParameterValue(const int64_t int_value);
      |            ^~~~~~~~~~~~~~
/opt/ros/galactic/include/rclcpp/parameter_value.hpp:85:12: note: candidate: ‘rclcpp::ParameterValue::ParameterValue(int)’
   85 |   explicit ParameterValue(const int int_value);
      |            ^~~~~~~~~~~~~~
/opt/ros/galactic/include/rclcpp/parameter_value.hpp:82:12: note: candidate: ‘rclcpp::ParameterValue::ParameterValue(bool)’
   82 |   explicit ParameterValue(const bool bool_value);
      |            ^~~~~~~~~~~~~~
/opt/ros/galactic/include/rclcpp/parameter_value.hpp:71:7: note: candidate: ‘rclcpp::ParameterValue::ParameterValue(const rclcpp::ParameterValue&)’
   71 | class ParameterValue
      |       ^~~~~~~~~~~~~~
/opt/ros/galactic/include/rclcpp/parameter_value.hpp:71:7: note: candidate: ‘rclcpp::ParameterValue::ParameterValue(rclcpp::ParameterValue&&)’
Additional information

The same occurs with a rclcpp_lifecycle::LifecycleNode.
It might be useful to test all template variants through the unit tests. It seems only std::string and int is tested.

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.

Research direction

Start in rclcpp/node_impl.hpp at the template declare_parameter call that constructs rclcpp::ParameterValue, then inspect rclcpp/parameter_value.hpp and its overloads. Add unit-test coverage for the uint32_t and uint64_t template variants, and verify that the example compiles and all parameter type tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
robotics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.