> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 使用 qrb_ros_transport 测试 ROS 消息传输

> qrb_ros_transport 示例应用在 Qualcomm 机器人平台上实现了 ROS 消息的零拷贝传输。

该实现基于 [REP 2007](https://ros.org/reps/rep-2007.html)，它提供了定义序列化自定义类型的方法接口，或在无需转换的情况下将这些类型用于进程内通信。

`qrb_ros_transport` 在 ROS 节点之间发送图像 DMA 缓冲区文件描述符 (fd)，而不是发送图像数据本身。

摄像头、GPU 和 EVA 等硬件加速器通过 mmap DMA 缓冲区实现零拷贝共享图像数据。

## `qrb_ros_transport` 的管道流程

下图展示了 `qrb_ros_transport` 的管道流程。

<Frame caption="qrb_ros_transport 管道。">
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/SDKs/QIR-SDK-Ubuntu/images/image12.png" alt="ROS 2 component container where camera, color space convert, and face detection nodes exchange DMA buffer file descriptors through QRB ROS Transport." />
</Frame>

## 前提条件

你已根据[安装 QIR SDK](./install-the-qir-sdk)完成设备设置，并在设备上安装了 ROS2 Jazzy 和 Qualcomm Intelligent Robotics (QIR) SDK。

## 开箱即用运行 `qrb_ros_transport`

<Steps>
  <Step title="安装 qrb_ros_transport 包">
    ```bash Install the packages theme={null}
    sudo apt install ros-jazzy-qrb-ros-transport-\*
    ```
  </Step>

  <Step title="使用 qrb_ros::transport::type::Image">
    例如：

    1. 在你的 `package.xml` 中添加依赖：

       ```xml package.xml theme={null}
       <depend>qrb_ros_transport_image_type</depend>
       ```

    2. 在你的 `CMakeLists.txt` 中使用 `ament_cmake_auto` 查找依赖：

       ```cmake CMakeLists.txt theme={null}
       find_package(ament_cmake_auto REQUIRED)
       ament_auto_find_build_dependencies()
       ```

    3. 在你的 ROS 节点中使用适配的类型。

       ```cpp Use the adapted image type theme={null}
       #include "qrb_ros_transport_image_type/image.hpp"
       // Create message
       auto msg = std::make_unique<qrb_ros::transport::type::Image>();
       msg->header = std_msgs::msg::Header();
       msg->width = width;
       msg->height = height;
       msg->encoding = "nv12";
       // Allocate dmabuf for message
       auto dmabuf = lib_mem_dmabuf::DmaBuffer::alloc(size, "/dev/dma_heap/system");
       // ... set data to dmabuf
       msg->dmabuf = dmabuf;
       // Publish message
       pub->publish(std::move(msg));
       ```
  </Step>
</Steps>

## 从源码构建

从 `qrb_ros_transport` 源码构建并运行此应用。

<Steps>
  <Step title="安装依赖">
    ```bash Install the dependencies theme={null}
    sudo apt install ros-dev-tools \
      ros-jazzy-lib-mem-dmabuf \
      ros-jazzy-qrb-sensor-client \
      ros-jazzy-pcl-conversions colcon
    ```
  </Step>

  <Step title="将仓库克隆到设备上">
    ```bash Clone the repository theme={null}
    mkdir -p ~/qrb_ros_ws/src
    cd ~/qrb_ros_ws/src
    source /opt/ros/jazzy/setup.bash
    git clone https://github.com/qualcomm-qrb-ros/qrb_ros_transport.git
    ```
  </Step>

  <Step title="构建示例应用">
    ```bash Build the workspace theme={null}
    cd ~/qrb_ros_ws
    colcon build
    ```
  </Step>
</Steps>
