前言

Intel RealSense D435i是一款带有IMU(惯性测量单元)的深度相机,广泛应用于SLAM、视觉导航等领域。本文记录在ROS2环境下的安装与使用方法。

驱动安装

详细的驱动安装步骤可以参考:CSDN教程

简要步骤:

1. 安装依赖

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

2. 安装ROS2包装

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

3. 验证安装

连接相机后,运行:

1
realsense-viewer

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

ROS2使用

基本使用

发布影像和IMU数据的完整命令:

1
2
3
4
5
6
7
8
9
10
11
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 \
accel_fps:=200 \
depth_module.infra_profile:=640,480,30

参数说明

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

常用配置

仅发布双目红外图像和IMU数据(适合VIO)

1
2
3
4
5
6
7
8
9
10
11
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 \
accel_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

运行时配置

关闭激光发射器

在某些场景下(如使用双目相机进行室外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 RGB彩色图像
/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查看相机数据:

1
rviz2

在RViz2中添加相应的显示项:

  • Image:查看红外/彩色图像
  • PointCloud2:查看点云数据(需启用深度相机)
  • TF:查看坐标系关系

性能优化建议

  1. 根据需求选择数据流:不需要的数据流禁用可以降低CPU占用
  2. 调整帧率和分辨率:降低帧率可以减少数据传输量
  3. 使用IMU融合:设置 unite_imu_method:=2 可以获得时间同步更好的IMU数据
  4. 关闭激光发射器:在室外或使用被动双目时关闭,节省电量

常见问题

1. 相机无法识别

检查USB连接和权限:

1
2
lsusb | grep Intel
realsense-viewer

2. ROS2无法启动相机

检查驱动安装:

1
dpkg -l | grep realsense

重新安装驱动:

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

3. IMU数据不同步

设置 unite_imu_method:=2 并重启相机节点。

4. 帧率不稳定

检查USB带宽,尝试使用USB 3.0接口,或降低帧率设置。

参考资源