【无人机自主导航3-ORB-SLAM2】Gazebo仿真环境下的视觉SLAM

发布于 2021-03-14  1119 次阅读


一、背景

无人机的自主导航需要无人机的位置信息、姿态等,在空旷的室外环境,一般需要基于GNSS系统进行位置信息的获取与无人机导航。

但在室内等无GNSS的情况下,我们就需要其他的手段来实现。

在我们确定自己的位置时,一般是通过地图定位+环境地物相对定位来实现。近些年由于实际的需要,地图构建与同步定位(SLAM)技术被人们提出并得到了广泛应用。

二、Pangolin

2.1 简介

Pangolin是一个轻量级的便携式快速开发库,用于管理OpenGL显示/交互和抽象视频输入。 它的核心是一个简单的OpenGl视口管理器,它可以帮助模块化3D可视化而又不增加其复杂性,并提供先进而直观的3D导航处理程序。 Pangolin还提供了一种通过配置文件和ui集成来操纵程序变量的机制,并具有灵活的实时绘图仪,用于可视化图形数据。

Pangolin的精神是减少通常编写的可视化样板代码,以可视化并与(通常基于图像和3D的)系统进行交互,而不会影响性能。 它还为许多平台(包括Windows,Linux,OSX,Android和IOS)启用一次写入代码。
-Github

其源代码获取方式如下:

git clone https://github.com/stevenlovegrove/Pangolin.git

2.2 依赖项

2.2.1 必要依赖配置

  • C++11

  • OpenGL (Desktop / ES / ES2)

(lin) sudo apt install libgl1-mesa-dev
  • Glew
(win) built automatically (assuming git is on your path)
(deb) sudo apt install libglew-dev
(mac) sudo port install glew
  • CMake (for build environment)
(win平台) http://www.cmake.org/cmake/resources/software.html
(deb) sudo apt install cmake
(mac) sudo port install cmake

2.2.2 推荐的依赖配置

  • Python2 / Python3, for drop-down interactive console
(win) http://www.python.org/downloads/windows
(deb) sudo apt install libpython2.7-dev
(mac) preinstalled with osx
(for pybind11) git submodule init && git submodule update
(useful modules) sudo python -mpip install numpy pyopengl Pillow pybind11
  • Wayland
pkg-config: sudo apt install pkg-config
Wayland and EGL:sudo apt install libegl1-mesa-dev libwayland-dev libxkbcommon-dev wayland-protocols

2.3 编译安装

Linux平台下可以通过CMake在目录build中构建出,在shell(或使用GUI进行的等效操作)中执行如下指令:

git clone https://github.com/stevenlovegrove/Pangolin.git
cd Pangolin
mkdir build
cd build
cmake ..
cmake --build .

如果需要生成文档,先确保已经安装了Doxygen,然后执行:

cmake --build . --target pangolin_doc

官方的提示:

在Windows上,Pangolin将尝试自动下载并构建glew,libjpeg,libpng和zlib。 这样做是假设git在路径上可用-对于通过github上的zip文件下载了Pangolin的Windows用户,有可能是错误的。 这就需要您将手动下载和编译依赖项,并将这些库的BUILDEXTERN(lib)选项设置为false。 另一种推荐的方法是从其提供的控制台中安装gitbash并进行工作。

三、编译构建ORB-SLAM2

本文所用的ORB-SLAM2算法来源于XTDrone平台,如有其他来源请自行配置。

cp -r ~/XTDrone/sensing/slam/vslam/ORB_SLAM2/ ~/catkin_ws/src/
mkdir ~/catkin_ws/scripts/
cp ~/catkin_ws/src/ORB_SLAM2/xtdrone* ~/catkin_ws/scripts/
cd ~/catkin_ws/src/ORB_SLAM2
chmod +x build.sh
./build.sh
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/catkin_ws/src/ORB_SLAM2/Examples/ROS
chmod +x build_ros.sh
./build_ros.sh

官方说明:

该ORBSLAM2是在原版本基础上略做修改,其虽然支持ROS,但不是标准的ROS架构,因此不能采用catkin build编译。

  • 以上代码默认发布的话题是给iris_0的提供位姿,如果是给别的机器提供,需要修改代码,再重新编译,修改的方式如下:
# 1.打开.cc文件
vi ~/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/ros_stereo.cc

# 2.找到类似的话题指令,将iris_0修改成目标机器代码
ros::Publisher pose_pub = nh.advertise<geometry_msgs::PoseStamped>("/iris_0/mavros/vision_pose/pose", 100);

四、启动Gazebo仿真

4.1 启动PX4仿真,以indoor1.launch为例,其余场景同理:

cd PX4_Firmware
roslaunch px4 indoor1.launch

4.2 打开新terminal,启动ORBSLAM2:

cd ~//catkin_ws/src/ORB_SLAM2
sh xtdrone_run_stereo.sh

视觉定位信息就通过mavros发到PX4,可以在PX4仿真终端看到相关信息(步骤 4.1)

注意,此步骤XTDrone给的路径操作在我本机上是不相同的,不知道是否为个例,启动时需要注意自己的启动脚本所在位置:

cd ~/catkin_ws/scripts/
sh xtdrone_run_stereo.sh

如何确定自己的路径呢?正确的路经包含的文件如下,可以参考:

ganahe@ganahe-Nitro-AN515-51:~/catkin_ws/src/ORB_SLAM2$ ls -lath
total 684K
-rw-r--r--  1 ganahe ganahe 431K 3月  14 15:52 FrameTrajectory_KITTI_Format.txt
-rw-r--r--  1 ganahe ganahe 115K 3月  14 15:52 FrameTrajectory_TUM_Format.txt
-rw-r--r--  1 ganahe ganahe 1.7K 3月  14 15:52 KeyFrameTrajectory_TUM_Format.txt
drwxr-xr-x 10 ganahe ganahe 4.0K 3月  14 00:36 .
drwxr-xr-x  2 ganahe ganahe 4.0K 3月  14 00:12 lib
drwxr-xr-x  3 ganahe ganahe 4.0K 3月  14 00:10 build
drwxr-xr-x  2 ganahe ganahe 4.0K 3月  14 00:10 Vocabulary
-rw-r--r--  1 ganahe ganahe   81 3月  14 00:09 xtdrone_run_stereo.sh
-rw-r--r--  1 ganahe ganahe   73 3月  14 00:09 xtdrone_run_rgbd.sh
-rw-r--r--  1 ganahe ganahe   69 3月  14 00:09 log.sh
-rw-r--r--  1 ganahe ganahe   78 3月  14 00:09 run_euroc.sh
-rwxr-xr-x  1 ganahe ganahe  116 3月  14 00:09 build_ros.sh
-rwxr-xr-x  1 ganahe ganahe  479 3月  14 00:09 build.sh
-rw-r--r--  1 ganahe ganahe  35K 3月  14 00:09 License-gpl.txt
-rw-r--r--  1 ganahe ganahe  447 3月  14 00:09 LICENSE.txt
-rw-r--r--  1 ganahe ganahe  14K 3月  14 00:09 README.md
-rw-r--r--  1 ganahe ganahe 2.9K 3月  14 00:09 CMakeLists.txt
-rw-r--r--  1 ganahe ganahe 1.8K 3月  14 00:09 Dependencies.md
-rw-r--r--  1 ganahe ganahe  552 3月  14 00:09 .gitignore
drwxr-xr-x  2 ganahe ganahe 4.0K 3月  13 16:58 src
drwxr-xr-x  2 ganahe ganahe 4.0K 3月  13 16:58 include
drwxr-xr-x  2 ganahe ganahe 4.0K 3月  13 16:58 cmake_modules
drwxr-xr-x  4 ganahe ganahe 4.0K 3月  13 16:58 Thirdparty
drwxr-xr-x  6 ganahe ganahe 4.0K 3月  13 16:58 Examples
drwxr-xr-x  3 ganahe ganahe 4.0K 3月  13 16:58 ..

4.3 打开新的终端,建立键盘与Px4的通信:

cd ~/XTDrone/communication
python multirotor_communication.py iris 0

4.4 建立通信后,启动键盘控制无人机飞行查看效果:

cd ~/XTDrone/control/keyboard
python multirotor_keyboard_control.py iris 1 vel

1

file

2

file

参考文献

[1]stevenlovegrove/Pangolin from Github
[2]肖昆 / XTDrone from gitee
[3]视觉SLAM