本文记录了ORB-SLAM在Ubuntu14.04下的安装过程。
安装环境:
- Trusty (Ubuntu 14.04) amd64
- ROS Indigo Igloo
- ORB-SLAM
首先,安装若干必备工具:
sudo apt-get install vim git cmake -y
接下来将安装 ROS Indigo Igloo
下面我将给出 ROS Indigo Igloo 在 Trusty (Ubuntu 14.04) 上的安装和测试过程。
点击这里,查看 ROS 官网的 ROS Indigo Igloo 安装手册。
配置Ubuntu要求允许接受"restricted," “universe,” and "multiverse."的软件源,可以根据下面的链接配置:
https://help.ubuntu.com/community/Repositories/Ubuntu
一般地,这是系统默认设置,如下图所示:
ROS Indigo ONLY supports Saucy (Ubuntu13.10) and Trusty (Ubuntu14.04) for debian packages.
设置你的计算机从packages.ros.org
接收软件包。
添加ROS官方软件源:
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
一般地,ROS官方源速度很慢或者连接不上,推荐使用清华 TUNA Mirror 。
设置清华大学TUNA源:
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'
所有 Mirrors.
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
如果你在连接秘钥服务器时遇到问题,你可以在上面的命令中替换链接为hkp://pgp.mit.edu:80
或者hkp://keyserver.ubuntu.com:80
首先,更新Debian包索引
sudo apt-get update
If you are using Ubuntu Trusty 14.04.2 and experience dependency issues during the ROS installation, you may have to install some additional system dependencies.
Do not install these packages if you are using 14.04, it will destroy your X server:sudo apt-get install xserver-xorg-dev-lts-trusty mesa-common-dev-lts-trusty libxatracker-dev-lts-trusty libopenvg1-mesa-dev-lts-trusty libgles2-mesa-dev-lts-trusty libgles1-mesa-dev-lts-trusty libgl1-mesa-dev-lts-trusty libgbm-dev-lts-trusty libegl1-mesa-dev-lts-trusty
Do not install the above packages if you are using 14.04, it will destroy your X server
Alternatively, try installing just this to fix dependency issues:sudo apt-get install libgl1-mesa-dev-lts-trusty
For more information on this issue see this answers.ros.org thread or this launchpad issue
X server is an application that manages one or more graphics displays and one or more input devices (keyboard, mouse, etc.) connected to the computer.
It works as a server and can run on the local computer or on another computer on the network. Services can communicate with the X server to display graphical interfaces and receive input from the user.
It’s worth noting, a common component used with an X server is the Window Manager, an application that manages the resizing and moving of windows and decorative elements of windows such as title bars, minimize, and close buttons.
The X server can be started with the ‘startx’ command, or more commonly, from a display manager such as gdm.
- ~/.xinitrc is a shell script used by xinit, that starts the X server when not using a display manager, to define some application to start automatically in the X server.
- /etc/X11/xorg.conf is a configuration file used to give the X server information about the hardware components used, but now the X server can avoid using it, because it is capable of autoconfiguring itself.
-在安装之前,请认真阅读上述引用。安装ROS完整版后可能会导致 X server 损坏,在重新启动Ubuntu后出现The system is running in low-graphics mode
的错误,导致无法进入Ubuntu桌面。请尝试点击 answers.ros.org thread 或者 launchpad issue 解决问题。
ROS含有多种库和工具。官网提供了4种默认配置的安装供你选择。你也可以依据自己需求进行个性化安装。
Indigo uses Gazebo 2 which is the default version of Gazebo on Trusty and is recommended. If you would like to instead use a newer version of Gazebo (5, 6 or 7), refer to these instructions on the Gazebo site. Note that installing a newer version of Gazebo will require you to build dependent packages (such as turtlebot_gazebo) to be built from source. See also Using a specific Gazebo version with ROS.
sudo apt-get install ros-indigo-desktop-full
sudo apt-get install ros-indigo-desktop
sudo apt-get install ros-indigo-ros-base
sudo apt-get install ros-indigo-PACKAGE
PACKAGE
指包的名称
e.g.
sudo apt-get install ros-indigo-slam-gmapping
搜索可用包:
apt-cache search ros-indigo
我们使用 Desktop-Full Install
sudo apt-get install ros-indigo-desktop-full
在使用ROS之前,我们需要首先初始化rosdep
,rosdep
帮助你轻松地进行系统依赖项源码的编译和安装,并且它是ROS核心组件运行的必要成分。
sudo rosdep init
rosdep
初始化后如下图,写入/etc/ros/rosdep/sources.list.d/20-default.list
。
更新ROS软件包
rosdep update
使用apt-get
方式在 Ubuntu上安装 ROS,在使用前需要激活/opt/ros/indigo/
目录下的setup.bash
文件来添加 ROS 环境变量。
我们安装的是ROS Indigo Igloo,命令如下:
source /opt/ros/indigo/setup.bash
在每次打开一个新的 shell 时,我们都需要使用上述命令激活setup.bash
文件。这样很繁琐。
因此,可以添加 ROS 的环境变量,这样,当我们打开新的shell时,我们的bash会话中会自动添加环境变量。
echo "source /opt/ros/indigo/setup.bash" >> ~/.bashrc
source ~/.bashrc #(使环境变量设置立即生效)
Tips:
使用下面命令可以在不同的 ROS distribution (ROS 发行版)间切换$ source /opt/ros/<distro>/setup.bash
使用 ROS distribution 的短名称替换
如果我们想切换到 ROS Kinetic Kame :$ source /opt/ros/kinetic/setup.bash
rosinstall
是 ROS 包中常用的命令行工具。它可以帮助我们轻松地下载许多 ROS 包源码并建立依赖关系,并且只需要一行命令。
sudo apt-get install python-rosinstall
其他的常用项
sudo apt-get install python-rosinstall-generator python-wstool -y
运行 roscore 是使用 ROS 的首要步骤。
roscore
我们可以看到
... logging to ~/.ros/log/9cf88ce4-b14d-11df-8a75-00251148e8cf/roslaunch-machine_name-13039.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://machine_name:33919/
ros_comm version 1.4.7
SUMMARY
======
PARAMETERS
* /rosversion
* /rosdistro
NODES
auto-starting new master
process[master]: started with pid [13054]
ROS_MASTER_URI=http://machine_name:11311/
setting /run_id to 9cf88ce4-b14d-11df-8a75-00251148e8cf
process[rosout-1]: started with pid [13067]
started core service [/rosout]
说明 ROS 已经成功安装并配置
有两种方式创建 ROS 工作空间:
catkin
和rosbuild
- ROS Groovy 以及更新的版本请使用
catkin
- ROS Fuerte 以及以前的版本请使用
rosbuild
我们开始创建 catkin workspaces
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
catkin_make
The catkin_make
command is a convenience tool for working with catkin workspaces
. Running it the first time in your workspace, it will create a CMakeLists.txt
link in your src
folder. Additionally, if you look in your current directory you should now have a build
and devel
folder. Inside the devel
folder you can see that there are now several setup.*sh files. Sourcing any of these files will overlay this workspace on top of your environment. To understand more about this see the general catkin documentation: catkin. Before continuing source your new setup.*sh file:
source devel/setup.bash
To make sure your workspace is properly overlayed by the setup script, make sure ROS_PACKAGE_PATH environment variable includes the directory you’re in.
slam1a@slam1a-vm:~/catkin_ws$ echo $ROS_PACKAGE_PATH
/home/slam1a/catkin_ws/src:/opt/ros/indigo/share:/opt/ros/indigo/stacks
出现上述结果,说明我们的 catkin workspaces
已经创建好了,并且 ROS_PACKAGE_PATH
也已经配置好了。
接下来的所有工作都在
~/catkin_ws/src
目录下完成,即在catkin workspaces
。
=======================================================
除了 ROS 外,ORB-SLAM 还依赖于其他若干第三方库:Boost
、OpenCV
、Eigen3
、g2o
和DBoW2
。g2o
和DBoW2
已经包含在 ORB-SLAM 项目下的 Thirdparty/
目录下。
下面我们将依次安装其它各第三方库。
使用 Boost 管理 ORB-SLAM 多线程。
sudo apt-get install libboost-all-dev
OpenCV 版本最低要求为2.4.3,建议采用 OpenCV 2.4.13 或者 OpenCV 3.2.0。
从OpenCV 官网 或者 OpenCV GitHub 下载 OpenCV2.4.13。
也可以直接点击这里下载
然后安装依赖项:
安装编译工具
sudo apt-get install build-essential -y
安装依赖包
sudo apt-get install libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev -y
安装可选包
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev -y
sudo apt-get install libgtk2.0-dev -y
sudo apt-get install pkg-config -y
进入 ~/catkin_ws/src
从GitHub下载opencv2.4.13,这不是一个 git repository,使用wget。
将下载的OpenCV解压~/catkin_ws/src
目录下。
cd ~/catkin_ws/src
wget https://github.com/Itseez/opencv/archive/2.4.13.zip
unzip 2.4.13.zip
进入OpenCV的目录下。
编译安装OpenCV 2.4.13 源码。
cd opencv-2.4.13/
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install
安装完毕。
查看OpenCV版本。
pkg-config --modversion opencv
下面进行测试。
测试实例
//文件名字lena.cpp
#include
#include
using namespace cv;
int main( )
{
Mat image;
//按照自己的目录,或者将
image = imread("lena.png", 1 );
if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
return 0;
}
将上述 lena.cpp
和 lena.png
文件放入同一目录下,编译
g++ lena.cpp -o lena.o `pkg-config --cflags --libs opencv`
运行
./lena.o
效果如下
OpenCVC 已经成功安装。
最低要求版本为3.1.0。在http://eigen.tuxfamily.org 下载 Eigen3.2.10 压缩文件,并解压。
进入~/catkin_ws/src/
cd ~/catkin_ws/src/
wget https://bitbucket.org/eigen/eigen/get/3.2.10.tar.bz2
tar -xjf 3.2.10.tar.bz2
得到eigen-eigen-b9cd8366d4e8目录,重命名eigen-3.2.10
mv eigen-eigen-b9cd8366d4e8/ eigen-3.2.10
编译安装eigen3.2.10
cd eigen-3.2.10/
mkdir build
cd build
cmake ..
make
sudo make install
Eigen3.2.10 安装完毕
进入 ROS 工作空间 ~/catkin_ws/src
cd ~/catkin_ws/src
git clone https://github.com/raulmur/ORB_SLAM.git ORB_SLAM
ORB-SLAM项目的绝对路径PATH_TO_PARENT_OF_ORB_SLAM
为~/catkin_ws/src/ORB-SLAM
。设置环境变量ROS_PACKAGE_PATH为~/catkin_ws/src/ORB_SLAM
。
~/.bashrc
,将下列命令添加在文件最下面,保存退出。export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:~/catkin_ws/src/ORB_SLAM
~/.bashrc
文件source ~/.bashrc
这样,打开每个新的shell后就自动添加了环境变量。
进入目录 ORB_SLAM/Thirdparty/g2o/
,并在命令行中执行命令,
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
g2o 编译完毕
进入目录 ORB_SLAM/Thirdparty/DBoW2/
,并在命令行中执行命令,
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
DBoW2 编译完毕
特别需要注意的是,我们安装的 ROS 版本是 ROS Indigo,需要将根目录下的
manifest.xml
文件中的opencv2依赖一行的代码去掉!
# 用 进行注释
#
<!-- <depend package="opencv2"/> -->
进入目录ORB_SLAM项目根目录,并在命令行中执行命令,
mkdir build
cd build
cmake .. -DROS_BUILD_TYPE=Release
make
ORB-SLAM 编译完成
Example.bag
进行测试。cd ~/Downloads/
http://webdiis.unizar.es/~raulmur/orbslam/downloads/Example.bag.tar.gz
tar -xzf Example.bag.tar.gz
~/catkin_ws/src/ORB_SLAM/Data
目录,解压 ORBvoc.txt.tar.gz
得到 ORBvoc.txt
cd ~/catkin_ws/src/ORB_SLAM/Data
tar -xzvf ORBvoc.txt.tar.gz
测试数据集准备就绪
使用根目录下的launch文件启动程序,ORB_SLAM项目目录下包含两个launch文件:ExampleFuerte.launch
和 ExampleGroovyOrNewer.launch
,对应不同的ROS版本,根据ROS的版本选择不同的launch文件。launch文件是一个脚本文件,包含启动程序的各个步骤。接下来,按下列步骤启动 ORB-SLAM。
roscore
roslaunch ExampleGroovyOrNewer.launch
rosbag play --pause Example.bag
执行下面命令,完整运行
rosbag play Example.bag
ORB-SLAM 成功运行