ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

ROS2 - Galactic: undeclare_parameter raises an exception

asked 2022-02-07 07:58:03 -0500

doronhi gravatar image

In ROS2-Galactic, the following lines:

rcl_interfaces::msg::ParameterDescriptor desc;  
declare_parameter("aa", 5, desc);

raise the following exception: parameter 'aa' has invalid type: cannot undeclare an statically typed parameter

The following code fixes that:

rcl_interfaces::msg::ParameterDescriptor desc;
declare_parameter("aa", 5, desc);

Is this a result of PR#1522:Enforce static parameter types?

I was under the impression that the idea behind the PR was to prevent an unintentional change of the parameter's type, not to prevent its destruction. Is the way I came up with in my example the proper way to declare parameters which I intend to undeclare later on in the program?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-02-07 17:41:36 -0500

osilva gravatar image

updated 2022-02-07 17:43:36 -0500

HI @doronhi:

I believe the error message is as intended but I see your point:

If you look at the source code, this is when the condition is met:

  // Collect parameters who will have had their type changed to
  // rclcpp::PARAMETER_NOT_SET so they can later be implicitly undeclared.
  std::vector<const rclcpp::Parameter *> parameters_to_be_undeclared;
  for (const auto & parameter : *parameters_to_be_set) {
    if (rclcpp::PARAMETER_NOT_SET == parameter.get_type()) {
      auto it = parameters_.find(parameter.get_name());
      if (it != parameters_.end() && rclcpp::PARAMETER_NOT_SET != it->second.value.get_type()) {
        if (!it->second.descriptor.dynamic_typing) {
          result.reason = "cannot undeclare an statically typed parameter";
          result.successful = false;
          return result;

Can't comment about the PR, but you can find the latest on ROS2 documentation:

edit flag offensive delete link more

Question Tools



Asked: 2022-02-07 07:58:03 -0500

Seen: 278 times

Last updated: Feb 07 '22