ROS2編程基礎課程–arguments

  • 2019 年 10 月 5 日
  • 筆記

版權聲明:本文為部落客原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接和本聲明。

本文鏈接:https://blog.csdn.net/ZhangRelay/article/details/100773565

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。

Name remapping 名稱重新映射

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).

有關重新映射參數的更多詳細資訊,請參考此設計文檔(並非所有功能都可用)。

Example 示例

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。

Logger configuration 日誌記錄器配置

See __log_level argument usage in the logging page.

請參考日誌記錄網頁__log_level中參數用法。

Parameters 參數

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

Crystal and Older Crystal和之前發行版(Bouncy等)

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文件支援從命令行設置參數。

See here for examples of the yaml file syntax. 有關 yaml文件語法的示例,請參考此處

As an example, save the following as demo_params.yaml:

例如,將以下內容另存為demo_params.yaml:

talker:

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 talker __params:=demo_params.yaml

Other nodes will be able to retrieve the parameter values, e.g.: 其他節點將能夠檢索參數值,例如:

$ ros2 param list talker

a_string

some_int

some_lists.some_doubles

some_lists.some_integers