# Hub 集成

> **版本警告**
> 本文档面向 RVC4 设备和 ROS2 Kilted 及以上版本。 从
> **Kilted**
> 开始，默认 ROS 驱动为 v3，包名无后缀（例如
> `depthai_ros_driver`
> ）。 在
> **Humble**
> 和
> **Jazzy**
> 上，等效的 ROS v3 包使用
> `_v3`
> 后缀（例如
> `depthai_ros_driver_v3`
> ）。 同时假设您已经按照我们的
> [入门指南](https://docs.luxonis.com/cloud/hub/connect-oak.md)
> 设置好了 RVC4 摄像头。

## 快速开始 - 基本应用安装

设置好摄像头后，您应该能在 Hub 应用商店中看到 ROS 包 应用类别。

如果您安装并运行它，摄像头将在板载运行 ROS 驱动，并发布 RGB、深度和 IMU 数据。您可以在连接到同一网络的主机上检查和可视化这些数据，就像使用普通运行 ROS 的设备一样。

## 为 RVC4 开发 ROS 应用

以下所有示例都可以在 [示例仓库](https://github.com/luxonis/oak-examples/tree/main/apps/ros) 中找到。

## 修改基本示例

让我们来看看发布到商店的基本示例是如何构建的。您可以在 ros-driver-basic 目录中找到它。

我们最感兴趣的是 oakapp.toml 和 parameters.yaml 文件。在 parameters.yaml 中，我们可以按照
[参数说明文章](https://docs.luxonis.com/software-v3/depthai/ros/parameters.md) 中描述的方式设置驱动的参数。

```yaml
/**:
  ros__parameters:
    driver:
      i_enable_ir: true
    pipeline_gen:
      i_pipeline_type: RGBD
```

oakapp.toml 描述了应用运行的环境。它使用一个基础 ROS Kilted 镜像，其中已安装 depthai-ros 包，并将参数文件复制到该镜像中。设置完成后，驱动被启动，参数文件被传递给它。

```toml
identifier = "example.apps.ros.ros-driver-basic"
app_version = "0.9.0"

prepare_container = [
    { type = "COPY", source = "resolv.conf", target = "/etc/resolv.conf" },
    { type = "RUN", command = "apt-get update" },
    { type = "RUN", command = "apt-get install -y ros-kilted-depthai-ros"},
]

prepare_build_container = [

]

build_steps = [
]

entrypoint = ["bash", "-c", "source /opt/ros/kilted/setup.bash && ros2 launch depthai_ros_driver driver.launch.py params_file:=/app/parameters.yaml"]

[base_image]
api_url = "https://registry-1.docker.io" 
service = "registry.docker.io" 
oauth_url = "https://auth.docker.io/token"
auth_type = "repository" 
auth_name = "library/ros"
image_name = "library/ros"
image_tag = "kilted-ros-base"
```

ros-driver-rgb-pcl 和 ros-driver-spatial-bb 示例遵循类似的逻辑，它们使用不同的启动文件和参数。

```toml
identifier = "example.apps.ros.driver-rgb-pcl"
app_version = "0.9.0"

prepare_container = [
    { type = "COPY", source = "resolv.conf", target = "/etc/resolv.conf" },
    { type = "RUN", command = "apt-get update" },
    { type = "RUN", command = "apt-get install -y ros-kilted-depthai-ros"},
]

prepare_build_container = [

]

build_steps = [
]

entrypoint = ["bash", "-c", "source /opt/ros/kilted/setup.bash && ros2 launch depthai_ros_driver rgbd_pcl.launch.py"]

[base_image]
api_url = "https://registry-1.docker.io" 
service = "registry.docker.io" 
oauth_url = "https://auth.docker.io/token"
auth_type = "repository" 
auth_name = "library/ros"
image_name = "library/ros"
image_tag = "kilted-ros-base"
```

```toml
identifier = "example.apps.ros.driver-spatial-bb"
app_version = "0.9.0"

prepare_container = [
    { type = "COPY", source = "resolv.conf", target = "/etc/resolv.conf" },
    { type = "RUN", command = "apt-get update" },
    { type = "RUN", command = "apt-get install -y ros-kilted-depthai-ros"},
]

prepare_build_container = [

]

build_steps = [
]

entrypoint = ["bash", "-c", "source /opt/ros/kilted/setup.bash && ros2 launch depthai_filters spatial_bb.launch.py"]

[base_image]
api_url = "https://registry-1.docker.io" 
service = "registry.docker.io" 
oauth_url = "https://auth.docker.io/token"
auth_type = "repository" 
auth_name = "library/ros"
image_name = "library/ros"
image_tag = "kilted-ros-base"
```

## 自定义工作空间和管道

另一个有趣的示例位于 ros-driver-custom-workspace 中。我们可以看到如何开发直接在设备上运行的完整 ROS 应用。

与之前的示例一样，我们有 oakapp.toml 和 parameters.yaml 文件。

此外，还有一个 src 目录，对应于经典 ROS 工作空间中 src 目录的设置方式。其中有两个包：example_package 基于 ROS 发布者教程，包含用于此演示的自定义启动文件。

我们还可以看到 dai_ros_plugins 包，展示了如何创建自定义插件管道，然后可以直接在驱动中加载。

管道插件类型在传递给自定义启动文件的 parameters.yaml 文件中指定。

在 oakapp.toml 文件中，我们可以看到自定义工作空间是如何（直接在设备上！）构建和加载的。

```toml
identifier = "example.apps.ros.driver-custom-workspace"
app_version = "0.9.0"

prepare_container = [
    { type = "COPY", source = "resolv.conf", target = "/etc/resolv.conf" },
    { type = "RUN", command = "apt-get update -qq" },
    { type = "RUN", command = "apt install -y ros2-testing-apt-source"},
    { type = "RUN", command = "apt-get update -qq" },
    { type = "RUN", command = "apt-get install -qy ros-kilted-depthai-ros python3-colcon-common-extensions"},
]

prepare_build_container = [

]

build_steps = [
    "mkdir -p /ws/src",
    "cp -r /app/src/ /ws/",
    'bash -c "cd /ws && source /opt/ros/kilted/setup.bash && colcon build"'
]

entrypoint = ["bash", "-c", "source /ws/install/setup.bash && ros2 launch example_package example.launch.py"]

[base_image]
api_url = "https://registry-1.docker.io" 
service = "registry.docker.io" 
oauth_url = "https://auth.docker.io/token"
auth_type = "repository" 
auth_name = "library/ros"
image_name = "library/ros"
image_tag = "kilted-ros-base"
```
