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

Does 'ros2 set param' exist? [closed]

asked 2019-06-20 13:17:19 -0500

ahtsan gravatar image

If not, is there a way to declare a global parameter for all nodes?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by ahtsan
close date 2019-07-11 18:38:12.126435

1 Answer

Sort by ยป oldest newest most voted

answered 2019-06-20 14:34:11 -0500

sloretz gravatar image

Parameters are per node in ROS 2. There is no a global parameter server like ROS 1. It is possible to set a param on a node with ros2 param set

$ ros2 run demo_nodes_cpp parameter_blackboard &
$ ros2 param set /parameter_blackboard foo bar
Set parameter successful
$ ros2 param list /parameter_blackboard

If you'd like to set a parameter on all running nodes, you'll need to enumerate them and set the parameter on each one. If you would like to set a parameter on a lot of nodes that you're launching, the parameter should be passed into each launch_ros.actions.Node.

import launch
import launch_ros

def generate_launch_description():
    use_sim_time = launch.substitutions.LaunchConfiguration('use_sim_time', default=False)

    return launch.LaunchDescription(
                package='demo_nodes_cpp', node_executable='talker',
                parameters=[{'use_sim_time': use_sim_time}]),
                package='demo_nodes_cpp', node_executable='listener',
                parameters=[{'use_sim_time': use_sim_time}]),

I used a LaunchConfiguration in this example. You can give it a value on the command line

$ ros2 launch use_sim_time:=True
$ ros2 param get /listener use_sim_time
Boolean value is: True
edit flag offensive delete link more


Perfect. Does ros2 param set /node_name key value trigger the on_parameter_event if a SyncParametersClient is defined inside the node? What I want to achieve is to perform some tasks if a parameter is true in the node.

ahtsan gravatar image ahtsan  ( 2019-06-20 14:49:28 -0500 )edit

I am answering to my own question: Yes, it does.

ahtsan gravatar image ahtsan  ( 2019-06-20 15:07:54 -0500 )edit

We can pass argument to set the parameter value for launch file. Is it possible when we run a standalone node? like ros2 run demo_nodes_cpp parameter_blackboard foo:=true.

ahtsan gravatar image ahtsan  ( 2019-06-20 17:16:22 -0500 )edit

It doesn't seem to be possible at the moment. But it is listed on the feature list for the next ROS 2 distribution:

passing key-value parameters on CLI

marguedas gravatar image marguedas  ( 2019-06-20 18:03:33 -0500 )edit

Can I use the same node for another rclcpp::SyncParametersclient? I have a node named foo_node running and do

void Foo::init()
  auto parameters_client = std::make_shared<rclcpp::SyncParametersClient>(this);


  auto sub = parameters_client->on_parameter_event(
    [this](const rcl_interfaces::msg::ParameterEvent::SharedPtr event) -> void
      for (auto & changed_param : event->changed_parameters)
        if ( == "foo")
          RCLCPP_INFO(this->get_logger(), "Foo is set");

and when I run ros2 set param /foo_node foo true in another process, the callback is not triggered but instead it logs [INFO] [Logger]: Hey.

Any thoughts?

ahtsan gravatar image ahtsan  ( 2019-06-20 19:36:45 -0500 )edit

I am answering my self again: I have to make sure there is at least one reference to sub, otherwise it destroy itself.

ahtsan gravatar image ahtsan  ( 2019-06-20 19:45:24 -0500 )edit

Question Tools

1 follower


Asked: 2019-06-20 13:17:19 -0500

Seen: 1,070 times

Last updated: Jun 20 '19