ROS2编程基础课程--arguments

版权声明:本文为博主原创文章,遵循 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

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券