版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/ZhangRelay/article/details/100772918
See also http://docs.ros2.org/ for ROS 2 high level documentation.
有关ROS 2高级文档,另请参考http://docs.ros2.org/。
Table of Contents 目录
ROS is a middleware based on an anonymous publish/subscribe mechanism that allows for message passing between different ROS processes.
ROS是一种基于匿名发布/订阅机制的中间件,允许在不同的ROS进程之间传递消息。
At the heart of any ROS 2 system is the ROS graph. The ROS graph refers to the network of nodes in a ROS system and the connections between them by which they communicate.
任何ROS 2系统的核心是ROS图。ROS图指的是ROS系统中的节点网络以及它们之间通信的连接。
ROS2 turtlesim Graph
节点:节点是使用ROS与其他节点通信的实体(或实例)。
消息:订阅或发布到主题时ROS使用的数据类型。
主题:节点可以将消息发布到主题,也可以订阅主题以接收消息。
发现:节点确定如何相互通信的自动过程。
A node is a participant in the ROS graph. ROS nodes use a ROS client library to communicate with other nodes. Nodes can publish or subscribe to a Topic. Nodes can also provide or use a Service. There are configurable Parameters associated with a node. Connections between nodes are established through a distributed discovery process. Nodes may be located in the same process, in different processes, or on different machines. These concepts will be described in more detail in the sections that follow.
节点是ROS图中的参与者。ROS节点使用ROS客户端库与其他节点通信。节点可以发布或订阅主题。节点还可以提供或使用服务。可以对节点相关联的参数进行配置。节点之间的连接是通过分布式发现过程建立的。节点可以位于相同的进程中,也可以位于不同的进程中,还可以位于不同的机器上。这些概念将在以下部分中更详细地介绍说明。
ROS client libraries allow nodes written in different programming languages to communicate. There is a core ROS client library (RCL) that implements common functionality needed for the ROS APIs of different languages. This makes it so that language-specific client libraries are easier to write and that they have more consistent behavior.
ROS客户端库支持不同编程语言编写的节点进行通信。一个核心的ROS客户端库(ROS client library, RCL)实现了不同语言ROS API所需的通用功能。这使得特定语言的客户端库更易于编写,并且它们具有更一致的行为。
The following client libraries are maintained by the ROS 2 team:
以下客户端库由ROS 2团队维护:
rclcpp = C ++客户端库
rclpy = Python客户端库
Additionally, other client libraries have been developed by the ROS community. See the ROS 2 Client Libraries article for more details.
此外,ROS社区还开发了其他客户端库。有关这方面内容的更多详细信息,请参考ROS 2客户端库文章。
Discovery of nodes happens automatically through the underlying middleware of ROS 2. It can be summarized as follows: 节点的发现通过ROS 2的底层中间件自动实现完成。可以总结如下:
启动节点时,它会将其存在通告给具有相同ROS域的网络上的其他节点(使用ROS_DOMAIN_ID环境变量 设置ROS域)。节点使用有关自身的信息响应此通告,以便可以进行适当的连接并且节点可以进行通信。
节点定期通告其存在,以便即使在初始发现期之后也可以与新发现的实体建立连接。
节点在离线时通告其他节点。
Nodes will only establish connections with other nodes if they have compatible Quality of Service settings.
只有节点具有兼容的服务质量设置,它们之间才可以建立连接。
In one terminal, start a node (written in C++) that will publish messages on a topic.
在一个终端中,启动将在主题上发布消息的节点(用C ++编写)。
ros2 run demo_nodes_cpp talker
In another terminal, start a second node (written in Python) that will subscribe to messages on the same topic.
在另一个终端中,启动第二个节点(用Python编写),该节点将订阅同一主题的消息。
ros2 run demo_nodes_py listener
You should see that these nodes discover each other automatically, and begin to exchange messages.
如果运行正常,应该看到这些节点自动发现彼此,并开始交换消息。
多试几组案例,熟练掌握ros2 run和rqt的基本使用。