目录

1. ROS2 IPC and DDSROS2 IPC 和 DDS

1.1 IPC (Inter-process Communication) protocol in ROS2

1.2 DDS (Data Distribution Service) protocol in ROS2

1.3 Interaction between IPC and DDS

2. ROS2 的通信协议:Topics, Services and Actions

3. Ros2 Interfaces 接口

3.1 ROS2 Common InterfacesROS2 公共接口


In this post we'll cover the role of the fundamental IPC and DDS protocols in ROS2, and their abstractions: Topic, Service and Action protocols. Also, we'll introduce ROS2 interfaces.
在这篇文章中,我们将介绍基本的 IPC 和 DDS 协议在 ROS2 中的作用,以及它们的抽象概念:主题、服务和行动协议。此外,我们还将介绍 ROS2 接口。

In the realm of robotics, efficient and reliable communication between various components (sensors, actuators, hardware) is paramount for successful operation. ROS2 employs sophisticated communication mechanisms to facilitate seamless interaction between nodes within a robotic system.
在机器人领域,各种组件 (传感器、执行器、硬件) 之间高效可靠的通信对于成功运行至关重要。ROS2 采用复杂的通信机制,以促进机器人系统中节点之间的无缝互动。

At the heart of this communication infrastructure lie two key components: IPC, DDS and its abstractions: Topic, Service and Action protocols.
这种通信基础设施的核心包括两个关键组件:IPC、DDS 及其抽象概念:主题、服务和行动协议。

DDS and IPC serve as foundational pillars in robotics, providing the infrastructure necessary for building complex and robust robotic systems. Their seamless integration within ROS2 enables nodes to communicate efficiently, share information in real-time, and collaborate effectively to accomplish various tasks, ranging from perception and planning to control and decision-making.
DDS 和 IPC 是机器人学的基础支柱,为构建复杂而强大的机器人系统提供必要的基础设施。它们在 ROS2 中的无缝集成使节点能够高效地通信,实时共享信息,并有效地协作完成各种任务,从感知和规划到控制和决策。

1. ROS2 IPC and DDSROS2 IPC 和 DDS

1.1 IPC (Inter-process Communication) protocol in ROS2

IPC, or Inter-Process Communication, serves as the underlying mechanism for communication between processes running on the same system. IPC plays a vital role in enabling nodes to exchange messages, share data, and synchronize their activities within a robotic environment.
行程间通讯 (IPC) 是同一系统中运行的进程之间进行通信的基础机制。IPC 在使节点能够在机器人环境中交换消息、共享数据和同步其活动方面起着至关重要的作用。

Key aspects of IPC include:IPC 的关键方面包括:

  • Efficient Local Communication: IPC mechanisms such as shared memory, pipes, sockets, and message queues facilitate efficient communication between nodes running on the same machine, eliminating the overhead of network communication.
    高效的本地通信:共享内存、管道、套接字和消息队列等 IPC 机制促进了同一台机器上运行的节点之间的高效通信,消除了网络通信的开销。
  • Resource Sharing: IPC allows nodes to share resources such as data buffers or synchronization primitives, enabling collaborative processing and coordination among different components of a robotic system.
    资源共享:IPC 允许节点共享资源,如数据缓冲区或同步基元,从而实现机器人系统不同组件之间的协同处理和协调。
  • Low-latency Communication: By bypassing network protocols, IPC mechanisms offer low-latency communication, which is crucial for time-sensitive robotics applications, including real-time control and sensor data processing.
    低延迟通信:通过绕过网络协议,IPC 机制提供了低延迟通信,这对于时间敏感型机器人应用至关重要,包括实时控制和传感器数据处理。
1.2 DDS (Data Distribution Service) protocol in ROS2

   Data Distribution Service (DDS) stands as a pivotal middleware protocol utilized in ROS2 for real-time data distribution and messaging. Designed to offer standardized and efficient communication, DDS abstracts the intricacies of inter-process communication (IPC) and network protocols, streamlining data exchange between nodes.
数据分发服务 (DDS) 是 ROS2 中用于实时数据分发和消息传递的关键中间件协议。DDS 旨在提供标准化和高效的通信,它抽象了行程间通讯 (IPC) 和网络协议的复杂性,简化了节点之间的数据交换。

    DDS offers a comprehensive set of features crucial for robotics applications:
DDS 提供了一组对机器人应用至关重要的全面特性:

  • Publish-Subscribe Communication: DDS enables nodes to publish data on specific topics and subscribe to topics to receive relevant information. This decouples the nodes, allowing for modular and scalable system architectures.
    发布 - 订阅通信:DDS 使节点能够发布关于特定主题的数据,并订阅主题以接收相关信息。这解耦了节点,实现了模块化和可扩展的系统架构。
  • Quality of Service (QoS) Settings: DDS supports a wide range of Quality of Service parameters, allowing developers to tailor communication characteristics such as reliability, latency, and bandwidth usage to suit the requirements of their robotic systems.
    服务质量 (QoS) 设置:DDS 支持广泛的服务质量参数,使开发人员能够根据其机器人系统的需求定制通信特性,如可靠性、延迟和带宽使用。
  • Discovery Mechanisms: DDS facilitates automatic discovery of publishers and subscribers within a network, simplifying the configuration and deployment of distributed robotic systems.
    发现机制:DDS 促进了网络中发布者和订阅者的自动发现,简化了分布式机器人系统的配置和部署。
  • Real-time Capabilities: DDS is designed to support real-time and distributed systems, making it suitable for applications where timing constraints are critical, such as robotic control and sensor fusion.
    实时功能:DDS 旨在支持实时和分布式系统,使其适用于时序约束至关重要的应用,如机器人控制和传感器融合。

The current default implementation of DDS in ROS2 is Fast DDS (formerly known as Fast RTPS). Fast DDS is an open-source implementation of the DDS standard maintained by the Eclipse Foundation.
当前 ROS2 中 DDS 的默认实现是 Fast DDS (以前称为 Fast RTPS)。Fast DDS 是 Eclipse 基金会维护的 DDS 标准的开源实现。

But the realm of DDS is not 'one fits all': for implementations that require specific performance (such as a very small real time latency, a large number of nodes running at the same time etc), other DDS protocols may be used.
但 DDS 的领域并非 “一刀切”: 对于需要特定性能的实现 (如非常小的实时延迟、大量节点同时运行等), 可以使用其他 DDS 协议。

As the time of writing this post, the LTE distribution of ROS2 Iron supports eProsima’s Fast DDS, RTI’s Connext DDS, Eclipse Cyclone DDS, and GurumNetworks GurumDDS. You can check ROS DDS list for a list of supported DDS vendors by distribution.
截至撰写本文时,ROS2 Iron 的 LTE 发行版支持 eProsima 的 Fast DDS、RTI 的 Connect DDS、Eclipse Cyclone DDS 和 GurumNetworks GurumDDS。您可以查看 ROS DDS 列表,了解不同发行版支持的 DDS 供应商列表。

1.3 Interaction between IPC and DDS

IPC and DDS are closely related as DDS utilizes IPC mechanisms to facilitate communication between nodes: while DDS can handle communication over networks for distributed systems, it also utilizes IPC mechanisms for local communication between nodes running on the same machine.
IPC 和 DDS 密切相关,因为 DDS 利用 IPC 机制来促进节点之间的通信:虽然 DDS 可以处理分布式系统的网络通信,但它也利用 IPC 机制来实现运行在同一机器上的节点之间的本地通信。

For example, when nodes communicate over topics, services, or actions within a single ROS2 instance, DDS may employ IPC mechanisms such as shared memory, pipes, sockets, or message queues for efficient inter-process communication, so by using IPC, DDS can achieve low-latency and all the other performance prerequisites needed by robotic systems.
例如,当节点在单个 ROS2 实例中就主题、服务或操作进行通信时,DDS 可以使用 IPC 机制 (如共享内存、管道、套接字或消息队列) 来实现高效的行程间通讯,因此通过使用 IPC,DDS 可以实现低延迟和机器人系统所需的所有其他性能先决条件。

For further reading on DDS, check this amazing post on Medium: DDS in Ros2 for Realiable Robotics Communication
要进一步阅读 DDS, 请查看 Medium 上这篇令人惊叹的文章:DDS in Ros2 for Realable Robotics Communication


2. ROS2 的通信协议:Topics, Services and Actions

In ROS2, topics, services, and actions are the standard communication mechanisms used by nodes to exchange data and perform various tasks, and are implemented using DDS as the underlying middleware.
在 ROS2 中,主题、服务和动作是节点用于交换数据和执行各种任务的标准通信机制,并使用 DDS 作为底层中间件实现。

They all serve different purposes and can be tailored for robot's specific tasks:
它们都服务于不同的目的,可以根据机器人的特定任务进行定制:

  • Topics allow publisher - subscriber communication on a topic, also called channel. The publisher issues a message of a defined type on a named channel and the subscriber retrieves the data from the channel. There can be multiple nodes/applications interested in the channel content, i.e. multiple publishers nodes and multiple subscribers nodes. A node can also perform both publisher and subscriber activities on different channels. The type of the data exchanged on that specific channel is defined and never changes, and the channel id must be unique to avoid conflicts in the communication.
    主题允许发布者 - 订阅者在一个主题上进行通信,这个主题也称为通道。发布者在命名通道上发布一条定义类型的消息,订阅者从通道中检索数据。可能有多个节点 / 应用程序对通道内容感兴趣,即多个发布者节点和多个订阅者节点。节点还可以在不同的通道上执行发布者和订阅者活动。在该特定通道上交换的数据类型是定义的,永远不会改变,通道 id 必须是唯一的,以避免通信冲突。

Ros2 topics

  • Services allow client - server communication between nodes, over a service instance. The service server node provides some functionalities (ex. calculating a sum from two integers). When interested, the service client node requests the server functionalities specifying the service type and request message, and waits for a response from the server. Services can be either synchronous or asynchronous. If synchronous, during the server processing, the client node execution is put on hold; otherwise, the client node will continue its execution. The service is instantiated as the server is created, and multiple nodes can request a response from the server.
    服务允许节点之间通过服务实例进行客户端 - 服务器通信。服务服务器节点提供一些功能 (例如,计算两个整数的和)。当感兴趣时,服务客户端节点向服务器请求功能,指定服务类型和请求消息,并等待服务器的响应。服务可以是同步的或异步的。如果是同步的,在服务器处理过程中,客户端节点的执行将暂停;否则,客户端节点将继续其执行。服务在创建服务器时实例化,多个节点可以请求服务器的响应。

Ros2 services

  • Actions provide a protocol similar to services but are designed for long-running tasks with allowing asynchronous communication. Within Actions, Action Clients send a request to the Action Server, demanding the processing of a task and a final goal message. Contrary to services, during Action processing the Action Client continues to run while the Action Server is executing. During the execution, feedback messages will be sent to the Action Client and it also might decide to abort the execution before completion. Actions protocols are used for tasks whose execution is very time consuming (ex, robot navigation task).
    Action 提供了一个类似于 Service 的协议,但它是为长时间运行的任务设计的,允许异步通信。在 Action 中,Action 客户端向 Action 服务器发送请求,要求处理任务和最终目标消息。与 Service 不同,在 Action 处理过程中,Action 客户端在 Action 服务器执行时继续运行。在执行过程中,反馈消息将发送给 Action 客户端,它也可能决定在完成之前终止执行。Action 协议用于执行时间非常耗时的任务 (例如,机器人导航任务)。

In summary, topics, services, and actions in ROS2 leverage DDS to enable seamless communication between nodes, providing a flexible and efficient communication infrastructure for building complex robotic systems.
总之,ROS2 中的主题、服务和行动利用 DDS 实现节点之间的无缝通信,为构建复杂的机器人系统提供灵活高效的通信基础设施。

It's now the moment to delve into the structure of data exchanged through Topics, Services, and Actions. Specifically, we're introducing the notion of ROS2 Interfaces.
现在是时候深入研究通过主题、服务和行动交换的数据结构了。具体来说,我们正在介绍 ROS2 接口的概念。

3. Ros2 Interfaces 接口

In ROS2, an interface is a definition that specifies the structure of messages, services, or actions. It serves as a blueprint or contract that defines the fields and types of data that can be communicated between nodes.
在 ROS2 中,接口是一个定义,用于指定消息、服务或操作的结构。它充当蓝图或合约,定义节点之间可以通信的字段和数据类型。

Interfaces play a crucial role in facilitating communication between different components of a robotic system by ensuring that nodes agree on the format and content of exchanged data.
接口通过确保节点就交换数据的格式和内容达成一致,在促进机器人系统不同组件之间的通信方面发挥着至关重要的作用。

A data structure is defined by a set of fields, where each field is described by a type and a name.
数据结构由一组字段定义,其中每个字段都用类型和名称来描述。

  • Messages: single data structure is called message. Each message has a name and a type. Together with the name of the package, a message can be uniquely identified.
    消息:单一的数据结构称为消息。每条消息都有一个名称和类型。结合包的名称,消息可以被唯一识别。
  • Services: The service style communications are composed of two parts: a request and a response.  The request and response are message declarations.
    服务:服务风格通信由两部分组成:请求和响应。请求和响应是 message 声明。
  • Actions: The action style communications are composed of three parts: a goal, a result, and feedback. All three are message declarations.
    动作:动作风格的通信由三个部分组成:目标、结果和反馈。这三个部分都是 message 声明。
3.1 ROS2 Common InterfacesROS2 公共接口

        ROS 2 Common Interfaces typically refer to standardized message types, service definitions, and action definitions that are commonly used across various ROS 2 applications and packages. These common interfaces are provided by the ROS 2 ecosystem to promote interoperability and facilitate communication between different components and systems.
ROS 2 公共接口通常指的是标准化的消息类型、服务定义和操作定义,这些定义通常在各种 ROS 2 应用程序和包中使用。ROS 2 生态系统提供这些公共接口是为了促进互操作性并促进不同组件和系统之间的通信。

Logo

立足具身智能前沿赛道,致力于搭建全球化、开源化、全栈式技术交流与实践共创平台。

更多推荐