0
$\begingroup$

Rosanswers logo

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 = changed_parameter.name;
      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?


Originally posted by madmax on ROS Answers with karma: 496 on 2019-08-13

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.

https://github.com/ros2/rclcpp/issues/807 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) {
                RCLCPP_WARN(this->get_logger(),
                  "Trying to set parameter '%s' with wrong type",
                  parameter.get_name().c_str()
                );
                result.successful = false;
                result.reason = "parameter \'"+parameter.get_name()+"\' must be an integer";

Here you find a full working example https://github.com/alsora/ros2-code-examples/blob/master/simple_parameter/src/simple_parameter_server_node.cpp


Originally posted by alsora with karma: 1322 on 2019-08-13

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.