Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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