# VINS-mono详细解读与实现

VINS-mono详细解读

## 前言

Vins-mono是香港科技大学开源的一个VIO算法，https://github.com/HKUST-Aerial-Robotics/VINS-Mono，是用紧耦合方法实现的，通过单目+IMU恢复出尺度，效果非常棒。

## 3.正常的跟踪

### 3.3cere优化

3.3.1与先验值的残差

//每个关键帧的位姿与先验值的不同，会造成残差项增大

Eigen::Map<Eigen::VectorXd>(residuals, n) = marginalization_info->linearized_residuals + marginalization_info->linearized_jacobians * dx;

### 3.3.4边缘化

H*x=JT*residuals，H=JT*J。

## 5.流程图

VIN-SLAM实现转载自博客：https://www.cnblogs.com/Jessica-jie/p/6950604.html方便自己使用参考学习

## 期刊分享SLAMVINS-Mono：一种稳健的单目视觉惯性状态估计器 下

第一部分是测量处理前端，负责提取并跟踪每个新图像帧的特征，及帧间IMU数据预积分。


 

VINS-mono详细解读

VINS-Mono is a real-time SLAM framework for Monocular Visual-Inertial Systems. It uses an optimization-based sliding window formulation for providing high-accuracy visual-inertial odometry. It features efficient IMU pre-integration with bias correction, automatic estimator initialization, online extrinsic calibration, failure detection and recovery, loop detection, and global pose graph optimization. VINS-Mono is primarily designed for state estimation and feedback control of autonomous drones, but it is also capable of providing accurate localization for AR applications. This code runs on Linux, and is fully integrated with ROS. For iOS mobile implementation, please go to VINS-Mobile.

https://github.com/HKUST-Aerial-Robotics/VINS-Mono

1.运行环境

Ubuntu 14.04, ROS Indigo, OpenCV 3.1.0, Eigen 3.2.0,Ceres Solver

## 2. Build VINS-Mono on ROS

Clone the repository and catkin_make:

cd ~/catkin_ws/src
git clone git@github.com:HKUST-Aerial-Robotics/VINS-Mono.git
cd ../
catkin_make
source ~/catkin_ws/devel/setup.bash

## 3. Performance on EuRoC dataset

3.1Download EuRoC MAV Dataset.Although it contains stereo cameras, we only use one camera.

3.2 Open three terminals, launch the vins_estimator , rviz and play the bag file respectively. Take MH_05 as example:

[1]roslaunch vins_estimator euroc.launch    ///estimation
roslaunch benchmark_publisher publish.launch     ///ground-truth
[2]roslaunch vins_estimator vins_rviz.launch
等同于---rosrun rviz rviz -d /home/wj/catkin_ws/src/VINS-Mono/config/vins_rviz_config.rviz
[3]rosbag play YOUR_PATH_TO_DATASET/MH_05_difficult.bag
---rosbag play /home/wj/Downloads/dataset/EuRoC/ROS_bag/MH_05_difficult.bag 

### 注意：***.launch要在其工作空间执行.

wj@wj-Inspiron-5437:~$cd catkin_ws wj@wj-Inspiron-5437:~/catkin_ws$ source ~/catkin_ws/devel/setup.bash
wj@wj-Inspiron-5437:~/catkin_ws$roslaunch vins_estimator euroc.launch wj@wj-Inspiron-5437:~$ cd catkin_ws
wj@wj-Inspiron-5437:~/catkin_ws$source ~/catkin_ws/devel/setup.bash wj@wj-Inspiron-5437:~/catkin_ws$ roslaunch benchmark_publisher publish.launch

结果图：

# 解析：

wj@wj-Inspiron-5437:~/catkin_ws$roslaunch vins_estimator euroc.launch SUMMARY ======== PARAMETERS * /feature_tracker/config_file: /home/wj/catkin_w... * /feature_tracker/vins_folder: /home/wj/catkin_w... * /rosdistro: indigo * /rosversion: 1.11.20 * /vins_estimator/config_file: /home/wj/catkin_w... * /vins_estimator/vins_folder: /home/wj/catkin_w... NODES / feature_tracker (feature_tracker/feature_tracker) vins_estimator (vins_estimator/vins_estimator) auto-starting new master process[master]: started with pid [4194] ROS_MASTER_URI=http://localhost:11311 setting /run_id to d4e07290-fea5-11e7-92da-bc8556c5ff8b process[rosout-1]: started with pid [4207] started core service [/rosout] process[feature_tracker-2]: started with pid [4211] process[vins_estimator-3]: started with pid [4222] [ INFO] [1516537385.770250050]: init begins [ INFO] [1516537385.783868675]: Loaded config_file: /home/wj/catkin_ws/src/VINS-Mono/feature_tracker/../config/euroc/euroc_config.yaml [ INFO] [1516537385.786188731]: Loaded vins_folder: /home/wj/catkin_ws/src/VINS-Mono/feature_tracker/../config/../ [ WARN] [1516537385.786329200]: Optimize extrinsic param around initial guess! [ INFO] [1516537385.786765223]: Extrinsic_R : 2.22045e-16 -1 0 1 2.22045e-16 0 0 0 1 [ INFO] [1516537385.786810735]: Extrinsic_T : -0.02 -0.06 0.01 [ WARN] [1516537385.786861452]: waiting for image and imu... [ WARN] [1516537385.830039004]: LOOP_CLOSURE true voc file: /home/wj/catkin_ws/src/VINS-Mono/feature_tracker/../config/..//support_files/brief_k10L6.bin loop start load vocabulary loop closure init finish    wj@wj-Inspiron-5437:~/catkin_ws$ roslaunch benchmark_publisher publish.launch

SUMMARY
========

PARAMETERS
* /benchmark_publisher/data_name: /home/wj/catkin_w...
* /rosdistro: indigo
* /rosversion: 1.11.21

NODES
/
benchmark_publisher (benchmark_publisher/benchmark_publisher)

ROS_MASTER_URI=http://localhost:11311

core service [/rosout] found
process[benchmark_publisher-1]: started with pid [6334]
[ INFO] [1520410994.189896520]: Loaded data_name: /home/wj/catkin_ws/src/VINS-Mono/benchmark_publisher/config/MH_05_difficult/data.csv
[ INFO] [1520410994.284550074]: Data loaded: 22212

4.AR Demo

4.2 Open three terminals, launch the ar_demo, rviz and play the bag file respectively.We put one 0.8m x 0.8m x 0.8m virtual box in front of your view.

 roslaunch ar_demo 3dm_bag.launch
roslaunch ar_demo ar_rviz.launch
rosbag play /home/wj/Downloads/dataset/ar_box.bag ---YOUR_PATH_TO_DATASET

VINS-Mono代码注释以及公式推导：https://github.com/QingSimon/VINS-Mono-code-annotation

https://blog.csdn.net/wangshuailpp/article/details/78461171
https://blog.csdn.net/houlianfeng/article/details/79525854
https://blog.csdn.net/houlianfeng/article/details/79626657
https://blog.csdn.net/houlianfeng/article/details/79713333
https://www.cnblogs.com/ilekoaiq/p/8836970.html