教程:VENTUNO Q/ROS 2 RGBD 相机:修订间差异

来自WindwizPi wiki
此页面具有访问限制。如果您看见此消息,则说明您没有权限访问此页面。
Windwiz​(留言 | 贡献)
导入 VENTUNO Q 中文教程
 
Windwiz​(留言 | 贡献)
导入 VENTUNO Q 中文教程
 
第25行: 第25行:
=== 硬件连接 ===
=== 硬件连接 ===


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/ventuno-sbc-mode-realsense.png" alt="VENTUNO Q 单板机模式" />
 
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/ventuno-sbc-mode-realsense.png
 


上图显示了本教程中使用的基本VENTUNO Q设置、电路板、电源、HDMI显示器、USB键盘和鼠标,在SBC模式下运行Ubuntu。这是连接相机之前的起点。除了此基本设置之外,RealSense还连接到开发板的 USB-A 端口之一。
上图显示了本教程中使用的基本VENTUNO Q设置、电路板、电源、HDMI显示器、USB键盘和鼠标,在SBC模式下运行Ubuntu。这是连接相机之前的起点。除了此基本设置之外,RealSense还连接到开发板的 USB-A 端口之一。
第52行: 第54行:
RealSense 是一款深度相机,它将标准 RGB 图像与来自红外立体传感器的深度数据相结合。它还生成 3D 点云,即空间中的一组点,每个点都有一个位置和颜色,这是 ''RTABMap'' 等 3D SLAM 算法的主要输入。
RealSense 是一款深度相机,它将标准 RGB 图像与来自红外立体传感器的深度数据相结合。它还生成 3D 点云,即空间中的一组点,每个点都有一个位置和颜色,这是 ''RTABMap'' 等 3D SLAM 算法的主要输入。


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_lens.png" alt="实感 D435 镜头" />
 
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_lens.png
 


D435 的正面有四个开口。其中两个组成了立体红外对,共同工作,通过比较同一场景的两个视图之间的细微差异来计算深度。
D435 的正面有四个开口。其中两个组成了立体红外对,共同工作,通过比较同一场景的两个视图之间的细微差异来计算深度。
第60行: 第64行:
第四个开口是RGB相机,捕捉正常的彩色图像。深度来自立体红外对,颜色来自 RGB 相机,点云将两者结合起来。
第四个开口是RGB相机,捕捉正常的彩色图像。深度来自立体红外对,颜色来自 RGB 相机,点云将两者结合起来。


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_setup.png" alt="Realsense D435 设置" />
 
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_setup.png
 


<blockquote>
<blockquote>
第168行: 第174行:
在 VENTUNO Q 上,RSUSB 后端可以通过独立 SDK 工具(<code>realsense-viewer</code>、<code>rs-enumerate-devices</code>)和ROS 2 包装器直接与 D435 一起使用。
在 VENTUNO Q 上,RSUSB 后端可以通过独立 SDK 工具(<code>realsense-viewer</code>、<code>rs-enumerate-devices</code>)和ROS 2 包装器直接与 D435 一起使用。


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_rs1.png" alt="实感 - ROS (1)" />


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_rs2.png" alt="实感 - ROS (2)" />
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_rs1.png
 
 
 
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_rs2.png
 
 
 
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_viewer_1.gif
 
 


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_viewer_1.gif" alt="实感 - ROS (3_1)" />
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_viewer_2.gif


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_viewer_2.gif" alt="实感 - ROS (3_2)" />


<span id="installing-the-ros-wrapper"></span>
<span id="installing-the-ros-wrapper"></span>
第241行: 第255行:
</syntaxhighlight>
</syntaxhighlight>


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_1.png" alt="实感 - ROS (4)" />
 
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_1.png
 


<span id="updating-the-firmware"></span>
<span id="updating-the-firmware"></span>
第335行: 第351行:
</syntaxhighlight>
</syntaxhighlight>


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_3.png" alt="实感 - ROS (5)" />
 
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_3.png
 


或者使用启动文件,这是推荐的方式,因为它公开了方便的参数:
或者使用启动文件,这是推荐的方式,因为它公开了方便的参数:
第354行: 第372行:
</syntaxhighlight>
</syntaxhighlight>


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_2.png" alt="实感 - ROS (6)" />
 
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_2.png
 


<span id="camera-name-and-topic-structure"></span>
<span id="camera-name-and-topic-structure"></span>
第387行: 第407行:
</syntaxhighlight>
</syntaxhighlight>


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_4.png" alt="实感 - ROS (7)" />
 
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_4.png
 


将深度与颜色对齐使得深度图像中的每个像素对应于彩色图像中的相同像素。它在<code>/camera/camera/aligned_depth_to_color/image_raw</code>上发布对齐的流。
将深度与颜色对齐使得深度图像中的每个像素对应于彩色图像中的相同像素。它在<code>/camera/camera/aligned_depth_to_color/image_raw</code>上发布对齐的流。
第409行: 第431行:
</syntaxhighlight>
</syntaxhighlight>


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_5.png" alt="实感 - ROS (8)" />
 
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_5.png
 


默认情况下,此构建上的点云仅发布几何体、<code>x</code>、<code>y</code>、<code>z</code>和强度,没有颜色数据,即使颜色流正在运行也是如此。这可以通过直接检查消息字段来验证:
默认情况下,此构建上的点云仅发布几何体、<code>x</code>、<code>y</code>、<code>z</code>和强度,没有颜色数据,即使颜色流正在运行也是如此。这可以通过直接检查消息字段来验证:
第436行: 第460行:
寻找RealSense出现的巴士。报告<code>5000M</code>或<code>10000M</code>的总线是USB 3.x,报告<code>480M</code>的总线是USB 2.x:
寻找RealSense出现的巴士。报告<code>5000M</code>或<code>10000M</code>的总线是USB 3.x,报告<code>480M</code>的总线是USB 2.x:


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_lsusb_t.png" alt="实感 - ROS (9)" />
 
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_lsusb_t.png
 


深度和颜色维护单独、独立的有效配置文件列表,因此直接查询两者,而不是假设分辨率对两个流都有效:
深度和颜色维护单独、独立的有效配置文件列表,因此直接查询两者,而不是假设分辨率对两个流都有效:
第444行: 第470行:
</syntaxhighlight>
</syntaxhighlight>


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_6_1.png" alt="实感 - ROS (10)" />
 
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_6_1.png
 


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
第450行: 第478行:
</syntaxhighlight>
</syntaxhighlight>


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_6_2.png" alt="实感 - ROS (10)" />
 
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_6_2.png
 


在两个流上以较低的分辨率启动。例如,在 D435 上:
在两个流上以较低的分辨率启动。例如,在 D435 上:
第461行: 第491行:
</syntaxhighlight>
</syntaxhighlight>


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_usb32_reduced_profile.png" alt="实感 - ROS (11)" />
 
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_usb32_reduced_profile.png
 


然后像以前一样重新启用点云:
然后像以前一样重新启用点云:
第471行: 第503行:
在此分辨率下,颜色流保持稳定的 15 Hz:
在此分辨率下,颜色流保持稳定的 15 Hz:


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_usb32_hz.png" alt="实感 - ROS (12)" />
 
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_usb32_hz.png
 


<blockquote>
<blockquote>
第494行: 第528行:
</syntaxhighlight>
</syntaxhighlight>


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_7.png" alt="实感 - ROS (10)" />
 
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_7.png
 


<code>/camera/camera/depth/color/points</code>主题将3D点云作为<code>sensor_msgs/PointCloud2</code>消息携带,并且是<code>RTABMap</code>用于3D SLAM的消费主题。在VENTUNO Q上,该主题仅在运行时设置<code>pointcloud__neon_.enable</code>后出现,如上所述。
<code>/camera/camera/depth/color/points</code>主题将3D点云作为<code>sensor_msgs/PointCloud2</code>消息携带,并且是<code>RTABMap</code>用于3D SLAM的消费主题。在VENTUNO Q上,该主题仅在运行时设置<code>pointcloud__neon_.enable</code>后出现,如上所述。
第508行: 第544行:
</syntaxhighlight>
</syntaxhighlight>


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_8.png" alt="实感 - ROS (11)" />


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_9.png" alt="实感 - ROS (12)" />
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_8.png
 
 
 
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_9.png
 


从窗口顶部的主题下拉列表中选择<code>/camera/camera/color/image_raw</code>。特别是对于点云,使用[[#visualizing-sensors-in-rviz2|'''RViz2''' with a ⟦C1⟧ display]]设置为<code>/camera/camera/depth/color/points</code>主题,并将颜色转换器设置为<code>RGB8</code>以查看实际的相机颜色而不是强度梯度。
从窗口顶部的主题下拉列表中选择<code>/camera/camera/color/image_raw</code>。特别是对于点云,使用[[#visualizing-sensors-in-rviz2|'''RViz2''' with a ⟦C1⟧ display]]设置为<code>/camera/camera/depth/color/points</code>主题,并将颜色转换器设置为<code>RGB8</code>以查看实际的相机颜色而不是强度梯度。


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_10.png" alt="实感 - ROS (13)" />
 
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_10.png
 


此完整序列、降低的分辨率、<code>pointcloud__neon_.enable</code> 和 <code>pointcloud__neon_.stream_filter:=2</code>,在 RViz2 中在近距离连接到 VENTUNO Q 的物理 D435 上产生稳定、正确着色的 3D 重建。在典型的房间尺度距离下,降低的分辨率将产生更稀疏的云,因为总体捕获的点更少,但应用相同的步骤。
此完整序列、降低的分辨率、<code>pointcloud__neon_.enable</code> 和 <code>pointcloud__neon_.stream_filter:=2</code>,在 RViz2 中在近距离连接到 VENTUNO Q 的物理 D435 上产生稳定、正确着色的 3D 重建。在典型的房间尺度距离下,降低的分辨率将产生更稀疏的云,因为总体捕获的点更少,但应用相同的步骤。
第527行: 第569行:
</syntaxhighlight>
</syntaxhighlight>


<img src="https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_rviz2.gif" alt="Realsense 和 Rviz2 - ROS" />
 
https://cdn.jsdelivr.net/gh/arduino/docs-content@main/content/hardware/ventuno/boards/ventuno-q/tutorials/robotics/ros2-perception-rgbd-cam/assets/realsense_d435_rviz2.gif
 


对于彩色图像,添加图像显示并将其主题设置为<code>/camera/camera/color/image_raw</code>。对于点云,添加 PointCloud2 显示并将其主题设置为<code>/camera/camera/depth/color/points</code>。
对于彩色图像,添加图像显示并将其主题设置为<code>/camera/camera/color/image_raw</code>。对于点云,添加 PointCloud2 显示并将其主题设置为<code>/camera/camera/depth/color/points</code>。

2026年9月28日 (一) 06:01的最新版本

概述

深度相机使机器人能够测量场景中每个点的距离,而不仅仅是它看起来的样子。在ROS 2中,摄像机数据作为标准消息类型通过主题发布,因此系统中的任何节点都可以订阅并处理它,无论哪个特定摄像机生成它。

在本教程中,您将使用 ⟦C0⟧ 包在 Arduino® VENTUNO™ Q 上构建 RealSense SDK 和 ROS 包装器,并将颜色、深度和点云数据发布为 ROS 2 主题。

目标

  • 在VENTUNO Q上构建RealSense SDK和ROS包装器。
  • 启动RealSense节点并验证颜色、深度和点云主题。
  • 从终端验证摄像机的数据速率并使用rqt_image_view和RViz2查看。

硬件与软件要求

硬件要求

硬件连接

ventuno-sbc-mode-realsense.png


上图显示了本教程中使用的基本VENTUNO Q设置、电路板、电源、HDMI显示器、USB键盘和鼠标,在SBC模式下运行Ubuntu。这是连接相机之前的起点。除了此基本设置之外,RealSense还连接到开发板的 USB-A 端口之一。

VENTUNO Q 有两个 USB-A 端口,在此基本设置中键盘和鼠标已占用这些端口。由于RealSense也需要USB端口,因此建议使用连接到开发板USB-C端口的USB-C集线器来提供额外的USB-A端口,这样您就不需要在每次连接相机时断开键盘或鼠标的连接。

说明:

在本教程中,显示​​器通过主板的本机 HDMI 端口进行连接,从而为集线器保留 USB-C 端口。

软件要求

警告:

在继续本教程之前,请确保您的 VENTUNO Q 安装了最新的系统映像,并且 ROS 2 Jazzy 工作正常。

RealSense 相机

RealSense 是一款深度相机,它将标准 RGB 图像与来自红外立体传感器的深度数据相结合。它还生成 3D 点云,即空间中的一组点,每个点都有一个位置和颜色,这是 RTABMap 等 3D SLAM 算法的主要输入。


realsense_d435_lens.png


D435 的正面有四个开口。其中两个组成了立体红外对,共同工作,通过比较同一场景的两个视图之间的细微差异来计算深度。

它们之间有一台红外投影仪,它可以将不可见的点图案投射到场景上,从而提供立体对纹理来匹配,因此深度仍然适用于平坦、无特征的表面(如空白墙)。

第四个开口是RGB相机,捕捉正常的彩色图像。深度来自立体红外对,颜色来自 RGB 相机,点云将两者结合起来。


realsense_d435_setup.png


说明:

RealSense GitHub 组织已迁移至RealSenseAI。如果您发现IntelRealSense/realsense-ros的引用,请参阅⟦C0⟧。

安装RealSense SDK

RealSense ROS 包装器依赖于首先安装的 librealsense SDK。有三种安装选项,建议使用单一安装路径以避免安装冲突。

第一个选项直接从英特尔服务器安装librealsense2 Debian 软件包,紧随Linux Debian Installation Guide。

确保还安装了 librealsense2-dkms、librealsense2-utils 和 librealsense2-dev 软件包以及基础软件包。librealsense2-utils 软件包提供了 realsense-viewer,这是一个用于直接检查相机颜色和深度流的图形工具,如果您有连接到 VENTUNO Q 的监视器,则非常有用。

第二个选项通过 ROS 包服务器安装它:

sudo apt install ros-jazzy-librealsense2*

第三个选项从源代码构建⟦C0⟧。可以参考 Linux Installation guide,它使您可以访问发布的最新功能和特定 SDK 版本。有两种从源代码构建的方法,具体取决于您是否可以使用内核补丁。

内核补丁构建

这是 RealSense 推荐的构建,以获得最佳性能和完整的多摄像头支持。它使用一个脚本来修补和重建内核的 uvcvideo 模块,并针对元数据支持和帧处理进行 RealSense 特定修复。

该脚本根据您运行的内核版本从 git.launchpad.net 获取匹配的 Ubuntu 内核源代码:

git clone --depth 1 https://github.com/realsenseai/librealsense.git
cd librealsense/scripts
sudo bash patch-realsense-ubuntu-lts-hwe.sh
curl -v https://git.launchpad.net

警告:

此方法需要网络访问git.launchpad.net。如果该主机在您的环境中无法访问(例如由于网络策略限制),则脚本将在内核源获取步骤中挂起或失败。请先检查连接情况:


如果无法连接,请使用下面的 RSUSB 后端版本。

RSUSB 后端构建

此方法使用用户空间 USB 驱动程序而不是修补的内核模块,完全避免了内核修补。对于无法进行内核修补的平台,它是标准替代方案:

git clone --depth 1 https://github.com/realsenseai/librealsense.git
cd librealsense
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DFORCE_RSUSB_BACKEND=true
make -j$(nproc)
sudo make install

构建后,应用 udev 规则,以便无需 root 即可访问相机:

sudo cp ../config/99-realsense-libusb.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules && sudo udevadm trigger
sudo apt remove --purge ros-jazzy-librealsense2*

警告:

如果还安装了ros-jazzy-librealsense2,则在构建ROS包装器时,无论CMAKE_PREFIX_PATH或-Drealsense2_DIR覆盖如何,它都具有优先权。要专门针对此源构建构建 ROS 包装器,请首先删除 apt 包:

在 VENTUNO Q 上,RSUSB 后端可以通过独立 SDK 工具(realsense-viewer、rs-enumerate-devices)和ROS 2 包装器直接与 D435 一起使用。


realsense_d435_rs1.png


realsense_d435_rs2.png


realsense_d435_viewer_1.gif


realsense_d435_viewer_2.gif


安装 ROS 包装器

安装 SDK 后,安装 ROS 包装器。有两种选择。第一个选项直接从 ROS 包服务器安装包装器:

sudo apt install ros-jazzy-realsense2-camera

如果您已经使用上面的 ros-jazzy-librealsense2* 命令安装了 SDK,则该包可能已经作为依赖项存在。

第二个选项从源代码构建它,使您可以访问打包版本中尚未包含的功能。将其克隆到您的工作区中,确保使用 ros2-master 分支:

mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src/
git clone https://github.com/realsenseai/realsense-ros.git -b ros2-master
cd ~/ros2_ws

使用 rosdep 安装依赖项。--skip-keys=librealsense2 标志告诉 rosdep 不要再次尝试安装 librealsense2,因为您已经在上一步中安装了它:

sudo apt-get install python3-rosdep -y
sudo rosdep init
rosdep update
rosdep install -i --from-path src --rosdistro jazzy --skip-keys=librealsense2 -y

构建并获取工作区:

colcon build
source /opt/ros/jazzy/setup.bash
cd ~/ros2_ws
. install/local_setup.bash


realsense_d435_1.png


更新固件

librealsense 附带固件更新工具rs-fw-update,安装 SDK 后即可使用。检查相机当前的固件版本:

rs-fw-update -l
Connected devices:
1) [USB] Intel RealSense D435 s/n 827112070867, update serial number: 823313020158, firmware version: 5.17.3.10

将此与 latest D400 series firmware release 进行比较。如果有新版本可用,请在 SBC 模式下使用VENTUNO Q本身的浏览器直接下载它,这将引导您完成所需的许可协议并下载包含Signed_Image_UVC_<version>.bin文件的压缩文件,默认情况下到~/Downloads。

提取固件文件:

cd ~/Downloads
unzip d400_series_production_fw_<version>.zip

由于只连接一台相机,直接通过路径更新即可,无需序列号。该工具需要sudo,并且由于sudo默认重置环境,因此需要显式传递库路径:

sudo LD_LIBRARY_PATH=/opt/ros/jazzy/lib/aarch64-linux-gnu /opt/ros/jazzy/bin/rs-fw-update -f ~/Downloads/Signed_Image_UVC_<version>.bin

更新过程中请勿断开相机连接。

sudo LD_LIBRARY_PATH=/opt/ros/jazzy/lib/aarch64-linux-gnu /opt/ros/jazzy/bin/rs-fw-update -r -f ~/Downloads/Signed_Image_UVC_<version>.bin

警告:

如果更新被中断,例如由于缺少库路径而导致命令中途失败,则相机可以处于恢复模式,在该模式下,它仅响应固件命令而不响应正常操作。如果稍后 rs-fw-update 报告 Device is in recovery mode, use -r to recover,请重新运行相同的命令并添加 -r 标志:

成功后,该工具会报告更新完成并且设备重新连接:

Update to FW: /home/arduino/Downloads/Signed_Image_UVC_5_17_3_10.bin
No recovery devices were found!
Warning! the camera is connected via USB 2 port, in case the process fails, connect the camera to a USB 3 port and try again
Updating device FW: 
[USB] Intel RealSense D435 s/n 827112070867, update serial number: 823313020158, firmware version: 5.17.3.10
Firmware update started. Please don't disconnect device!
Firmware update done
Waiting for device to reconnect...
Device 827112070867 successfully updated to FW: 5.17.3.10

在未连接相机的情况下验证安装

在连接相机之前,您可以检查安装本身是否正常工作。启动未连接设备的节点:

ros2 launch realsense2_camera rs_launch.py

在没有连接摄像头的情况下,节点启动、报告其版本并在等待设备时重复发出警告:

[INFO] [camera.camera]: RealSense ROS v4.58.3
[INFO] [camera.camera]: Built with LibRealSense v2.58.1
[WARN] [camera.camera]: No RealSense devices were found!

这验证了节点本身是否已安装并正确运行,它只是在等待设备。警告每隔几秒重复一次,直到连接相机或节点因 Ctrl+C 停止。

您还可以检查启动文件的可用参数,包括下面介绍的pointcloud.enable和align_depth.enable:

ros2 launch realsense2_camera rs_launch.py --show-args

启动相机节点

您可以直接启动节点:

ros2 run realsense2_camera realsense2_camera_node


realsense_d435_3.png


或者使用启动文件,这是推荐的方式,因为它公开了方便的参数:

ros2 launch realsense2_camera rs_launch.py

连接相机后,节点报告检测到的设备并打开其默认流:

[INFO] [camera.camera]: Device with name Intel RealSense D435 was found.
[INFO] [camera.camera]: Device USB type: 3.2
[INFO] [camera.camera]: Set ROS param depth_module.depth_profile to default: 848x480x30
[INFO] [camera.camera]: Set ROS param depth_module.infra_profile to default: 848x480x30
[INFO] [camera.camera]: Set ROS param rgb_camera.color_profile to default: 640x480x30
[INFO] [camera.camera]: RealSense Node Is Up!


realsense_d435_2.png


摄像机名称和主题结构

默认情况下,如果您未设置 camera_name 或 camera_namespace,节点将同时使用 camera,从而生成名为 /camera/camera 的节点以及嵌套在 /camera/camera/ 下的主题。了解这一点很重要,因为它会影响您以后将使用的每个主题名称。使用默认设置并连接 D435 时,您将看到的主题包括:

/camera/camera/color/image_raw
/camera/camera/color/camera_info
/camera/camera/color/metadata
/camera/camera/depth/image_rect_raw
/camera/camera/depth/camera_info
/camera/camera/depth/metadata
/camera/camera/extrinsics/depth_to_color
/camera/camera/extrinsics/depth_to_depth

与 USB 网络摄像头一样,RealSense 节点也通过 image_transport 自动发布每个图像流的压缩变体,例如 /camera/camera/color/image_raw/compressed、.../theora 和 .../zstd,无需任何额外配置。

如果您设置自定义 camera_name 和 camera_namespace,例如 camera_namespace:=robot1 camera_name:=D455_1,则主题将嵌套在 /robot1/D455_1/ 下。

启用点云和深度对齐

默认情况下,enable_color和enable_depth为true,但点云不会自动生成。

大多数 3D 绘图工具(例如 RTABMap)都需要深度对齐,可以在启动时直接启用:

ros2 launch realsense2_camera rs_launch.py align_depth.enable:=true


realsense_d435_4.png


将深度与颜色对齐使得深度图像中的每个像素对应于彩色图像中的相同像素。它在/camera/camera/aligned_depth_to_color/image_raw上发布对齐的流。

警告:

在 Realsense-ros 的 VENTUNO Q ARM64 版本上,点云过滤器在内部注册为 pointcloud__neon_(NEON 优化变体),而不是大多数 RealSense 文档中使用的标准 pointcloud 名称。一旦节点已经运行,就可以在运行时使用相应的参数名称启用它。

在节点已经运行的情况下,通过在运行时直接设置正确的参数来启用点云:

ros2 param set /camera/camera pointcloud__neon_.enable true

设置此参数后,将出现/camera/camera/depth/color/points主题。您可以随时通过列出运行节点上的所有pointcloud相关参数来检查构建中的确切参数名称:

ros2 param list /camera/camera | grep pointcloud


realsense_d435_5.png


默认情况下,此构建上的点云仅发布几何体、x、y、z和强度,没有颜色数据,即使颜色流正在运行也是如此。这可以通过直接检查消息字段来验证:

ros2 topic echo /camera/camera/depth/color/points --no-arr

纯几何云报告 fields: length: 3 和 point_step: 16。要将颜色组合到点云中,请设置流过滤器以显式选择颜色流:

ros2 param set /camera/camera pointcloud__neon_.stream_filter 2

此后,现在包含显示颜色数据的相同现场检查报告fields: length: 4和point_step: 20。在 RViz2 中,PointCloud2 显示器的颜色转换器现在将提供 RGB8 作为选项,允许您以实际捕获的颜色而不是强度梯度查看云。

USB 带宽和显示共享

在调整分辨率之前,您可以直接从终端检查相机连接的是哪一代 USB:

lsusb -t

寻找RealSense出现的巴士。报告5000M或10000M的总线是USB 3.x,报告480M的总线是USB 2.x:


realsense_d435_lsusb_t.png


深度和颜色维护单独、独立的有效配置文件列表,因此直接查询两者,而不是假设分辨率对两个流都有效:

ros2 param describe /camera/camera depth_module.depth_profile


realsense_d435_6_1.png


ros2 param describe /camera/camera rgb_camera.color_profile


realsense_d435_6_2.png


在两个流上以较低的分辨率启动。例如,在 D435 上:

ros2 launch realsense2_camera rs_launch.py \
  align_depth.enable:=true \
  depth_module.depth_profile:=480x270x15 \
  rgb_camera.color_profile:=424x240x15


realsense_d435_usb32_reduced_profile.png


然后像以前一样重新启用点云:

ros2 param set /camera/camera pointcloud__neon_.enable true

在此分辨率下,颜色流保持稳定的 15 Hz:


realsense_d435_usb32_hz.png


说明:

如果节点在启动时报告Device USB type: 2.1,请检查相机的固件是否是最新的,请参阅上面的更新固件 section。在这种降低的分辨率下,USB 3.x 连接可在该板上测量出最一致的结果,具有更严格的帧时序,并且在持续使用过程中不会出现连接丢失的情况。

验证主题

当节点运行时,打开第二个终端并列出活动主题:

ros2 topic list | grep camera

检查彩色图像的发布率:

ros2 topic hz /camera/camera/color/image_raw


realsense_d435_7.png


/camera/camera/depth/color/points主题将3D点云作为sensor_msgs/PointCloud2消息携带,并且是RTABMap用于3D SLAM的消费主题。在VENTUNO Q上,该主题仅在运行时设置pointcloud__neon_.enable后出现,如上所述。

通过连接到VENTUNO Q的监视器,您可以使用rqt_image_view可视化颜色流:

sudo apt install ros-jazzy-rqt-image-view
ros2 run rqt_image_view rqt_image_view


realsense_d435_8.png


realsense_d435_9.png


从窗口顶部的主题下拉列表中选择/camera/camera/color/image_raw。特别是对于点云,使用RViz2 with a ⟦C1⟧ display设置为/camera/camera/depth/color/points主题,并将颜色转换器设置为RGB8以查看实际的相机颜色而不是强度梯度。


realsense_d435_10.png


此完整序列、降低的分辨率、pointcloud__neon_.enable 和 pointcloud__neon_.stream_filter:=2,在 RViz2 中在近距离连接到 VENTUNO Q 的物理 D435 上产生稳定、正确着色的 3D 重建。在典型的房间尺度距离下,降低的分辨率将产生更稀疏的云,因为总体捕获的点更少,但应用相同的步骤。

RViz2 中的可视化传感器

您可以手动打开 RViz2 以可视化彩色图像或点云:

ros2 run rviz2 rviz2


realsense_d435_rviz2.gif


对于彩色图像,添加图像显示并将其主题设置为/camera/camera/color/image_raw。对于点云,添加 PointCloud2 显示并将其主题设置为/camera/camera/depth/color/points。

故障排除

如果librealsense与ROS包装器冲突或产生版本不匹配错误,请确保您仅通过本教程中描述的三种方法之一安装SDK,而不是多种。将 Debian 软件包安装与源代码构建混合在一起是导致此问题的最常见原因。

如果rosdep install报告找不到RealSense包装器的软件包,请确保您通过了--skip-keys=librealsense2,否则rosdep将尝试通过可能与您已安装的内容冲突的方法重新安装SDK。

总结

在本教程中,您在VENTUNO Q上构建了RealSense SDK和ROS包装器,并将颜色、深度和点云数据发布为ROS 2主题。这些主题是标准的ROS 2消息类型,可以直接由本系列其余部分中的 SLAM、导航和 AI 节点使用。

后续步骤

随着深度数据流经 ROS 2 主题,您可以继续进行 3D 绘图或探索其他感知传感器:

致谢

ROS 是 Open Source Robotics Foundation 的商标。本教程仅用于教育目的,帮助用户在 Arduino 硬件上学习 ROS 2。本内容并不意味着 Arduino 与 Open Source Robotics Foundation 之间存在背书、合作或隶属关系。

支持

在使用 VENTUNO Q 过程中如遇问题或有疑问,我们提供多种支持资源帮助你找到答案与解决方案。

帮助中心

浏览我们的帮助中心,其中提供大量面向 VENTUNO Q 的文章与指南。Arduino 帮助中心旨在提供深入的技术支持,帮助你充分发挥设备潜力。

论坛

加入我们的社区论坛,与其他用户交流、分享经验并提问。

联系我们

若需要个性化协助,或有上述帮助与支持资源未涵盖的问题,请联系我们的支持团队。


原文:https://docs.arduino.cc/tutorials/ventuno-q/ros2-perception-rgbd-cam/ 本页为 Arduino 官方教程的中文翻译,供内部查阅。命令与代码保持原文。