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

Revision history [back]

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