前言

Intel RealSense D435i 是一款带 IMU 的深度相机,常用于 SLAM、VIO、视觉导航等任务。本文记录在 Ubuntu 22.04 + ROS2 Humble 环境下的安装、启动和常见问题处理。

一、安装驱动

1. 添加软件源

1
2
3
4
5
6
# 添加 GPG key
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys FB0B24895113F120
sudo apt-key export FB0B24895113F120 | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/librealsense.gpg

# 添加 RealSense 软件源
echo 'deb [signed-by=/etc/apt/trusted.gpg.d/librealsense.gpg] https://librealsense.intel.com/Debian/apt-repo jammy main' | sudo tee /etc/apt/sources.list.d/librealsense.list

2. 安装 librealsense

1
2
sudo apt update
sudo apt install -y librealsense2-dkms librealsense2-utils librealsense2-dev librealsense2-dbg

3. 安装 ROS2 驱动包

1
sudo apt install -y ros-humble-realsense2-camera

4. 验证安装

连接相机后运行:

1
realsense-viewer

如果可以看到相机图像和 IMU 数据,说明驱动安装成功。

更详细的驱动安装说明可参考:CSDN教程

二、ROS2 启动方式

VIO 常用配置:双目红外 + IMU

适合 VINS-Fusion、OpenVINS 等视觉惯性算法:

1
2
3
4
5
6
7
8
9
10
ros2 launch realsense2_camera rs_launch.py \
enable_color:=false \
enable_depth:=false \
enable_infra1:=true \
enable_infra2:=true \
enable_accel:=true \
enable_gyro:=true \
unite_imu_method:=2 \
gyro_fps:=200 \
depth_module.infra_profile:=640,480,30

RGB-D 配置

适合需要彩色图像和深度图像的任务:

1
2
3
4
5
6
7
ros2 launch realsense2_camera rs_launch.py \
enable_color:=true \
enable_depth:=true \
enable_infra1:=false \
enable_infra2:=false \
enable_accel:=false \
enable_gyro:=false

默认配置

不指定参数时,使用驱动默认配置:

1
ros2 launch realsense2_camera rs_launch.py

三、常用参数

参数 说明 常用值
enable_color 是否启用彩色相机 true / false
enable_depth 是否启用深度相机 true / false
enable_infra1 是否启用左红外相机 true / false
enable_infra2 是否启用右红外相机 true / false
enable_accel 是否启用加速度计 true / false
enable_gyro 是否启用陀螺仪 true / false
unite_imu_method IMU 融合方式:0 不融合,1 线性插值,2 拷贝 2
gyro_fps 陀螺仪采样率 200
accel_fps 加速度计采样率 200
depth_module.infra_profile 红外图像分辨率和帧率 640,480,30

四、运行时设置

关闭激光发射器

室外 VIO 或被动双目场景中,通常需要关闭激光投影器:

1
ros2 param set /camera/camera depth_module.emitter_enabled 0

查看可用参数

1
ros2 param list /camera/camera

修改参数

1
ros2 param set /camera/camera <参数名> <参数值>

五、常用话题

相机启动后,常用话题如下:

话题名 消息类型 说明
/camera/infra1/image_raw sensor_msgs/msg/Image 左红外图像
/camera/infra2/image_raw sensor_msgs/msg/Image 右红外图像
/camera/color/image_raw sensor_msgs/msg/Image 彩色图像
/camera/depth/image_rect_raw sensor_msgs/msg/Image 深度图像
/camera/accel/sample sensor_msgs/msg/Imu 加速度计数据
/camera/gyro/sample sensor_msgs/msg/Imu 陀螺仪数据
/camera/imu sensor_msgs/msg/Imu 融合后的 IMU 数据

六、RViz2 可视化

启动 RViz2:

1
rviz2

常用显示项:

  • Image:查看红外图像、彩色图像
  • PointCloud2:查看点云,需要启用深度相机
  • TF:查看相机坐标系关系

七、性能优化

  • 按需开启数据流,不用的彩色、深度或红外数据可以关闭。
  • 适当降低分辨率和帧率,减少 USB 带宽和 CPU 占用。
  • VIO 场景建议设置 unite_imu_method:=2,使用融合后的 IMU 话题。
  • 室外或被动双目场景建议关闭激光发射器。

八、常见问题

1. 相机无法识别

检查 USB 连接和设备识别情况:

1
2
lsusb | grep Intel
realsense-viewer

优先使用 USB 3.0 接口,并避免通过低质量扩展坞连接。

2. ROS2 无法启动相机

检查 RealSense 相关包是否已安装:

1
dpkg -l | grep realsense

必要时重新安装 ROS2 驱动包:

1
sudo apt install --reinstall ros-humble-realsense2-camera

3. IMU 数据不同步

启动时加入:

1
unite_imu_method:=2

然后重启相机节点。

4. 帧率不稳定

常见原因是 USB 带宽不足。可以尝试:

  • 使用 USB 3.0 接口
  • 降低图像分辨率
  • 降低帧率
  • 关闭暂时不用的数据流

参考资源