jetson 连接 d435i(Intel(R) RealSense(TM) Cameras) 后,如何在 ros2 中使用?需要安装 librealsense 和 realsense-ros,本篇介绍如何安装它们。

安装 librealsense

首先请先查看 librealsense 的 github 网站,里面有关于 jetson 上配置的详细教程:https://github.com/IntelRealSense/librealsense/blob/master/doc/installation_jetson.md,主要命令如下:

1
2
3
4
5
6
7
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE || sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE

sudo add-apt-repository "deb https://librealsense.intel.com/Debian/apt-repo $(lsb_release -cs) main" -u

sudo apt-get install librealsense2-utils
sudo apt-get install librealsense2-dev

但是,需要注意的是,对于某些版本的 jetson,上面的安装方法无效,无法驱动 d435i 运行。具体的

For Jetson Orin™ with JetPack 6.0 you will need to follow build for MIPI driver as NVIDIA released Kernel 5.15 default configuration with disabled HID: Intel® RealSense™ camera driver for GMSL* interface

For Jetson Nano™ we strongly recommend enabling the Barrel Jack connector for extra power (See jetsonhacks.com/jetson-nano-use-more-power/ to learn how)

此时,需要先卸载上面方式安装的驱动包,手动编译安装,编译方式可参考上面的 librealsense github 网站,也可以使用另一个仓库:jetsonhacks/installRealSenseSDK

1
2
3
4
5
6
7
8
9
10
11
12
13
# 卸载上面方式安装的 librealsense2
sudo dpkg -l | grep "realsense" | cut -d " " -f 3 | xargs sudo dpkg --purge

# 编译安装指定版本的 librealsense2,建议以 root 用户编译
sudo -i
git clone https://github.com/jetsonhacks/installRealSenseSDK.git
cd installRealSenseSDK
# 编译方式如下,默认使用 CUDA
# ./buildLibrealsense.sh [ -v | --version <version> ] [ -j | -jobs <number of jobs> ] [ -n | --no_cuda ]
$ ./buildLibrealsense.sh -v v2.55.1 -j 8

# 安装后会输出安装路径,同时会在 installRealSenseSDK 同目录下创建 librealsense 用于编译,可删除或重新编译安装时须先删除

安装完成后,就可以使用 realsense-viewer,如果打开后左上角没有打开页面,那么需要重新编译安装。

安装 realsense-ros

安装 realsense-ros 需要和 librealsense 版本对应,不然,无法在 ros2 中使用,会提示找不到设备。上面安装的 librealsense 版本是 2.55.1(也可以在使用 realsense-viewer时查看),对应的 realsense-ros 版本为 v4.54.1。如果不关注版本对应,直接使用下面的简单方式安装,那么可能会导致无法使用:

1
2
3
4
5
6
7
8
# 配置  Ubuntu repositories
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

sudo apt install curl # if you haven't already installed curl
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -

# 安装,这里以 humble 为例
sudo apt install ros-humble-realsense2-*

如果上面的安装方式,无法在 ros2 中使用 d435i,那么可以使用下面的编译方式安装:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 首先卸载上面安装的包
sudo dpkg -l | grep "ros-humble-realsense2" | cut -d " " -f 3 | xargs sudo dpkg --purge

# 编译安装
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src/

git clone https://github.com/IntelRealSense/realsense-ros.git -b 4.54.1
cd ~/ros2_ws

sudo apt-get install python3-rosdep -y
sudo rosdep init # "sudo rosdep init --include-eol-distros" for Foxy and earlier
rosdep update # "sudo rosdep update --include-eol-distros" for Foxy and earlier
rosdep install -i --from-path src --rosdistro humble --skip-keys=librealsense2 -y # ROS_DISTRO: iron, humble, foxy

colcon build

source /opt/ros/humble/setup.bash
cd ~/ros2_ws
. install/local_setup.bash

安装成功后,就可以使用了,测试:

1
ros2 launch realsense2_camera rs_launch.py enable_rgbd:=true enable_sync:=true align_depth.enable:=true enable_color:=true enable_depth:=true

参考文献

  1. NVIDIA® Jetson™ Devices
  2. IntelRealSense/librealsense
  3. IntelRealSense/realsense-ros
  4. Installation Ubuntu Sources
  5. jetsonhacks/installRealSenseSDK
  6. Intel RealSense D435i:简介、安装与使用(ROS、Python)
  7. 常见安装错误 Hardware Setup