Advertisement

Ubuntu18.04 ROS Kinect2

阅读量:

安装libfreenect2

github上的readme写的很详细了,一步步参考着来

  1. 下载
复制代码
    git clone https://github.com/OpenKinect/libfreenect2.git
    
    
      
    
    AI写代码

此步骤可参考官方文档完成安装。

简单记录一下:当时我是按照别人的博客配置软件的,默认步骤也都大致相同。需要注意的是,在安装18.04版本时需要执行sudo apt-get install libturbojpeg0-dev命令以避免"无法找到tubojpeg"的错误提示。

不过在实际操作中还会遇到无法找到libva、liba-drm以及tegrajpeg的情况。其他人提到过这种情况通常是因为没有安装libturbojpeg0-dev的原因。然而即便我已经安装好了该包但依然存在这些问题因此先暂时忽略这个问题也没报错。

  1. 编译
复制代码
    mkdir build && cd build
    #cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/freenect2   // 这是官方给出的
    cmake .. -DENABLE_CXX11=ON //我是没有设置这个路径,建议按上边的来
    make
    sudo make install
    
    #You need to specify cmake -Dfreenect2_DIR=$HOME/freenect2/lib/cmake/freenect2 for CMake based third-party application to find libfreenect2.
    
    
      
      
      
      
      
      
      
    
    AI写代码

在使用Cmake开发过程中遇到了一些常见的问题,在这个过程中我犯过的一个常见错误就是在将libfreenect2项目放置在包含中文字符的目录下时遇到了麻烦。具体来说是在构建过程中的CMakeDoxyfile.tpl模板无法被成功生成而导致系统抛出错误提示:无法打开指定的输出文件。经过一番排查发现这个问题的根本原因是由于路径配置的原因而产生的问题后来经过对项目的路径进行重新命名调整终于解决了这个问题

  • OpenGL相关警告:

cmake在处理OpenGL模块时生成了如下警告:

cmake notice (dev) at /home/y/.local/lib/python2.7/site-packages/cmake/data/share/cmake-3.18/Modules/FindOpenGL.cmake:305(message): Policy CMP0072 is not set: FindOpenGL prefers GLVND by preference when available. 如果您希望关闭此提示,请执行cmake --help-policy CMP0072以获取详细政策说明。

为了解决这个问题,请在CMakeLists中添加以下内容:

if block POLICY CMP0072
set( OpenGL_GL_Preference LEGACY )
endif block

这将确保当 policy CMP0072未设置时,默认选择GLVND作为OpenGL支持库。

  • make install过程中遇到了一个问题,大致意思是无法将内容复制至指定位置。这是因为缺乏执行权限,在make install过程中使用sudo指令就可以解决问题。
  1. Set up udev rules for device access: sudo cp ../platform/linux/udev/90-kinect2.rules /etc/udev/rules.d/, then replug the Kinect.重新插拔Kinect2.
  2. 测试
    Run the test program: build目录下
    ./bin/Protonect
    ./bin/Protonect cl
    ./bin/Protonect gl
    ./bin/Protonect cpu

安装iai-kinect2

  1. 下载、编译
复制代码
    cd ~/catkin_ws/src/
    git clone https://github.com/code-iai/iai_kinect2.git
    cd iai_kinect2
    rosdep install -r --from-paths . 
    cd ~/catkin_ws
    catkin_make -DCMAKE_BUILD_TYPE="Release"   //出现100%就是成功了
    
    
      
      
      
      
      
      
    
    AI写代码
  • 在运行rosdep install -r --from-paths . 会出现如下报错
复制代码
    ERROR: the following packages/stacks could not have their rosdep keys resolved
    to system dependencies:
    kinect2_viewer: Cannot locate rosdep definition for [kinect2_bridge]
    kinect2_bridge: Cannot locate rosdep definition for [kinect2_registration]
    kinect2_calibration: Cannot locate rosdep definition for [kinect2_bridge]
    Continuing to install resolvable dependencies...
    
    
      
      
      
      
      
      
    
    AI写代码

解决方案:无需理会此问题;如果不想忽视它,则可参考以下链接获取更多信息:https://answers.ros.org/question/237451/run-rosdep-install-r-from-paths-error-when-i-install-iai_kinect2/

(参考:https://github.com/code-iai/iai_kinect2/issues/296)
Maybe reading the README:
Note: rosdep will output errors on not being able to locate [kinect2_bridge] and [depth_registration].
That is fine because they are all part of the iai_kinect2 package and rosdep does not know these packages.

设置CMake编译类型为 Release。
需要注意的是,在 Home/freenect2 或 /usr/local 两个标准路径的情况下,默认配置即可;否则,请按照以下命令进行配置:
设置 CMake 编译类型为 Release 并指定 freenctct 的安装目录:
catkin_make -DCMAKE_BUILD_TYPE="Release" -Dfrenctct_DIR=HOME/FRENETCT/lcaytaylib/cmake/FRENETCT

我在catkin_make -DCMAKE_BUILD_TYPE="Release"这里出错,根据报错信息:

在这里插入图片描述

问题源于OpenCV版本不兼容。
解决方法如下:
首先,在iai-kinect2软件包中的kinect2_bridge、kinect2_calibration等四个目录下编辑CMakeLists文件。
找到其中的find_package(OpenCV REQUIRED)部分,并将其修改为find_package(OpenCV 3 REQUIRED)。
接下来,在配置时指定使用的OpenCV版本为3.2.0。
完成上述配置后,重新运行catkin_make命令以生成所需的构建文件。
尽管在构建过程中会遇到一些警告信息提示可能存在配置问题或依赖项不足的情况(例如缺少某些库或头文件),但最终构建过程能够顺利完成。

  1. 运行
复制代码
    roslaunch kinect2_bridge kinect2_bridge.launch   //在src下运行
    
    
      
    
    AI写代码

此问题出现在catkin_make处理之前
若该节点前的节点已成功运行,则此处问题不大

[ERROR] [1605063781.417458728]: 无法加载对应的nodelet组件 kinect2_bridge/kinect2_bridge_nodelet
[ERROR] [1605065349.856412161]: 在初始化Kinect2Bridge设备时出现异常
[ERROR] [1605065349.858918791]: 初始化过程出现异常

[FATAL] [1605065349.938611904]: 无法加载nodelet组件 'kinect2_bridge'到ros master节点kinect2
log file: /home/y/.ros/log/0eea346c-23ce-11eb-a8bc-002b676588cd/kinect2_bridge-*.log

当终端显示 [ INFO] [1605065815.596049840]: [Kinect2Bridge::callbackStatus] client connected. starting device... 时,则表明设备已准备好启动。

重新打开一个终端,输入rostopic list,可以看到:

/kinect2/bond
/kinect2/hd/camera_info
/kinect2/hd/image_color
/kinect2/hd/image_color/compressed
/kinect2/hd/image_color_rect
/kinect2/hd/image_color_rect/compressed
/kinect2/hd/image_depth_rect
/kinect2/hd/image_depth_rect/compressed
/kinect2/hd/image_mono
/kinect2/hd/image_mono/compressed
/kinect2/hd/image_mono_rect
/kinect2/hd/image_mono_rect/compressed
/kinect2/hd/points
/kinect2/qhd/camera_info
/kinect2/qhd/image_color
/kinect2/qhd/image_color/compressed
/kinect2/qhd/image_color_rect
/kinect2/qhd/image_color_rect/compressed
/kinect2/qhd/image_depth_rect
/kinect2/qhd/image_depth_rect/compressed
/kinect2/qhd/image_mono
/kinect2/qhd/image_mono/compressed
/kinect2/qhd/image_mono_rect
/kinect2/qhd/image_mono_rect/compressed
/kinect2/qhd/points
/kinect2/sd/camera_info
/kinect2/sd/image_color_rect
/kinect2/sd/image_color_rect/compressed
/kinect2/sd/image_depth
/kinect2/sd/image_depth/compressed
/kinect2/sd/image_depth_rect
/kinect2/sd/image_depth_rect/compressed
/kinect2/sd/image_ir
/kinect2/sd/image_ir/compressed
/kinect2/sd/image_ir_rect
/kinect2/sd/image_ir_rect/compressed
/kinect2/sd/points
/rosout
/rosout_agg

然后可以通过 rosrun kinect2_viewer kinect2_viewer 查看图像

全部评论 (0)

还没有任何评论哟~