1.准备运行环境

1.1 操作系统

Ubuntu 16.04 LTS,最好是干净的系统。

可以到阿里巴巴开源镜像站或其他下载站下载系统镜像。
https://mirrors.aliyun.com/ubuntu-releases/16.04/ubuntu-16.04.6-desktop-amd64.iso

安装git、cmake、vim、wget

sudo apt-get update
sudo apt-get install git
sudo apt-get install cmake
sudo apt-get install vim
sudo apt-get install wget

1.2 ROS

安装说明:http://wiki.ros.org/cn/kinetic/Installation/Ubuntu

1.2.1 配置 Ubuntu 软件仓库

配置你的 Ubuntu 软件仓库(repositories) 以允许 "restricted"、"universe" 和 "multiverse"这三种安装模式。 你可以按照ubuntu中的配置指南来完成配置。

1.2.2 添加 sources.list

官方源速度有些慢,添加中科大源

sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'

或清华源

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'

1.2.3 添加key

sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

添加公钥(官方文档没有这一步,但是不添加公钥会报不信任错误)

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654

1.2.4 安装

sudo apt-get update

安装桌面完整版

sudo apt-get install ros-kinetic-desktop-full

1.2.5 初始化rosdep

sudo rosdep init
rosdep update

1.2.6 环境配置

echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
source ~/.bashrc

1.2.7 构建工厂依赖

sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential

1.2.8 配置ROS环境,创建工作空间

参考:http://wiki.ros.org/cn/ROS/Tutorials/InstallingandConfiguringROSEnvironment

mkdir -p ~/catkin_ws/src
cd ~/catkin_ws
catkin_make
source devel/setup.bash
echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc

2. 安装依赖项

2.1 安装Pangolin

准备依赖

sudo apt-get install libglew-dev libpython2.7-dev libboost-dev libboost-thread-dev libboost-filesystem-dev -y

下载Pangolin并配置环境

git clone https://github.com/stevenlovegrove/Pangolin Pangolin
cd Pangolin
mkdir build
cd build
cmake ..
make -j2
sudo make install

2.2 安装Eigen3

最低要求为3.1.0,这里安装Eigen 3.2.10。

可以从官网下载源码。

cd ~/catkin_ws/src
wget https://bitbucket.org/eigen/eigen/get/3.2.10.tar.bz2
tar -xjf 3.2.10.tar.bz2
mv eigen-eigen-b9cd8366d4e8/ eigen-3.2.10

编译安装

cd eigen-3.2.10
mkdir build
cd build
cmake ..
make
sudo make install

2.3 安装OpenCV 3.2.0

参考:https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html

  1. 安装依赖(前两个必装,optional可选)
[compiler] sudo apt-get install build-essential
[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
  1. 下载(也可以从官网下载安装)
cd ~
wget https://github.com/opencv/opencv/archive/3.2.0.zip
unzip 3.2.0.zip
cd opencv-3.2.0
mkdir build
cd build
  1. 配置并编译安装
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install
  1. 在/etc/ld.so.conf.d/opencv.conf中添加路径
sudo vim /etc/ld.so.conf.d/opencv.conf

​ 在其中添加

/usr/local/lib

​ 使之生效

sudo ldconfig
  1. 在bash.bashrc中添加路径
sudo vim /etc/bash.bashrc

​ 在其中添加

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export PKG_CONFIG_PATH

​ 使之生效

source /etc/bash.bashrc
  1. 测试opencv
cd ~/opencv-3.2.0/samples/cpp/example_cmake
mkdir muild
cd build
cmake ..
make
./opencv_example

​ 此时应当打开摄像头,并在左上角显示 Hello OpenCV

2.4 安装usb_cam

同样的,要安装在工作区的~/catkin_ws/src文件夹下。

  1. 下载源码
cd ~/catkin_ws/src
git clone https://github.com/bosch-ros-pkg/usb_cam.git
cd ..
catkin_make
source ~/catkin_ws/devel/setup.bash
  1. 编译安装
cd ~/catkin_ws/src/usb_cam
mkdir build
cd build
cmake ..
make
  1. 测试摄像头

    1. 打开终端
    roscore
    1. 打开新的终端
    cd ~/catkin_ws/src/usb_cam/launch
    source ~/catkin_ws/devel/setup.bash
    roslaunch usb_cam usb_cam-test.launch

能正常打开摄像头,显示图像即可。

3. 安装ORB SLAM2

  1. 下载源码到工作空间 ~/catkin_ws/src
cd ~/catkin_ws/src
git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
cd ORB_SLAM2
  1. 分别打开build.sh和build_ros.sh,更改 make -jmake -j2(或j4)。
  2. 编译安装(无ROS依赖):
chmod +x build.sh
./build.sh
  1. 添加路径

sudo vim ~/.bashrc,在最后添加

export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:~/catkin_ws/src/ORB_SLAM2/Examples/ROS
source ~/.bashrc
  1. 配置库文件

    1. 打开终端,查找库文件
    $ locate boost_system //查找到目录,然后加到cmakelist中。
    /usr/lib/x86_64-linux-gnu/libboost_system.a 
    /usr/lib/x86_64-linux-gnu/libboost_system.so 
    /usr/lib/x86_64-linux-gnu/libboost_system.so.1.58.0 
     
    $ locate boost_filesystem //查找到目录 
    /usr/lib/x86_64-linux-gnu/libboost_filesystem.a 
    /usr/lib/x86_64-linux-gnu/libboost_filesystem.so 
    /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.58.0
    
    1. 拷贝库文件
    sudo cp /usr/lib/x86_64-linux-gnu/libboost_system.so ~/catkin_ws/src/ORB_SLAM2/lib
    sudo cp /usr/lib/x86_64-linux-gnu/libboost_filesystem.so ~/catkin_ws/src/ORB_SLAM2/lib
    1. 打开CMakeLists.txt
    vim ~/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/CMakeLists.txt
    或
    gedit ~/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/CMakeLists.txt

​ 找到 set(LIBS ... ,添加以下内容:

set(LIBS
${PROJECT_SOURCE_DIR}/../../../lib/libboost_filesystem.so
${PROJECT_SOURCE_DIR}/../../../lib/libboost_system.so
  1. 编译ORB SLAM2 ROS

    cd ~/catkin_ws/src/ORB_SLAM2
    chmod +x build_ros.sh
    ./build_ros.sh

4.运行ROS实例(笔记本摄像头)

  1. 标定相机

参考https://www.jianshu.com/p/c3e8c88edb64进行相机参数标定

  1. 订阅usb_cam节点

    1. 在ROS目录下的ros_mono.cc文件中修改,双目,深度以及AR demo同理。

    /camera/image_raw 改为 /usb_cam/image_raw

    1. 修改完成后删除Examples/ROS/ORB_SLAM2/下的build文件夹:
    cd ~/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/
    sudo rm -r build
    1. 重编ORB SLAM ROS
    cd ~/catkin_ws/src/ORB_SLAM2/
    ./build_ros.sh
  2. 启动新的终端,运行usb_cam

    roslaunch usb_cam usb_cam-test.launch
  3. 启动新的终端,运行orb_slam

    rosrun ORB_SLAM2 Mono ~/catkin_ws/src/ORB_SLAM2/Vocabulary/ORBvoc.txt ~/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/Asus.yaml

5.后记

ORB SLAM是我第一个跑的开源项目,从配置到跑完折腾了挺久,期间还重装了三次系统。为了最顺利的跑通项目,最好使用一个新安装的Ubuntu 16.04 LTS系统,按照本文跑下来应该是没有什么问题的。在装完系统之后,提示的升级先都不要升,我有一次执行 sudo apt upgrade之后,ROS就装不上了==虽然不太清楚究竟是什么原因,但还是不要做一些奇怪的操作比较好。

参考资料:

https://blog.csdn.net/qq_39397000/article/details/83745332

https://blog.csdn.net/qq_42037180/article/details/88371971

Last modification:March 11th, 2020 at 06:12 pm