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

Revision history [back]

click to hide/show revision 1
initial version

To set a single parameter on all nodes in the same scope of a launch file, you can use the SetParameter action. The parameter will be set on all nodes launched after the SetParameter action, also applying to any included launch files.

For example, to set the ROS parameter use_sim_time for all nodes in a launch file, you can something like

import launch
import launch_ros.actions

def generate_launch_description():
    return launch.LaunchDescription([
        launch_ros.actions.SetParameter(name='use_sim_time', value=True),
        # 'use_sim_time' will be set on all nodes following the line above
    ])

This is also supported in front-end launch files, for example XML:

<launch>
  <set_parameter name="use_sim_time" value="true" />
  <!-- 'use_sim_time' will be set on all nodes following the line above -->
</launch>

Note, you can use a launch "group" to scope the SetParameter action. In the following example, the talker node does not have the use_sim_time parameter set, but the listener node does:

<launch>
  <group>
    <set_parameter name="use_sim_time" value="true" />
    <node name="listener" pkg="demo_nodes_cpp" exec="listener" output="screen" />
  </group>
  <node name="talker" pkg="demo_nodes_cpp" exec="talker" output="screen" />
</launch>

This can be done as of ROS Foxy.

To set a single parameter on all nodes in the same scope of a launch file, you can use the SetParameter action. The parameter will be set on all nodes launched after the SetParameter action, also applying to any included launch files.

For example, to set the ROS parameter use_sim_time for all nodes in a launch file, you can something like

import launch
import launch_ros.actions

def generate_launch_description():
    return launch.LaunchDescription([
        launch_ros.actions.SetParameter(name='use_sim_time', value=True),
        # 'use_sim_time' will be set on all nodes following the line above
    ])

This is also supported in front-end launch files, for example XML:

<launch>
  <set_parameter name="use_sim_time" value="true" />
  <!-- 'use_sim_time' will be set on all nodes following the line above -->
</launch>

Note, you can use a launch "group" to scope the SetParameter action. In the following example, the talker node does not have the use_sim_time parameter set, but the listener node does:

<launch>
  <group>
    <set_parameter name="use_sim_time" value="true" />
    <node name="listener" pkg="demo_nodes_cpp" exec="listener" output="screen" />
  </group>
  <node name="talker" pkg="demo_nodes_cpp" exec="talker" output="screen" />
</launch>

I'll add that it's currently not possible to set parameters from a parameters file in this many, though it would b e interesting to add such a feature.

This can be done as of ROS Foxy.

To set a single parameter on all nodes in the same scope of a launch file, you can use the SetParameter action. The parameter will be set on all nodes launched after the SetParameter action, also applying to any included launch files.

For example, to set the ROS parameter use_sim_time for all nodes in a launch file, you can something like

import launch
import launch_ros.actions

def generate_launch_description():
    return launch.LaunchDescription([
        launch_ros.actions.SetParameter(name='use_sim_time', value=True),
        # 'use_sim_time' will be set on all nodes following the line above
    ])

This is also supported in front-end launch files, for example XML:

<launch>
  <set_parameter name="use_sim_time" value="true" />
  <!-- 'use_sim_time' will be set on all nodes following the line above -->
</launch>

Note, you can use a launch "group" to scope the SetParameter action. In the following example, the talker node does not have the use_sim_time parameter set, but the listener node does:

<launch>
  <group>
    <set_parameter name="use_sim_time" value="true" />
    <node name="listener" pkg="demo_nodes_cpp" exec="listener" output="screen" />
  </group>
  <node name="talker" pkg="demo_nodes_cpp" exec="talker" output="screen" />
</launch>

I'll add that it's currently not possible to set parameters from a parameters file in this many, a similar way, though it would b e interesting to add such a feature.

This can be done as of ROS Foxy.

To set a single parameter on all nodes in the same scope of a launch file, you can use the SetParameter action. The parameter will be set on all nodes launched after the SetParameter action, also applying to any included launch files.

For example, to set the ROS parameter use_sim_time for all nodes in a launch file, you can something like

import launch
import launch_ros.actions

def generate_launch_description():
    return launch.LaunchDescription([
        launch_ros.actions.SetParameter(name='use_sim_time', value=True),
        # 'use_sim_time' will be set on all nodes following the line above
    ])

This is also supported in front-end launch files, for example XML:

<launch>
  <set_parameter name="use_sim_time" value="true" />
  <!-- 'use_sim_time' will be set on all nodes following the line above -->
</launch>

Note, you can use a launch "group" to scope the SetParameter action. In the following example, the talker node does not have the use_sim_time parameter set, but the listener node does:

<launch>
  <group>
    <set_parameter name="use_sim_time" value="true" />
    <node name="listener" pkg="demo_nodes_cpp" exec="listener" output="screen" />
  </group>
  <node name="talker" pkg="demo_nodes_cpp" exec="talker" output="screen" />
</launch>

I'll add that it's currently not possible to set parameters from a parameters file in a similar way, though it would b e be interesting to add such a feature.