当前位置: 代码迷 >> 综合 >> Intel RealSense D435i 及ROS
  详细解决方案

Intel RealSense D435i 及ROS

热度:60   发布时间:2023-12-09 03:02:53.0

主机系统 Ubuntu18.04 ROS2系统Melodic 

参考文章:

https://dev.intelrealsense.com/docs/ros-wrapper 

https://idorobotics.com/2018/11/02/integrating-the-intel-realsense-d435-with-ros/

 

参看前文,已经搭建好ROS2的系统,~/workspace/robot1.0创建了工作区。

1、PC配置摄像头

查看ubuntu内核版本符合要求

~/workspace/robot1.0/src$ cat /proc/version
Linux version 5.4.0-58-generic (buildd@lgw01-amd64-040) (gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)) #64~18.04.1-Ubuntu SMP Wed Dec 9 17:11:11 UTC 2020
采取安装包形式进行配置

~/workspace/robot1.0$ sudo apt-key adv --keyserver keys.gnupg.net --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE || sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE

~/workspace/robot1.0$ sudo add-apt-repository "deb http://realsense-hw-public.s3.amazonaws.com/Debian/apt-repo bionic main" -u

~/workspace/robot1.0$ sudo apt-get install librealsense2-dkms

~/workspace/robot1.0$ sudo apt-get install librealsense2-utils

~/workspace/robot1.0$ sudo apt-get install librealsense2-dev

~/workspace/robot1.0$ sudo apt-get install librealsense2-dbg

运行测试 realsense-viewer 无视频输出。看资料,不确定是否是安装的时候链接了摄像头的原因。

返回到安装前的快照,摄像头不能和电脑链接。

sudo apt-get update

sudo apt-get install git libssl-dev libusb-1.0-0-dev pkg-config libgtk-3-dev

sudo apt-get install libglfw3-dev

~/Downloads/librealsense-2.41.0$ sudo cp config/99-realsense-libusb.rules /etc/udev/rules.d/

sudo udevadm control --reload-rules && udevadm trigger

构建并修补内核模块,耗时较长

~/Downloads/librealsense-2.41.0$ ./scripts/patch-realsense-ubuntu-lts.sh 或者执行 ./scripts/patch-ubuntu-kernel-4.16.sh 

mkdir build && cd build

librealsense-2.41.0/build$ cmake ../ -DBUILD_EXAMPLES=true
sudo make uninstall && make clean && make && sudo make install

查看摄像头链接:librealsense-2.41.0/build$ lsusb

执行pc端数据回看:librealsense-2.41.0/build$ sudo realsense-viewer

2、在ros中配置realsense

:~/workspace/robot1.0/src$ ls
CMakeLists.txt   ydlidar
参看https://github.com/IntelRealSense/realsense-ros 

robot1.0/src$ git clone https://github.com/IntelRealSense/realsense-ros.git

robot1.0/src/realsense-ros$ git checkout `git tag | sort -V | grep -P "^2.\d+\.\d+" | tail -1`

需要安装make sure that the ros package *ddynamic_reconfigure* is installed

 https://mp.weixin.qq.com/s?src=11&timestamp=1609383689&ver=2799&signature=CC*9iTfRid2IH1fJeXYvdo00mfdO2RjSEle3JFJRKkgkcnDbBRY08DaCpTsF9fqke0fILH8NThWK8aduAw89KkSYnTcPu-hZt6CiT2TkcKsG27wZ2uQmE53Imt8g4yG3&new=1

注意,此处是 ~/workspace/robot1.0$ sudo apt-get install -y ros-$ROS_DISTRO-ddynamic-reconfigure

~/workspace/robot1.0$ catkin_make clean
Base path: /home/robot123/workspace/robot1.0
Source space: /home/robot123/workspace/robot1.0/src
Build space: /home/robot123/workspace/robot1.0/build
Devel space: /home/robot123/workspace/robot1.0/devel
Install space: /home/robot123/workspace/robot1.0/install
####
#### Running command: "make cmake_check_build_system" in "/home/robot123/workspace/robot1.0/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/robot123/workspace/robot1.0/devel
-- Using CMAKE_PREFIX_PATH: /home/robot123/workspace/robot1.0/devel;/opt/ros/melodic
-- This workspace overlays: /home/robot123/workspace/robot1.0/devel;/opt/ros/melodic
-- Using PYTHON_EXECUTABLE: /usr/bin/python2
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: False
-- catkin 0.7.29
-- BUILD_SHARED_LIBS is on
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 3 packages in topological order:
-- ~~  - realsense2_description
-- ~~  - realsense2_camera
-- ~~  - ydlidar
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'realsense2_description'
-- ==> add_subdirectory(realsense-ros/realsense2_description)
-- +++ processing catkin package: 'realsense2_camera'
-- ==> add_subdirectory(realsense-ros/realsense2_camera)
-- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy
-- Create Release Build.
-- realsense2_camera: 2 messages, 0 services
-- +++ processing catkin package: 'ydlidar'
-- ==> add_subdirectory(ydlidar)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/robot123/workspace/robot1.0/build
####
#### Running command: "make clean -j2 -l2" in "/home/robot123/workspace/robot1.0/build"
####

:~/workspace/robot1.0$ catkin_make -DCATKIN_ENABLE_TESTING=False -DCMAKE_BUILD_TYPE=Release

:~/workspace/robot1.0$ catkin_make install

3、在ros中使用camera

:~/workspace/robot1.0$ roslaunch realsense2_camera rs_camera.launch
... logging to /home/robot123/.ros/log/1535df78-4b16-11eb-8263-000c295f38e0/roslaunch-ubuntu-63353.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://ubuntu:44961/

SUMMARY
========

PARAMETERS
 * /camera/realsense2_camera/accel_fps: 250
 * /camera/realsense2_camera/accel_frame_id: camera_accel_frame
 * /camera/realsense2_camera/accel_optical_frame_id: camera_accel_opti...
 * /camera/realsense2_camera/align_depth: False
 * /camera/realsense2_camera/aligned_depth_to_color_frame_id: camera_aligned_de...
 * /camera/realsense2_camera/aligned_depth_to_fisheye1_frame_id: camera_aligned_de...
 * /camera/realsense2_camera/aligned_depth_to_fisheye2_frame_id: camera_aligned_de...
 * /camera/realsense2_camera/aligned_depth_to_fisheye_frame_id: camera_aligned_de...
 * /camera/realsense2_camera/aligned_depth_to_infra1_frame_id: camera_aligned_de...
 * /camera/realsense2_camera/aligned_depth_to_infra2_frame_id: camera_aligned_de...
 * /camera/realsense2_camera/allow_no_texture_points: False
 * /camera/realsense2_camera/base_frame_id: camera_link
 * /camera/realsense2_camera/calib_odom_file: 
 * /camera/realsense2_camera/clip_distance: -2.0
 * /camera/realsense2_camera/color_fps: 30
 * /camera/realsense2_camera/color_frame_id: camera_color_frame
 * /camera/realsense2_camera/color_height: 480
 * /camera/realsense2_camera/color_optical_frame_id: camera_color_opti...
 * /camera/realsense2_camera/color_width: 640
 * /camera/realsense2_camera/depth_fps: 30
 * /camera/realsense2_camera/depth_frame_id: camera_depth_frame
 * /camera/realsense2_camera/depth_height: 480
 * /camera/realsense2_camera/depth_optical_frame_id: camera_depth_opti...
 * /camera/realsense2_camera/depth_width: 640
 * /camera/realsense2_camera/device_type: 
 * /camera/realsense2_camera/enable_accel: False
 * /camera/realsense2_camera/enable_color: True
 * /camera/realsense2_camera/enable_depth: True
 * /camera/realsense2_camera/enable_fisheye1: False
 * /camera/realsense2_camera/enable_fisheye2: False
 * /camera/realsense2_camera/enable_fisheye: False
 * /camera/realsense2_camera/enable_gyro: False
 * /camera/realsense2_camera/enable_infra1: False
 * /camera/realsense2_camera/enable_infra2: False
 * /camera/realsense2_camera/enable_infra: False
 * /camera/realsense2_camera/enable_pointcloud: False
 * /camera/realsense2_camera/enable_pose: False
 * /camera/realsense2_camera/enable_sync: False
 * /camera/realsense2_camera/filters: 
 * /camera/realsense2_camera/fisheye1_frame_id: camera_fisheye1_f...
 * /camera/realsense2_camera/fisheye1_optical_frame_id: camera_fisheye1_o...
 * /camera/realsense2_camera/fisheye2_frame_id: camera_fisheye2_f...
 * /camera/realsense2_camera/fisheye2_optical_frame_id: camera_fisheye2_o...
 * /camera/realsense2_camera/fisheye_fps: 30
 * /camera/realsense2_camera/fisheye_frame_id: camera_fisheye_frame
 * /camera/realsense2_camera/fisheye_height: 480
 * /camera/realsense2_camera/fisheye_optical_frame_id: camera_fisheye_op...
 * /camera/realsense2_camera/fisheye_width: 640
 * /camera/realsense2_camera/gyro_fps: 400
 * /camera/realsense2_camera/gyro_frame_id: camera_gyro_frame
 * /camera/realsense2_camera/gyro_optical_frame_id: camera_gyro_optic...
 * /camera/realsense2_camera/imu_optical_frame_id: camera_imu_optica...
 * /camera/realsense2_camera/infra1_frame_id: camera_infra1_frame
 * /camera/realsense2_camera/infra1_optical_frame_id: camera_infra1_opt...
 * /camera/realsense2_camera/infra2_frame_id: camera_infra2_frame
 * /camera/realsense2_camera/infra2_optical_frame_id: camera_infra2_opt...
 * /camera/realsense2_camera/infra_fps: 30
 * /camera/realsense2_camera/infra_height: 480
 * /camera/realsense2_camera/infra_rgb: False
 * /camera/realsense2_camera/infra_width: 640
 * /camera/realsense2_camera/initial_reset: False
 * /camera/realsense2_camera/json_file_path: 
 * /camera/realsense2_camera/linear_accel_cov: 0.01
 * /camera/realsense2_camera/odom_frame_id: camera_odom_frame
 * /camera/realsense2_camera/pointcloud_texture_index: 0
 * /camera/realsense2_camera/pointcloud_texture_stream: RS2_STREAM_COLOR
 * /camera/realsense2_camera/pose_frame_id: camera_pose_frame
 * /camera/realsense2_camera/pose_optical_frame_id: camera_pose_optic...
 * /camera/realsense2_camera/publish_odom_tf: True
 * /camera/realsense2_camera/publish_tf: True
 * /camera/realsense2_camera/rosbag_filename: 
 * /camera/realsense2_camera/serial_no: 
 * /camera/realsense2_camera/tf_publish_rate: 0.0
 * /camera/realsense2_camera/topic_odom_in: odom_in
 * /camera/realsense2_camera/unite_imu_method: 
 * /camera/realsense2_camera/usb_port_id: 
 * /rosdistro: melodic
 * /rosversion: 1.14.10

NODES
  /camera/
    realsense2_camera (nodelet/nodelet)
    realsense2_camera_manager (nodelet/nodelet)

auto-starting new master

数据应参考 https://github.com/IntelRealSense/realsense-ros 中 Launch parameters部分 

或者 https://github.com/IntelRealSense/librealsense/blob/master/doc/post-processing-filters.md

在另外一个终端执行 :~/workspace/robot1.0$ rostopic list
/camera/color/camera_info
/camera/color/image_raw
/camera/color/image_raw/compressed
/camera/color/image_raw/compressed/parameter_descriptions
/camera/color/image_raw/compressed/parameter_updates
/camera/color/image_raw/compressedDepth
/camera/color/image_raw/compressedDepth/parameter_descriptions
/camera/color/image_raw/compressedDepth/parameter_updates
/camera/color/image_raw/theora
/camera/color/image_raw/theora/parameter_descriptions
/camera/color/image_raw/theora/parameter_updates
/camera/depth/camera_info
/camera/depth/image_rect_raw
/camera/depth/image_rect_raw/compressed
/camera/depth/image_rect_raw/compressed/parameter_descriptions
/camera/depth/image_rect_raw/compressed/parameter_updates
/camera/depth/image_rect_raw/compressedDepth
/camera/depth/image_rect_raw/compressedDepth/parameter_descriptions
/camera/depth/image_rect_raw/compressedDepth/parameter_updates
/camera/depth/image_rect_raw/theora
/camera/depth/image_rect_raw/theora/parameter_descriptions
/camera/depth/image_rect_raw/theora/parameter_updates
/camera/extrinsics/depth_to_color
/camera/motion_module/parameter_descriptions
/camera/motion_module/parameter_updates
/camera/realsense2_camera_manager/bond
/camera/rgb_camera/auto_exposure_roi/parameter_descriptions
/camera/rgb_camera/auto_exposure_roi/parameter_updates
/camera/rgb_camera/parameter_descriptions
/camera/rgb_camera/parameter_updates
/camera/stereo_module/auto_exposure_roi/parameter_descriptions
/camera/stereo_module/auto_exposure_roi/parameter_updates
/camera/stereo_module/parameter_descriptions
/camera/stereo_module/parameter_updates
/diagnostics
/rosout
/rosout_agg
/tf
/tf_static

或者运行 

roslaunch realsense2_camera rs_camera.launch filters:=pointcloud

再运行 rviz 查看结果。若先运行rviz,应先执行roscore

robot123@ubuntu:~$ rosrun rviz rviz
[ INFO] [1609385280.913982817]: rviz version 1.13.15
[ INFO] [1609385280.914038971]: compiled against Qt version 5.9.5
[ INFO] [1609385280.914069347]: compiled against OGRE version 1.9.0 (Ghadamon)
[ INFO] [1609385280.917618740]: Forcing OpenGl version 0.
[ INFO] [1609385282.056520342]: Stereo is NOT SUPPORTED
[ INFO] [1609385282.056899257]: OpenGl version: 3.3 (GLSL 3.3).
robot123@ubuntu:~$ 

 

 

  相关解决方案