Passing ROS arguments to nodes via the command-line
通過指令行将ROS參數傳遞給節點
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.
所有ROS節點都采用一組參數,可以重新配置各種屬性。示例包括配置節點的名稱/命名空間,使用的主題/服務名稱以及節點上的參數。
Note: all features on this page are only available as of the ROS 2 Bouncy release.
注意:此網頁上的所有功能僅在ROS 2 Bouncy及之後發行版本中提供,适用于Bouncy、Crystal和Dashing。
Names within a node (e.g. topics/services) can be remapped using the syntax <old name>:=<new name>. The name/namespace of the node itself can be remapped using __node:=<new node name> and __ns:=<new node namespace>.
可以使用<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 chatter. 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 (/my_topic).
以下調用将導緻節點talker以節點名稱my_talker下啟動,釋出消息到主題my_topic上而不是預設值chatter。必須以正斜杠開頭的命名空間設定為/demo,這意味着在該命名空間(/demo/my_topic)中建立主題,而不是全局(/my_topic)。
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:
如果在單個程序内運作多個節點(例如,使用Composition),則可以使用其名稱作為字首重新映射參數傳遞給特定節點。例如,以下内容将重映射參數傳遞給指定的節點:
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
主題名稱為my_topic而不是預設值chatter。
See __log_level argument usage in the logging page.
請參考日志記錄網頁__log_level中的參數用法。
Note: The behavior of parameters changed for Dashing and newer, so if you’re using Crystal or older, see the section below for the old tutorial content.
注意:參數的行為已更改為Dashing和更新版本,是以如果使用的是Crystal或更舊版本,請參考下面的部分以擷取舊教程内容。
Setting parameters from the command-line is currently only supported in the form of yaml files.
目前僅以yaml檔案的形式支援從指令行設定參數。
See here for examples of the yaml file syntax. 有關 yaml檔案文法的示例,請參考此處。
As an example, save the following as demo_params.yaml:
例如,将以下内容另存為demo_params.yaml:
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 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
Parameters support for Python nodes was added in Crystal. In Bouncy only C++ nodes are supported.
Crystal中添加了對Python節點的參數支援。在Bouncy中,僅支援C ++節點。
Setting parameters from the command-line is currently supported in the form of yaml files.
目前,yaml檔案支援從指令行設定參數。
talker:
Then run the following: 然後運作以下指令:
ros2 run demo_nodes_cpp talker __params:=demo_params.yaml
Other nodes will be able to retrieve the parameter values, e.g.: 其他節點将能夠檢索參數值,例如:
$ ros2 param list talker