ROS2编程基础课程--命令行工具
Introspection with command line tools 使用命令行工具进行自检
ROS 2 includes a suite of command-line tools for introspecting a ROS 2 system.
ROS 2包括一套用于ROS 2系统自检的命令行工具。
Usage 用法
The main entry point for the tools is the command ros2, which itself has various sub-commands for introspecting and working with nodes, topics, services, and more.
这些工具的主要入口点是命令ros2,它本身具有各类子命令,用于自检和处理节点、主题、服务等。
To see all available sub-commands run: 要查看运行的所有可用子命令:
ros2 --help
每个子命令的细节,如节点:
ros2 node -h
Examples of sub-commands that are available include:
可用的子命令示例包括:
- daemon: Introspect/configure the ROS 2 daemon 自检/配置ROS 2守护程序
- launch: Run a launch file 运行启动文件
- lifecycle: Introspect/manage nodes with managed lifecycles 使用托管生命周期自检/管理节点
- msg: Introspect msg types 自检msg类型
- node: Introspect ROS nodes 自检ROS节点
- param: Introspect/configure parameters on a node 在节点上自检/配置参数
- pkg: Introspect ROS packages 自检ROS包
- run: Run ROS nodes 运行ROS节点
- security: Configure security settings 配置安全性设置
- service: Introspect/call ROS services 自检/调用ROS服务
- srv: Introspect srv types 自检srv类型
- topic: Introspect/publish ROS topics 自检/发布ROS主题
Example 示例
To produce the typical talker-listener example using command-line tools, the topic sub-command can be used to publish and echo messages on a topic.
要使用命令行工具生成典型的talker-listener示例,topic子命令可用于发布和回显主题上的消息。
Publish messages in one terminal with:
在一个终端中发布消息:
$ ros2 topic pub /chatter std_msgs/String "data: Hello world"
publisher: beginning loop
publishing std_msgs.msg.String(data='Hello world')
publishing std_msgs.msg.String(data='Hello world')
Echo messages received in another terminal with:
在另一个终端收到的回应消息:
$ ros2 topic echo /chatter
data: Hello world
data: Hello world
如果ok,可以看到如下:
Behind the scenes 背后机制
ROS 2 uses a distributed discovery process for nodes to connect to each other. As this process purposefully does not use a centralized discovery mechanism (like the ROS Master in ROS 1), it can take time for ROS nodes to discover all other participants in the ROS graph. Because of this, there is a long-running daemon in the background that stores information about the ROS graph to provide faster responses to queries, e.g. the list of node names.
ROS 2使用分布式发现过程来连接节点。由于此过程刻意不使用集中式发现机制(如ROS 1中的ROS Master),因此ROS节点可能需要一段时间才能发现ROS图中的所有其他参与者。因此,后台存在一个长时间运行的守护程序,它存储有关ROS图的信息,以便更快地响应查询,例如节点名称列表。
The daemon is automatically started when the relevant command-line tools are used for the first time. You can run ros2 daemon --help for more options for interacting with the daemon.
首次使用相关命令行工具时,守护程序将自动启动。可以运行ros2 daemon --help更多选项以与守护程序进行交互。
Implementation 实现
The source code for the ros2 command is available at https://github.com/ros2/ros2cli
关于ros2命令的源代码可在网页https://github.com/ros2/ros2cli上找到。
The ros2 tool has been implemented as a framework that can be extended via plugins. For example, the sros2 package provides a security sub-command that is automatically detected by the ros2 tool if the sros2 package is installed.
ros2工具实现了可通过插件扩展的框架。例如,sros2包提供了一个security子命令,ros2如果安装了sros2包,工具会自动检测该子命令。
文章来源: zhangrelay.blog.csdn.net,作者:zhangrelay,版权归原作者所有,如需转载,请联系作者。
原文链接:zhangrelay.blog.csdn.net/article/details/100773460
- 点赞
- 收藏
- 关注作者
评论(0)