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

ROS2 - Galactic: undeclare_parameter raises an exception

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

doronhi gravatar image

In ROS2-Galactic, the following lines:

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

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;
desc.dynamic_typing=true;
declare_parameter("aa", 5, desc);
undeclare_parameter("aa");

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
0

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

osilva gravatar image

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

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: https://github.com/ros2/rclcpp/blob/m...

  // 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;
        }
        parameters_to_be_undeclared.push_back(&parameter);
      }
    }
  }

Can't comment about the PR, but you can find the latest on ROS2 documentation: https://docs.ros.org/en/rolling/Relea...

edit flag offensive delete link more

Question Tools

2 followers

Stats

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

Seen: 368 times

Last updated: Feb 07 '22