WSL折腾记录之二:在WSL的ROS环境运行ORB-SLAM3节点
系列文章目录
WSL折腾记录之一:在Windows上部署WSL/Ubuntu18.03
WSL折腾记录之二:在WSL的ROS环境运行ORB-SLAM3节点
前言
本文章主要记录笔者在WSL Ubuntu 18.04平台上安装和运行ROS与ORB-SLAM3的过程。
一、ORB-SLAM3是什么?
github/orb_slam3项目中如此叙述:
ORB-SLAM3 is the first real-time SLAM library able to perform Visual, Visual-Inertial and Multi-Map SLAM with monocular, stereo and RGB-D cameras, using pin-hole and fisheye lens models. In all sensor configurations, ORB-SLAM3 is as robust as the best systems available in the literature, and significantly more accurate.
We provide examples to run ORB-SLAM3 in the EuRoC dataset using stereo or monocular, with or without IMU, and in the TUM-VI dataset using fisheye stereo or monocular, with or without IMU. Videos of some example executions can be found at ORB-SLAM3 channel.
This software is based on ORB-SLAM2 developed by Raul Mur-Artal, Juan D. Tardos, J. M. M. Montiel and Dorian Galvez-Lopez (DBoW2).
二、使用步骤
2. 准备工作
ORB-SLAM3库可以在Ubuntu 16.04和18.04测试并运行, but it should be easy to compile in other platforms. A powerful computer (e.g. i7) will ensure real-time performance and provide more stable and accurate results.
C++11 or C++0x Compiler
We use the new thread and chrono functionalities of C++11.
Pangolin
ORB-SLAM3项目使用Pangolin作为GUI以实现数据的可视化与用户接口.
从https://github.com/stevenlovegrove/Pangolin获得代码与安装方法。
hill277:可以从https://gitee.com/zjulion/Pangolin使用如下命令获得代码:
sudo git clone https://gitee.com/zjulion/Pangolin.git ~/Pangolin
hill277:克隆代码完成后建立build目录,使用cmake命令生成代码:
cd ~/Pangolin
mkdir build
cd build
sudo cmake ..
hill277:代码生成后使用make命令编译代码:
sudo make
OpenCV
We use OpenCV to manipulate images and features. Dowload and install instructions can be found at: http://opencv.org. Required at leat 3.0. Tested with OpenCV 3.2.0.
Eigen3
Required by g2o (see below). Download and install instructions can be found at: http://eigen.tuxfamily.org. Required at least 3.1.0.
DBoW2 and g2o (Included in Thirdparty folder)
We use modified versions of the DBoW2 library to perform place recognition and g2o library to perform non-linear optimizations. Both modified libraries (which are BSD) are included in the Thirdparty folder.
Python
Required to calculate the alignment of the trajectory with the ground truth. Required Numpy module.
(win) http://www.python.org/downloads/windows
(deb) sudo apt install libpython2.7-dev
(mac) preinstalled with osx
3.构建 ORB-SLAM3 库与例程
注意:如果想要在ROS环境下使用ORB-SLAM3库,则最好将代码库git到你的catkin工作目录下的src文件夹里,比如我就是git到~/catkin_ws/src里。
使用下述命令将GitHub上的ORB-SLAM3代码库复制到本地:
git clone https://github.com/UZ-SLAMLab/ORB_SLAM3.git ORB_SLAM3
这里由于git clone的速度较慢可以尝试从我的仓库拉取代码,命令如下:
git clone https://gitee.com/hill227/ORB_SLAM3.git ORB_SLAM3
ORB-SLAM3的作者提供一个脚本 build.sh 来构建第三方库文件与ORB-SLAM3. 请确认你已经安装了第二节中所有要求安装的依赖项并在Shell中运行下述Bash命令:
cd ORB_SLAM3
chmod +x build.sh
./build.sh
这将在ORB-SLAM3的库目录构建 libORB_SLAM3.so文件并在Example文件夹下建立可执行文件。
下述命令摘自别人的CSDN,在我这不好用。sudo ln -s ~/catkin_ws/src/ORB_SLAM3/Examples/ROS/ORB_SLAM3 /opt/ros/melodic/share/ORB_SLAM3
运行sudo ./build_ros.sh后出现下述错误信息
aaa@qq.com:~/catkin_ws/src/ORB_SLAM3$ sudo ./build_ros.sh
Building ROS nodes
mkdir: cannot create directory ‘build’: File exists
CMake Error at CMakeLists.txt:2 (include):
include could not find load file:
/core/rosbuild/rosbuild.cmake
CMake Error at CMakeLists.txt:4 (rosbuild_init):
Unknown CMake command "rosbuild_init".
-- Configuring incomplete, errors occurred!
See also "/home/user/catkin_ws/src/ORB_SLAM3/Examples/ROS/ORB_SLAM3/build/CMakeFiles/CMakeOutput.log".
make: *** No targets specified and no makefile found. Stop.
网上要好多解决方法,我这试出来的是:
cd ~/catkin_ws/src/
sudo chown -R [myusername]:root ORB_SLAM3
cd ORB_SLAM3
./build_ros.sh
编译成功了,就可以运行ORB_SLAM3节点(需要提前运行roscore)
打开一个新的Terminal,运行ROSCORE
roscore
再打开一个新的Terminal,运行下述命令,其中Mono后需要跟两个参数,第一个是ORB vocabulary文件,第二个Asus.yaml可以直接使用或改成你自己的相机参数文件。
rosrun ORB_SLAM3 Mono ~/catkin_ws/src/ORB_SLAM3/Vocabulary/ORBvoc.txt ~/catkin_ws/src/ORB_SLAM3/Examples/ROS/ORB_SLAM3/Asus.yaml
出现如下错误
上述错误的原因与解决方案参看GitHub/Pangolin/Issue中的这篇帖子:https://github.com/stevenlovegrove/Pangolin/issues/260
Following is the explanation.
As the comment in this link (#74 (comment)) mentioned, the Pangolin needs GLX version >= 1.3. So I run “glxinfo” in the client to check the version and notice some info like the following:
server glx version string: 1.2
client glx version string: 1.4
The glx version does not match and the server version is only 1.2. So I believe it is caused by Xming server. I use another Xserver: VcXsrv instead of Xming. And I checked the glxinfo again. The server and client versions are now both 1.4.
Run HelloPangolin, Everything is fine now. And NO NEED To change “Pangolin/src/display/device/display_x11.cpp”
So if any you are using Xming like I do, probably you could switch to VcXsrv.
可知是由于Xming使用的glx驱动版本过低引起,诊断方法是安装mesa-utils工具,使用glxinfo获得驱动版本。
sudo apt install mesa-utils
glxinfo | grep server
确认server glx version string: ≤1.3
原帖中提供两种解决方法:
- 将Xming更换为VcXsrv
- 修改"Pangolin/src/display/device/display_x11.cpp"
并推荐在WSL环境中使用VcXsrv替代Xming
关于VcXsrv的安装,参见:
https://zhuanlan.zhihu.com/p/128507562
再运行
rosrun ORB_SLAM3 Mono ~/catkin_ws/src/ORB_SLAM3/Vocabulary/ORBvoc.txt ~/catkin_ws/src/ORB_SLAM3/Examples/ROS/ORB_SLAM3/Asus.yaml
最终出现如下窗口就说明配置成功了。
接下来就可以用rospack打开一个封装好的Example进行回放,并在ORB-SLAM3上查看结果。
总结
本文简单介绍了我的WSL的ROS环境运行ORB-SLAM3节点的过程。
上一篇: web学习笔记1