You're reading the documentation for a version of ROS 2 that has reached its EOL (end-of-life), and is no longer officially supported. If you want up-to-date information, please have a look at Galactic.
Passing ROS arguments to nodes via the command-line
All ROS nodes take a set of arguments that allow various properties to be reconfigured.
Examples include configuring the name/namespace of the node, topic/service names used, and parameters on the node.
All ROS-specific arguments have to be specified after a
ros2 run my_package node_executable ...
For more details, see this design doc.
Remapping rules are specified directly using
<old name>:=<new name>,
__node:=<new node name>,
__ns:=<new node namespace>.
Note that these remappings are “static” remappings, in that they apply for the lifetime of the node. “Dynamic” remapping of names after nodes have been started is not yet supported.
See this design doc for more details on remapping arguments (not all functionality is available yet).
The following invocation will cause the
talker node to be started under the node name
my_talker, publishing on the topic named
my_topic instead of the default of
The namespace, which must start with a forward slash, is set to
/demo, which means that topics are created in that namespace (
/demo/my_topic), as opposed to globally (
ros2 run demo_nodes_cpp talker __ns:=/demo __node:=my_talker chatter:=my_topic
Passing remapping arguments to specific nodes
If multiple nodes are being run within a single process (e.g. using Composition), remapping arguments can be passed to a specific node using its name as a prefix. For example, the following will pass the remapping arguments to the specified nodes:
ros2 run composition manual_composition talker:__node:=my_talker listener:__node:=my_listener
The following example will both change the node name and remap a topic (node and namespace changes are always applied before topic remapping):
ros2 run composition manual_composition talker:__node:=my_talker my_talker:chatter:=my_topic listener:__node:=my_listener my_listener:chatter:=my_topic
Setting parameters directly from the command line
Setting parameters directly in the command line is not supported in Dashing.
Setting parameters from YAML files
Parameters can be set from the command-line in the form of yaml files.
See here for examples of the yaml file syntax.
As an example, save the following as
parameter_blackboard: ros__parameters: some_int: 42 a_string: "Hello world" some_lists: some_integers: [1, 2, 3, 4] some_doubles : [3.14, 2.718]
Then either declare the parameters within your node with
declare_parameters (see documentation for function signatures), or set the node to automatically declare parameters if they were passed in via a command line override.
Then run the following:
ros2 run demo_nodes_cpp parameter_blackboard __params:=demo_params.yaml
Other nodes will be able to retrieve the parameter values, e.g.:
$ ros2 param list parameter_blackboard a_string some_int some_lists.some_doubles some_lists.some_integers