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

ROS2 add_on_set_parameters_callback not triggered for launch parameter

asked 2023-06-28 03:19:18 -0500

holunder gravatar image

I've defined a callback for parameter value change:

MyNode::MyNode() : Node("myNode")
{
  // subscriber, publisher, ....

  // Define callback to update parameter
  parameter_set_callback = this->add_on_set_parameters_callback(std::bind(&MyNode::update_parameter_callback, this, _1));
}

The function update_parameter_callback itself sets the changed parameter values in my application.

rcl_interfaces::msg::SetParametersResult MyNode::update_parameter_callback(const std::vector<rclcpp::Parameter> &parameters)
{

  rcl_interfaces::msg::SetParametersResult res;

  // Update parameter
  res = UpdateParameter_MyCode(parameters);

  return res;
}

This works well when setting parameter during runtime via ros2 param set

When I set a default value in launch file, this callback is not triggered:

<node pkg = "my_pkg" name = "MyNode" exec = "MyNode" >
    <param name="bar" value="201.0"/>
</node>

Is there any chance to re-use existing callback for parameter that are set within launch?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-29 02:48:56 -0500

holunder gravatar image

It seems like changing the order in my code fixed the issue.

When I setadd_on_set_parameters_callback before actually declaring parameter, it ensures that parameter override value is triggering the callback and then populating the value to my function.

edit flag offensive delete link more

Comments

if someone with higher reputation could mark this reply as an answer, the questions could be closed properly.

holunder gravatar image holunder  ( 2023-06-29 02:50:16 -0500 )edit

Question Tools

Stats

Asked: 2023-06-28 03:19:18 -0500

Seen: 125 times

Last updated: Jun 29 '23