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

[ROS2] I can publish a parameter with wrong type and get no exception

asked 2019-08-13 01:56:42 -0500

madmax gravatar image

Hi guys,

is this expected behavior, that when I publish a parameter with a wrong datatype, the result is always true?

ros2 param set /test/my_double_value 1

Returns success although value is written als int into the parameter.

And inside the test node where the parameter is declared, there is also no exception:

declare_parameter( frequencyParamName, rclcpp::ParameterValue( 20.0 ));  

for ( auto& changed_parameter : event->changed_parameters )
      auto paramName =;
      if ( paramName == frequencyParamName )
         updateFrequencyParam( changed_parameter.value.double_value );

Do we really need to check for correct type by ourselves or are we handling parameters wrong?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-08-13 09:24:10 -0500

alsora gravatar image

Yes, at the moment that is the expected behavior. If you want to avoid the type of the parameters to be changed, then you have to register a validation callback to do so. This is a discussion that I started to think about how to facilitate the validation process in some common cases as the one that you mentioned.

This is what you can do in the validation callback to check for the type. Note that it has to be done for all parameters

if (parameter.get_name().compare("my_parameter") == 0) {
              if (rclcpp::ParameterType::PARAMETER_INTEGER != parameter_type) {
                  "Trying to set parameter '%s' with wrong type",
                result.successful = false;
                result.reason = "parameter \'"+parameter.get_name()+"\' must be an integer";

Here you find a full working example

edit flag offensive delete link more

Question Tools



Asked: 2019-08-13 01:56:42 -0500

Seen: 897 times

Last updated: Aug 13 '19