Ask Your Question
0

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
1

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
  foo
  use_sim_time

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(
        [
            launch_ros.actions.Node(
                package='demo_nodes_cpp', node_executable='talker',
                node_name='talker',
                parameters=[{'use_sim_time': use_sim_time}]),
            launch_ros.actions.Node(
                package='demo_nodes_cpp', node_executable='listener',
                node_name='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 example_launch.py use_sim_time:=True
...
$ ros2 param get /listener use_sim_time
Boolean value is: True
edit flag offensive delete link more

Comments

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 imageahtsan ( 2019-06-20 14:49:28 -0500 )edit
1

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

ahtsan gravatar imageahtsan ( 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 imageahtsan ( 2019-06-20 17:16:22 -0500 )edit
2

It doesn't seem to be possible at the moment. But it is listed on the feature list for the next ROS 2 distribution: https://github.com/ros2/ros2/issues/734

passing key-value parameters on CLI

marguedas gravatar imagemarguedas ( 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);

  this->declare_parameter("foo");

  auto sub = parameters_client->on_parameter_event(
    [this](const rcl_interfaces::msg::ParameterEvent::SharedPtr event) -> void
    {
      for (auto & changed_param : event->changed_parameters)
        if (changed_param.name == "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 imageahtsan ( 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 imageahtsan ( 2019-06-20 19:45:24 -0500 )edit

Question Tools

1 follower

Stats

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

Seen: 93 times

Last updated: Jun 20