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名称重新映射
<oldname>:=<newname>. The name/namespace of the node itself can be remapped__node:=<newnodename>and__ns:=<newnodenamespace>.
可以使用<oldname>:=<newname>语法重新映射节点(例如主题/服务)的名称。可以使用__node:=<newnodename>和__ns:=<newnodenamespace>重新映射节点本身的名称/命名空间。
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.
请注意,这些重映射是“静态”重映射,因为它们适用于节点的生命周期。尚未支持节点启动后“动态”重新映射名称。
有关重新映射参数的更多详细信息,请参考此设计文档(并非所有功能都可用)。
Example示例
talkermy_talkermy_topicchatter/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
将重映射参数传递给特定节点
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
before
以下示例更改节点名称并重新映射主题(在主题重新映射֮ǰ始终应用节点和命名空间更改):
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日志记录器配置
__log_levelthe logging page.
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文件的形式支持从命令行设置参数。
demo_params.yaml:
例如,将以下内容另存为demo_params.yaml:
parameter_blackboard:
ros__parameters:
some_int:42
a_string:"Helloworld"
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 OlderCrystal和之前发行版(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文件支持从命令行设置参数。
demo_params.yaml:
例如,将以下内容另存为demo_params.yaml:
talker:
ros__parameters:
some_int:42
a_string:"Helloworld"
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
来源:51CTO
作者:zhangrelay
链接:https://blog.csdn.net/ZhangRelay/article/details/100773565