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
For more details, see this design doc.
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 (
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:
The following example will both change the node name and remap a topic (node and namespace changes are always applied before topic remapping):
Setting parameters directly in the command line¶
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:
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