ROS2 - Galactic: undeclare_parameter raises an exception
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?
Asked by doronhi on 2022-02-07 08:58:03 UTC
Answers
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/master/rclcpp/src/rclcpp/node_interfaces/node_parameters.cpp
// 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(¶meter);
}
}
}
Can't comment about the PR, but you can find the latest on ROS2 documentation: https://docs.ros.org/en/rolling/Releases/Release-Dashing-Diademata.html#declaring-parameters
Asked by osilva on 2022-02-07 18:41:36 UTC
Comments