【环境及第三方库配置】Ubuntu16.04,已安装ROS、Eigen3、Sophus、Ceres、g2o、OpenCV3.3、PCL等
1、在个人的/home目录下先创建ROS工作空间
$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/src
$ catkin_init_workspace
2、进入到catkin_ws/src目录下,下载usb_cam的源文件到此目录下
$ cd ~/catkin_ws/src
$ git clone https://github.com/bosch-ros-pkg/usb_cam.git
3、把ORB-SLAM2.tar.gz下载并解压缩到catkin_ws/src目录下,并build好(大概需要一小时)
$ chmod +x build.sh
$ ./build.sh
4、退回到catkin_ws/,运行
$ source ~/catkin_ws/devel/setup.bash
5、安装ros-kinetic-usb-cam
$ sudo apt-get install ros-kinetic-usb-cam
6、如果(其实大部分情况下都是)在虚拟机中运行ORB-SLAM和ROS的话,需要单击VMware Fusion的菜单栏中的“虚拟机—摄像头—……”,选取usb摄像头(默认是笔记本自带摄像头),此时如果一切正常的话,应可以看到摄像头的实时图像。更具体的操作请参见《ubuntu虚拟机下使用摄像头》:https://blog.csdn.net/xiaozi0221/article/details/79135930;
7、查看Ubuntu系统检测到的摄像头设备,先在终端中运行lsusb,看看列出的Bus ID后是否有已连接的摄像头型号,如Logitech, Inc. HD Webcam C525等;再到根目录下的dev文件夹中查看是否有video,一般是/dev/video0;这两个条件都满足说明摄像头连上虚拟机并被Ubuntu所识别;
$ ls /dev/video*
8、启用ROS系统和摄像头节点
$ cd ~/catkin_ws/
$ roscore
此时请打开新的终端,回到catkin_ws目录下,再make一次,然后source一下(注意,每一次catkin_make之后都要source一下):
$ cd ~/catkin_ws/
$ catkin_make
$ source ~/catkin_ws/devel/setup.bash
最后到usb_cam目录下的launch文件夹中运行roslaunch:
$ cd ~/catkin_ws/src/usb_cam/launch
$ roslaunch usb_cam usb_cam-test.launch
如果一切正常,将会弹出一个窗口,里面显示摄像头的实时映像。
9、如果拔了摄像头后再重新连接,或者中途关掉弹出窗口,请返回第8步重启roscore后再roslaunch。
【特殊情况二】
还有可能出现下面的错误,即所谓的“[usb_cam-1] process has died [pid 3546, exit code -11”错误:
kinetic@ros-vm:~/mywork/catkin_ws/src/usb_cam/launch$ roslaunch usb_cam-test.launch
... logging to /home/kinetic/.ros/log/e8db393a-feca-11e8-9c82-000c291d31c4/roslaunch-ros-vm-3528.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
started roslaunch server http://192.168.62.128:35227/
SUMMARY
========
PARAMETERS
* /image_view/autosize: True
* /rosdistro: kinetic
* /rosversion: 1.12.7
* /usb_cam/camera_frame_id: usb_cam
* /usb_cam/image_height: 480
* /usb_cam/image_width: 640
* /usb_cam/io_method: mmap
* /usb_cam/pixel_format: yuyv
* /usb_cam/video_device: /dev/video0
NODES
/
image_view (image_view/image_view)
usb_cam (usb_cam/usb_cam_node)
ROS_MASTER_URI=http://192.168.62.128:11311
core service [/rosout] found
process[usb_cam-1]: started with pid [3546]
process[image_view-2]: started with pid [3547]
init done
[ INFO] [1544700971.902073651]: Using transport "raw"
[ INFO] [1544700972.025623804]: using default calibration URL
[ INFO] [1544700972.025790930]: camera calibration URL: file:///home/kinetic/.ros/camera_info/head_camera.yaml
[ INFO] [1544700972.025874556]: Unable to open camera calibration file [/home/kinetic/.ros/camera_info/head_camera.yaml]
[ WARN] [1544700972.025906964]: Camera calibration file /home/kinetic/.ros/camera_info/head_camera.yaml not found.
[ INFO] [1544700972.025937876]: Starting 'head_camera' (/dev/video0) at 640x480 via mmap (yuyv) at 30 FPS
[usb_cam-1] process has died [pid 3546, exit code -11, cmd /opt/ros/kinetic/lib/usb_cam/usb_cam_node __name:=usb_cam __log:=/home/kinetic/.ros/log/e8db393a-feca-11e8-9c82-000c291d31c4/usb_cam-1.log].
log file: /home/kinetic/.ros/log/e8db393a-feca-11e8-9c82-000c291d31c4/usb_cam-1*.log
^C[image_view-2] killing on exit
shutting down processing monitor...
... shutting down processing monitor complete
done
这种情况原因还不明,但是通过重复第6-9步可以解决。过程就不赘述了。
【备注】本人刚接触ORB-SLAM2不久,也是参考了网上资料亲测总结而成,希望能帮到后来人。如有错误,请回复或联系我更正。谢谢阅读!
此教程参考如下链接:
https://blog.csdn.net/weixin_40522162/article/details/79477699
https://blog.csdn.net/panxiying1993/article/details/61922162
Eigen3、Sophus、Ceres、g2o、OpenCV3.3、PCL等的安装请见:
https://www.cnblogs.com/feifanrensheng/p/8227716.html