【学习SLAM】ROS下使用USB摄像机/ORB_SLAM2配置

  • Post author:
  • Post category:其他



先测试一下usb摄像头

打开摄像头,需要启动ros,在两个不同的终端分别执行以下命令:

$ roscore
 
source ~/catkin_ws/devel/setup.bashroslaunch usb_cam usb_cam-test.launch


具体的步骤

首先开个新的终端,运行roscore


$ roscore

在运行该节点之前,需要先配置一下

节点

参数,打开src/usb_cam/launch下的launch文件,我这里只需要该设备号即可,笔记本电脑的video0一般是网络摄像头,插入usb摄像头一般是video1,若想看usb摄像头是哪个端口号,可cd到根目录中的dev文件夹下查看.

这样,就能启动摄像头了,其中,我们可以打开位于usb_cam/launch下的launch文件:

<launch>
  <node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" >
    <param name="video_device" value="/dev/video0" />
    <param name="image_width" value="640" />
    <param name="image_height" value="480" />
    <param name="pixel_format" value="yuyv" />
    <param name="camera_frame_id" value="usb_cam" />
    <param name="io_method" value="mmap"/>
  </node>
  <node name="image_view" pkg="image_view" type="image_view" respawn="false" output="screen">
    <remap from="image" to="/usb_cam/image_raw"/>
    <param name="autosize" value="true" />
  </node>
</launch>

其中value=”/dev/video0″为笔记本摄像头,这里为video1,当然读者可以去/dev目录下查看自己的摄像头对应的value是多少。

想要查看当前连接设备,使用如下命令即可:

ls /dev/video*


更改后,其实只是换了个1

完成之后再开一个新的终端, 运行

source ~/catkin_ws/devel/setup.bash
 roslaunch usb_cam usb_cam-test.launch 


运行后,正常的情况下可打开摄像头,看到新建窗口将图像信息显示出来.同时命令窗口会有一部分warning ,直观显示是没有找到head_camera.yaml,应该是相机标定后的内参信息,我尝试将标定(标定之后也会说)后的数据写入yaml文件中让程序去读,打开失败,猜测应该是我的yaml文件中参数命名或者其他原因与程序不符合,因为还没有开始扒源码,暂且放一放,立个flag在这。

这里写图片描述

(打开新的终端)运行rqt_graph

(打开新的终端)运行rqt_graph可以看usb_cam节点向/usb_cam/image_raw发布了消息,image_view订阅了该消息,消息内容即为图像帧,由image_view显示.

这里写图片描述

Q1 问题解决 (填坑)

如果遇到了一些问题,运行不了,如果出现下面的情形:

ERROR: cannot launch node of type[usb_cam/usb_cam_node]:usb_cam

A1 执行

source ~/catkin_ws/devel/setup.bash

运行usb_cam_node开启摄像头

    在另外一个终端打开
    $ roscore
    新版本的usb_cam包在launch文件夹下有自带的launch文件,名叫usb_cam-test.launch 我们可以直接cd到这个文件夹下运行它.
    $ cd  
    $ cd catkin_ws/src/usb_cam/launch  
    $ roslaunch usb_cam-test.launch 
编译。然后
source ~/catkin_ws/devel/setup.bas

运行:

roslaunch usb_cam usb_cam-test.launch

——————————————

补充内容  https://blog.csdn.net/qq_17232031/article/details/79519695

ROS Kinetic下编译安装ORB_SLAM2


操作系统:Ubuntu16.04


ROS版本:  Kinetic

1.ROS的安装,可以参考

http://blog.csdn.net/qq_17232031/article/details/79519308

,这里不再叙述。

2.新建一个WorkSpace

$ mkdir catkin_ws
$ cd ./catkin_ws
$ mkdir src

3.设定src为工作空间,在src目录下:

$ catkin_init_workspace

4.回到catkin_ws目录下执行:

$ catkin_make

第3,4步若出现Not Found the Command错误,则要安装catkin,输入一下的命令:

$ git clone https://github.com/ros/catkin.git
$ cd catkin
$ mkdir build
$ cd build
$ cmake ..
$ make -j8 && make install
$ cd ..
$ python2 setup.py install
$ python3 setup.py install

切记,Python 中一定要安装catkin_pkg模块

pip install catkin_pkg
或
pip3 install catkin_pkg

安装一些依赖项:

sudo apt install autotools-dev ccache doxygen dh-autoreconf git liblapack-dev libblas-dev libgtest-dev libreadline-dev libssh2-1-dev pylint clang-format-3.8 
python-autopep8 python-catkin-tools python-pip python-git python-setuptools python-termcolor python-wstool --yes

5.下载ORB_SLAM2源码:

git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2

6.将ORB_SLAM2文件移入catkin_ws/src下

$ sudo mv ORB_SLAM2 ./catkin_ws/src

7.安装ORB_SLAM2,Ranul Mur-Artal大神的github(

https://github.com/raulmur/ORB_SLAM2

)中写的很清楚了

cd ORB_SLAM2
chmod +x build.sh
./build.sh

8.编译安装ROS版的ORB_SLAM2,在ORB_SLAM2目录下:

chmod +x build_ros.sh
./build_ros.sh

此时就开始有坑了,可能会出现一下错误:

CMake Error at /opt/ros/kinetic/share/ros/core/rosbuild/public.cmake:129 (message):

  Failed to invoke rospack to get compile flags for package 'ORB_SLAM2'.
  Look above for errors from rospack itself.  Aborting.  Please fix the
  broken dependency!

Call Stack (most recent call first):
  /opt/ros/kinetic/share/ros/core/rosbuild/public.cmake:207 (rosbuild_invoke_rospack)
  CMakeLists.txt:4 (rosbuild_init)
-- Configuring incomplete, errors occurred!

此时记得在 ~/.bashrc末尾添加:

export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:PATH/ORB_SLAM2/Examples/ROS

其中PATH是自己的工作空间路径(/home/(user名)/catkin_ws/src),然后记得:

$ source ~/.bashrc

还没解决的话,使用以下命令:

$ sudo rosdep fix-permissions
$ rosdep update

然后继续编译,可能又会出现一个坑,心累~:

MakeFiles/Makefile2:718: recipe for target 'CMakeFiles/Mono.dir/all' failed
make[1]: *** [CMakeFiles/Mono.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
make[2]: *** No rule to make target '/opt/ros/kinetic/lib/libopencv_calib3d3.so.3.2.0', needed by '../RGBD'. Stop.
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/RGBD.dir/all' failed
make[1]: *** [CMakeFiles/RGBD.dir/all] Error 2
make[2]: *** No rule to make target '/opt/ros/kinetic/lib/libopencv_calib3d3.so.3.2.0', needed by '../Stereo'. Stop.
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/Stereo.dir/all' failed
make[1]: *** [CMakeFiles/Stereo.dir/all] Error 2

解决办法:修改ORB_SLAM2/Examples/ROS/ORB_SLAM2中CMakelists.txt,在set那里添加-lboost_system:

set(LIBS
${OpenCV_LIBS}
${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${PROJECT_SOURCE_DIR}/../../../Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/../../../Thirdparty/g2o/lib/libg2o.so
${PROJECT_SOURCE_DIR}/../../../lib/libORB_SLAM2.so
-lboost_system
)

然后在编译,就能够成功了.

如果要在ROS下利用自己的摄像头跑ORB_SLAM2,那麽还需要安装usb_cam

下载链接(

https://github.com/ros-drivers/usb_cam

),下载下来,一样的移到src下

或这在src下利用git命令

git clone https://github.com/bosch-ros-pkg/usb_cam.git

编译usb_cam:

$ mkdir build
$ cd build
$ cmake ..
$ make

打开摄像头,需要启动ros,在两个不同的终端分别执行以下命令:

$ roscore
$ roslaunch usb_cam usb_cam-test.launch

这样,就能启动摄像头了,其中,我们可以打开位于usb_cam/launch下的launch文件:

<launch>
  <node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" >
    <param name="video_device" value="/dev/video1" />
    <param name="image_width" value="1280" />
    <param name="image_height" value="480" />
    <param name="pixel_format" value="yuyv" />
    <param name="camera_frame_id" value="usb_cam" />
    <param name="io_method" value="mmap"/>
  </node>
  <node name="image_view" pkg="image_view" type="image_view" respawn="false" output="screen">
    <remap from="image" to="/usb_cam/image_raw"/>
    <param name="autosize" value="true" />
  </node>
</launch>

其中value=”/dev/video0″为笔记本摄像头,这里为video1,当然读者可以去/dev目录下查看自己的摄像头对应的value是多少。

ROS下怎么使用USB摄像机

首先,先说一下LZ用的呢是Ubuntu14.04,ROS是我事先安装indigo版,已经安装好了,就不赘述啦,回到整体,做SLAM经常会遇到的一个问题就是要使用自己的摄像头,但是怎么使用呢,有是个bug,O(∩_∩)O哈哈~

首先:

git clone https://github.com/bosch-ros-pkg/usb_cam.git

从github下载原来的代码,指令下载下来进入这个node,然后直接运行里面的.launch文件就可以了,接着,使用下面的指令

roslaunch usb_cam/launch /usb_cam-test.launch

如果遇到了一些问题,运行不了,如果出现下面的情形:

ERROR: cannot launch node of type[usb_cam/usb_cam_node]:usb_cam

如果出现了问题,该怎么解决呢?



我的ROS工作区(为~/catkin_ws),新建usb_cam目录,并在其下新建一个src目录:

cd ~/catkin_ws/
mkdir -p usb_cam/src



进入src目录,使用git下载usb_cam源码:

cd usb_cam/src
git clone https://github.com/bosch-ros-pkg/usb_cam.git



退出src目录运行catkin_make并配置运行环境

cd ..
catkin_make
source ~/catkin_ws/devel/setup.bash



可以测试一下可不可以运行了呀

rosrun usb_cam
  • 1

##运行usb_cam

rosrun usb_cam usb_cam_node
  • 1



怎么可以看到当下的图片呢

rosrun image_view image_view image:=/usb_cam/image_row
  • 1

这样,你就可以看到摄像头里的画面啦!

source ~/catkin_ws/devel/setup.bash

编译。然后

 
source ~/catkin_ws/devel/setup.bash
  • 运行:
roslaunch usb_cam usb_cam-test.launch

发现还是一样的错误,发现还是少image view,那就

yaourt -S ros-jade-image-view

安装即可,之后重新roslaunch成功,如下。

————————————————————————————

一年的默默无闻的积累



版权声明:本文为KYJL888原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。