SVO2.0 - yuhannah/skills_map GitHub Wiki

SVO2.0

编译运行

  • 安装ubuntu16.04

    OPEN_VINS、VINS_Mono、ORB_SLAM2都支持ubuntu16.04,但SVO2.0支持ubuntu18.04和ubuntu20.04,选择大部分算法支持的ubuntu16.04。

  • 安装ROS Kinetic(自带OpenCV和Eigen3)

    • sources.list

      sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
    • set up keys

      sudo apt install curl # if you haven't already installed curl
      curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -

      网络不好时报错,多试几次会OK。

      gpg: no valid OpenPGP data found.
    • up date package

      sudo apt-get update
    • install,安装需要很长时间

      sudo apt-get install ros-kinetic-desktop-full
    • environment setup

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

      sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
    • initialize rosdep

      sudo apt install python-rosdep
      sudo rosdep init
      rosdep update

      网络不好时会报错,多试几次会OK。

      ERROR: cannot download default sources list from:
      https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
      Website may be down.
    • install tools

      sudo apt-get install python-catkin-tools python-vcstool
    • 查看Eigen3版本,ros安装了Eigen3.2.92

      pkg-config --modversion eigen3
      3.2.92
    • 查看OpenCV版本,ros安装了OpenCV3.3.1

      sudo find / -iname "*opencv*"
      /opt/ros/kinetic/include/opencv-3.3.1-dev
  • 安装Eigen3(已有3.2.92<3.3.4,版本低,使用项目自带的版本)

  • 安装OpenCV(已有3.3.1>2.4.3,跳过)

  • 编译SVO2.0(有34个packages需要编译,有多个仓库需要编译时下载!!)

    mkdir svo_ws && cd svo_ws
    # see below for the reason for specifying the eigen path
    catkin config --init --mkdirs --extend /opt/ros/<ROS-DISTRO> --cmake-args -DCMAKE_BUILD_TYPE=Release -DEIGEN3_INCLUDE_DIR=/usr/include/eigen3
    cd src
    git clone [email protected]:uzh-rpg/rpg_svo_pro_open.git
    vcs-import < ./rpg_svo_pro_open/dependencies.yaml
    touch minkindr/minkindr_python/CATKIN_IGNORE
    # vocabulary for place recognition
    cd rpg_svo_pro_open/svo_online_loopclosing/vocabularies && ./download_voc.sh
    cd ../../..

    在执行vcs-import步骤时,需要下载依赖仓库,报错连不上github:

    === ./catkin_simple (git) ===
    Could not determine ref type of version: Warning: Permanently added 'github.com,140.82.113.3' (ECDSA) to the list of known hosts.
    Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    === ./ceres_catkin (git) ===
    Could not determine ref type of version: Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    === ./cmake_external_project_catkin (git) ===
    Could not determine ref type of version: Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    === ./dbow2_catkin (git) ===
    Could not determine ref type of version: Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    === ./eigen_catkin (git) ===
    Could not determine ref type of version: Warning: Permanently added the ECDSA host key for IP address '140.82.114.4' to the list of known hosts.
    Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    === ./eigen_checks (git) ===
    Could not determine ref type of version: Warning: Permanently added the ECDSA host key for IP address '140.82.112.4' to the list of known hosts.
    Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    === ./fast_neon (git) ===
    Could not determine ref type of version: Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    === ./gflags_catkin (git) ===
    Could not determine ref type of version: Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    === ./glog_catkin (git) ===
    Could not determine ref type of version: Connection reset by 140.82.113.4 port 22
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    === ./minkindr (git) ===
    Could not determine ref type of version: Connection reset by 140.82.113.4 port 22
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    === ./minkindr_ros (git) ===
    Could not determine ref type of version: Connection reset by 140.82.113.3 port 22
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    === ./opengv (git) ===
    Could not determine ref type of version: Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    === ./rpg_trajectory_evaluation (git) ===
    Could not determine ref type of version: Warning: Permanently added the ECDSA host key for IP address '20.205.243.166' to the list of known hosts.
    Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.

    这个错误表明 Git 没有 SSH 密钥权限没有访问仓库的权限。使用 HTTPS 替代 SSH。修改dependencies.yaml文件中的地址,将git@替换成https://,重新执行命令。或者单独克隆文件中的仓库:

    repositories:
      catkin_simple:
        type: git
        url: https://github.com/catkin/catkin_simple.git
        version: master
      cmake_external_project_catkin:
        type: git
        url: https://github.com/zurich-eye/cmake_external_project_catkin.git
        version: master
      eigen_catkin:
        type: git
        url: https://github.com/ethz-asl/eigen_catkin.git
        version: master
      eigen_checks:
        type: git
        url: https://github.com/ethz-asl/eigen_checks.git
        version: master
      fast_neon:
        type: git
        url: https://github.com/uzh-rpg/fast_neon.git
        version: master
      gflags_catkin:
        type: git
        url: https://github.com/ethz-asl/gflags_catkin.git
        version: master
      glog_catkin:
        type: git
        url: https://github.com/ethz-asl/glog_catkin.git
        version: master
      minkindr:
        type: git
        url: https://github.com/ethz-asl/minkindr.git
        version: master
      opengv:
        type: git
        url: https://github.com/ethz-asl/opengv.git
        version: master
      minkindr_ros:
        type: git
        url: https://github.com/ethz-asl/minkindr_ros.git
        version: master
      ceres_catkin:
        type: git
        url: https://github.com/ethz-asl/ceres_catkin.git
        version: master
      dbow2_catkin:
        type: git
        url: https://github.com/uzh-rpg/dbow2_catkin.git
        version: master
      rpg_trajectory_evaluation:
        type: git
        url: https://github.com/uzh-rpg/rpg_trajectory_evaluation.git
        version: dev

    克隆完成所有仓库。

    查看编译顺序:

    catkin build --dry-run --verbose

    输出所有的packages:

    [build] Found '34' packages in 0.0 seconds.                                                                                                                                                                
    Packages to be built:
    - catkin_simple                 (catkin)
    - cmake_external_project_catkin (catkin)
    - dbow2_catkin                  (catkin)
    - eigen_catkin                  (catkin)
    - fast                          (catkin)
    - gflags_catkin                 (catkin)
    - glog_catkin                   (catkin)
    - ceres_catkin                  (catkin)
    - eigen_checks                  (catkin)
    - minkindr                      (catkin)
    - minkindr_conversions          (catkin)
    - opengv                        (catkin)
    - rpg_common                    (catkin)
    - rpg_trajectory_evaluation     (catkin)
    - rqt_svo                       (catkin)
    - svo_cmake                     (catkin)
    - svo_msgs                      (catkin)
    - vikit_common                  (catkin)
    - vikit_cameras                 (catkin)
    - svo_common                    (catkin)
    - svo_pgo                       (catkin)
    - svo_online_loopclosing        (catkin)
    - svo_vio_common                (catkin)
    - svo_global_map                (catkin)
    - vikit_py                      (catkin)
    - vikit_ros                     (catkin)
    - svo_test_utils                (catkin)
    - vikit_solver                  (catkin)
    - svo_direct                    (catkin)
    - svo_img_align                 (catkin)
    - svo_tracker                   (catkin)
    - svo                           (catkin)
    - svo_ceres_backend             (catkin)
    - svo_ros                       (catkin)
    - svo_benchmarking              (catkin)
    Total packages: 34

    查看依赖关系:

     catkin list --deps --recursive-depends-on

    编译eigen_catkin一直卡在12%不动,也不报错。清空编译记录和日志,屏蔽补丁,单独编译报错:

    # 1. 手动删除 eigen_catkin 相关文件
    cd /home/yu/ros_projects/catkin_ws_svo2.0
    
    # 删除 devel 空间中的 eigen_catkin
    rm -rf devel/include/eigen3
    rm -rf devel/share/eigen_catkin
    rm -rf devel/lib/pkgconfig/eigen_catkin.pc
    
    # 删除 build 空间中的 eigen_catkin
    rm -rf build/eigen_catkin
    
    # 删除 logs
    rm -rf logs/eigen_catkin
    
    # 2. 修复 catkin 记录
    # 创建空的 devel_manifest.txt(如果需要)
    mkdir -p .catkin_tools/profiles/default/packages/eigen_catkin
    touch .catkin_tools/profiles/default/packages/eigen_catkin/devel_manifest.txt
    
    # 3. 重新编译
    catkin build eigen_catkin -j1 --no-deps

    报错找不到DartConfiguration.tcl文件:

    CMake Error at cmake/EigenConfigureTesting.cmake:25 (file):
    
      file failed to open for reading (No such file or directory):
    
    
    
        /home/yu/ros_projects/catkin_ws_svo2.0/build/eigen_catkin/eigen_src-prefix/src/eigen_src-build/DartConfiguration.tcl
    
    Call Stack (most recent call first):
    
      CMakeLists.txt:419 (include)
    
    
    
    
    
    CMake Error at cmake/EigenConfigureTesting.cmake:27 (string):
    
      string sub-command REGEX, mode MATCH needs at least 5 arguments total to
    
      command.
    
    Call Stack (most recent call first):
    
      CMakeLists.txt:419 (include)
    
    
    
    
    
    CMake Error at cmake/EigenConfigureTesting.cmake:29 (string):
    
      string sub-command REGEX, mode MATCH needs at least 5 arguments total to
    
      command.
    
    Call Stack (most recent call first):
    
      CMakeLists.txt:419 (include)
    
    
    
    
    
    CMake Error at cmake/EigenConfigureTesting.cmake:31 (string):
    
      string sub-command REGEX, mode REPLACE needs at least 6 arguments total to
    
      command.
    
    Call Stack (most recent call first):
    
      CMakeLists.txt:419 (include)

    在本地仓库中编译报了同样的错误。重新克隆eigen仓库,清空编译记录和日志,打开补丁,再次单独编译通过。后续发现,重新编译也可能卡住,最好清空eigen仓库的补丁修改后再次编译。

    编译到svo_common时报错:

    Errors     << svo_common:make /home/yu/ros_projects/catkin_ws_svo2.0/logs/svo_common/build.make.000.log
    In file included from /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_common/src/point.cpp:9:0:
    /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_common/include/svo/common/point.h:97:15: error: ‘atomic_uint64_t’ in namespace ‘std’ does not name a type
       static std::atomic_uint64_t global_map_value_version_;
                   ^
    In file included from /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_common/include/svo/common/frame.h:19:0,
                     from /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_common/src/frame.cpp:9:
    /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_common/include/svo/common/point.h:97:15: error: ‘atomic_uint64_t’ in namespace ‘std’ does not name a type
       static std::atomic_uint64_t global_map_value_version_;
                   ^
    /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_common/src/point.cpp:39:6: error: ‘atomic_uint64_t’ in namespace ‘std’ does not name a type
     std::atomic_uint64_t Point::global_map_value_version_ {0u};
          ^
    cc1plus: error: unrecognized command line option ‘-Wno-int-in-bool-context’ [-Werror]
    cc1plus: error: unrecognized command line option ‘-Wno-int-in-bool-context’ [-Werror]
    cc1plus: all warnings being treated as errors
    make[2]: *** [CMakeFiles/svo_common.dir/src/frame.cpp.o] Error 1
    make[2]: *** Waiting for unfinished jobs....
    cc1plus: error: unrecognized command line option ‘-Wno-int-in-bool-context’ [-Werror]
    cc1plus: error: unrecognized command line option ‘-Wno-int-in-bool-context’ [-Werror]
    cc1plus: all warnings being treated as errors
    make[2]: *** [CMakeFiles/svo_common.dir/src/point.cpp.o] Error 1
    make[1]: *** [CMakeFiles/svo_common.dir/all] Error 2
    make: *** [all] Error 2

    是编译器版本较低,需要适配代码,修改rpg_svo_pro_open/svo_cmake/cmake/Modules/SvoSetup.cmake,根据GCC版本添加不同的编译选项:

    # 检查编译器版本
    EXECUTE_PROCESS(
      COMMAND ${CMAKE_CXX_COMPILER} --version
      OUTPUT_VARIABLE COMPILER_INFO_FULL
      OUTPUT_STRIP_TRAILING_WHITESPACE
    )
    STRING(REGEX MATCH "[^\n]*" COMPILER_INFO "${COMPILER_INFO_FULL}")
    MESSAGE(STATUS "Compiler: ${COMPILER_INFO}")
    
    # 检查 GCC 版本以确定是否支持某些选项
    IF(CMAKE_COMPILER_IS_GNUCXX)
      EXECUTE_PROCESS(
        COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
        OUTPUT_VARIABLE GCC_VERSION
        OUTPUT_STRIP_TRAILING_WHITESPACE
      )
      MESSAGE(STATUS "GCC version: ${GCC_VERSION}")
      
      # 解析主版本号
      STRING(REGEX MATCH "^[0-9]+" GCC_MAJOR_VERSION ${GCC_VERSION})
      
      # 根据版本设置选项
      IF(${GCC_MAJOR_VERSION} EQUAL 6 OR ${GCC_MAJOR_VERSION} GREATER 6)
        SET(EXTRA_WARN_FLAGS "-Wno-int-in-bool-context")
      ELSE()
        SET(EXTRA_WARN_FLAGS "")
        MESSAGE(WARNING "GCC version ${GCC_VERSION} may not support all compiler flags")
      ENDIF()
    ELSE()
      SET(EXTRA_WARN_FLAGS "-Wno-int-in-bool-context")
    ENDIF()
    
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -Wall -Werror -D_LINUX -D_REENTRANT -march=native -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unknown-pragmas -Wno-unused-but-set-parameter ${EXTRA_WARN_FLAGS} -Wno-maybe-uninitialized -Wno-unused-function")

    修改rpg_svo_pro_open/svo_common/include/svo/common/point.hrpg_svo_pro_open/svo_common/src/point.cpp中的std::atomic_uint64_tstd::atomic<std::uint64_t>

    // point.h
    // 原代码:
    // static std::atomic_uint64_t global_map_value_version_;
    
    // 修改为:
    static std::atomic<std::uint64_t> global_map_value_version_;
    
    // point.cpp
    // 原代码:
    // std::atomic_uint64_t Point::global_map_value_version_ {0u};
    
    // 修改为:
    std::atomic<std::uint64_t> Point::global_map_value_version_ {0u};
  • 编译(无global map)

    catkin build

    报错,找不到eigen_src/目录,原因是ROS自带的Eigen版本为3.2.92,比SVO2.0指定的最低版本3.3.4要低,需要重新下载Eigen仓库并编译。

    Warnings   << eigen_catkin:make /home/yu/ros_projects/catkin_ws_svo2.0/logs/eigen_catkin/build.make.000.log
    abort: repository /home/yu/ros_projects/catkin_ws_svo2.0/build/eigen_catkin/eigen_src-prefix/src/eigen_src not found!
    abort: repository /home/yu/ros_projects/catkin_ws_svo2.0/build/eigen_catkin/eigen_src-prefix/src/eigen_src not found!
    CMake Warning (dev) in bench/spbench/CMakeLists.txt:
      A logical block opening on the line
    
        /home/yu/ros_projects/catkin_ws_svo2.0/build/eigen_catkin/eigen_src-prefix/src/eigen_src/bench/spbench/CMakeLists.txt:51 (if)
    
      closes on the line
    
        /home/yu/ros_projects/catkin_ws_svo2.0/build/eigen_catkin/eigen_src-prefix/src/eigen_src/bench/spbench/CMakeLists.txt:63 (endif)
    
      with mis-matching arguments.
    This warning is for project developers.  Use -Wno-dev to suppress it.

    报错,连不上github,克隆dbow2_src失败:

    Errors     << dbow2_catkin:make /home/yu/ros_projects/catkin_ws_svo2.0/logs/dbow2_catkin/build.make.000.log
    Cloning into 'dbow2_src'...
    Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.

    后续查询所有仓库的CMakeLists.txt文件,将所有需要克隆仓库的地方全部修改成已有仓库。

    • 修改ceres_catkin/CMakeLists.txt,将克隆仓库替换成本地仓库,指定本地仓库路径:

      # 指定ceres-solver本地仓库的目录
      set(CERES_SOURCE_DIR "/home/yu/sources/ceres-solver")
      message(STATUS "CERES_SOURCE_DIR=${CERES_SOURCE_DIR}")
      
      ExternalProject_Add(ceres_src
        # 指定本地仓库路径
        SOURCE_DIR ${CERES_SOURCE_DIR}
        # 屏蔽克隆
        #GIT_REPOSITORY https://github.com/ceres-solver/ceres-solver.git
        #GIT_TAG ${VERSION}
        # 禁用下载
        DOWNLOAD_COMMAND ""
        # 禁用更新
        UPDATE_COMMAND ""
        CONFIGURE_COMMAND cmake
          -DGFLAGS=ON
          -DGFLAGS_LIBRARY_DIR_HINTS=${gflags_catkin_LIBRARIES}
          -DGFLAGS_INCLUDE_DIR_HINTS=${gflags_catkin_INCLUDE_DIR}
          -DGLOG_INCLUDE_DIR_HINTS=${glog_catkin_INCLUDE_DIR}
          -DGLOG_LIBRARY_DIR_HINTS=${glog_catkin_LIBRARIES}
          -DBUILD_DOCUMENTATION=OFF
          -DSUITESPARSE_INCLUDE_DIR_HINTS=${suitesparse_PREFIX}/include/suitesparse
          -DSUITESPARSE_LIBRARY_DIR_HINTS=${suitesparse_PREFIX}/lib
          -DBUILD_EXAMPLES=OFF
          -DBUILD_TESTING=OFF
          -DCMAKE_INSTALL_PREFIX=${CATKIN_DEVEL_PREFIX} -DBUILD_SHARED_LIBS=ON
          -DCMAKE_VERBOSE_MAKEFILE=ON
          -DCMAKE_BUILD_TYPE:STRING=Release
          -DCMAKE_CXX_FLAGS=-fPIC
          -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON
          -DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON
          # 指定本地仓库路径
          ${CERES_SOURCE_DIR}
          #../ceres_src
        BUILD_COMMAND make -j8
        INSTALL_COMMAND make install -j8
      )
    • 修改dbow2_catkin/CMakeLists.txt,将克隆仓库替换成本地仓库,指定本地仓库路径:

      # 指定DBoW2本地仓库的目录
      set(DBOW2_SOURCE_DIR "/home/yu/sources/DBoW2")
      message(STATUS "DBOW2_SOURCE_DIR=${DBOW2_SOURCE_DIR}")
      
      ExternalProject_Add(dbow2_src
        # 指定本地仓库路径
        SOURCE_DIR ${DBOW2_SOURCE_DIR}
        # 屏蔽克隆
        #GIT_REPOSITORY [email protected]:dorian3d/DBoW2.git
        # 禁用下载
        DOWNLOAD_COMMAND ""
        # 禁用更新
        UPDATE_COMMAND ""
        CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CATKIN_DEVEL_PREFIX}
        BUILD_COMMAND CXXFLAGS=-I${CATKIN_DEVEL_PREFIX}/include make
        INSTALL_COMMAND make install
      )
    • 修改eigen_catkin/CMakeLists.txt,将克隆仓库替换成本地仓库,指定本地仓库路径:

        # 指定eigen本地仓库的目录
        set(EIGEN_SOURCE_DIR "/home/yu/sources/eigen")
        message(STATUS "EIGEN_SOURCE_DIR=${EIGEN_SOURCE_DIR}")
      
        ExternalProject_Add(eigen_src
          # 指定本地仓库路径
          SOURCE_DIR ${EIGEN_SOURCE_DIR}
          # 禁用下载
          DOWNLOAD_COMMAND ""
          # 禁用更新
          UPDATE_COMMAND ""
          # 屏蔽克隆
          #URL https://gitlab.com/libeigen/eigen/-/archive/3.3.4/eigen-3.3.4.tar.bz2
          # 屏蔽校验
          #URL_MD5 6e74a04aeab3417120f1bdef6f3b4881
          PATCH_COMMAND patch -p0 < ${CMAKE_CURRENT_SOURCE_DIR}/StdVector.patch && patch -p0 < ${CMAKE_CURRENT_SOURCE_DIR}/DisableTests.patch && patch -p0 < ${CMAKE_CURRENT_SOURCE_DIR}/FixWarning.patch
          CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CATKIN_DEVEL_PREFIX} -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_TESTING=OFF
        )
    • 修改gflags_catkin/CMakeLists.txt,将克隆仓库替换成本地仓库,指定本地仓库路径:

      # 指定gflags本地仓库的目录
      set(GFLAGS_SOURCE_DIR "/home/yu/sources/gflags")
      message(STATUS "GFLAGS_SOURCE_DIR=${GFLAGS_SOURCE_DIR}")
      
      ExternalProject_Add(
        gflags_src
        # 指定本地仓库路径
        SOURCE_DIR ${GFLAGS_SOURCE_DIR}
        # 屏蔽克隆
        #URL https://github.com/gflags/gflags/archive/v2.2.1.zip
        # 屏蔽校验
        #URL_MD5 2d988ef0b50939fb50ada965dafce96b
        # 禁用下载
        DOWNLOAD_COMMAND ""
        # 禁用更新
        UPDATE_COMMAND ""
        CONFIGURE_COMMAND 
           # 指定本地仓库路径
           #cd ../gflags_src &&
           cmake ${GFLAGS_SOURCE_DIR}
           #cmake .
             -DCMAKE_INSTALL_PREFIX:PATH=${CATKIN_DEVEL_PREFIX}
             -DBUILD_SHARED_LIBS:BOOL=true
             -DGFLAGS_NAMESPACE:STRING=google
             -DCMAKE_BUILD_TYPE:STRING=Release
             -DCMAKE_TOOLCHAIN_FILE:STRING=${CMAKE_TOOLCHAIN_FILE}
        BUILD_COMMAND 
           #cd ../gflags_src && 
           make -j 8
        INSTALL_COMMAND 
           #cd ../gflags_src && 
           make install -j 8
      )
    • 修改glog_catkin/CMakeLists.txt,将克隆仓库替换成本地仓库,指定本地仓库路径:

        # 指定glog本地仓库的目录
        set(GLOG_SOURCE_DIR "/home/yu/sources/glog")
        message(STATUS "GLOG_SOURCE_DIR=${GLOG_SOURCE_DIR}")
      
        set(VERSION 0.3.5)
        ExternalProject_Add(glog_src
          # 指定本地仓库路径
          SOURCE_DIR ${GLOG_SOURCE_DIR}
          # 屏蔽克隆
          #URL https://github.com/google/glog/archive/v${VERSION}.zip
          # 禁用下载
          DOWNLOAD_COMMAND ""
          # 禁用更新
          UPDATE_COMMAND ""
          PATCH_COMMAND patch -p0 < ${CMAKE_CURRENT_SOURCE_DIR}/fix-unused-typedef-warning.patch
          CONFIGURE_COMMAND 
            #cd ../glog_src/ && 
            ${GLOG_SOURCE_DIR}/autoreconf -fi && ${GLOG_SOURCE_DIR}/configure --with-pic
            --with-gflags=${gflags_catkin_PREFIX}
            --prefix=${CATKIN_DEVEL_PREFIX}
          BUILD_COMMAND 
            #cd ../glog_src/ && 
            make -j 8
          INSTALL_COMMAND 
            #cd ../glog_src/ && 
            make install -j 8
        )
  • 编译(有global map)

    打开global map功能:

    rm rpg_svo_pro_open/svo_global_map/CATKIN_IGNORE
    
    # 修改svo_cmake/cmake/Modules/SvoSetup.cmake
    SET(USE_GLOBAL_MAP TRUE)

    克隆GTSAM,或者先克隆,再切换tag4.0.3

    git clone --branch 4.0.3 [email protected]:borglab/gtsam.git

    修改GTSAM的编译选项,这里要修改使用系统Eigen3库。系统自带是Eigen3.2.9,GTSAM自带的是Eigen3.3.7,而SVO2.0使用的是Eigen3.3.4,都不一样。先跳过第一个修改,用GTSAM自带的Eigen3库编译看看。如果报错,再添加cmake参数-DGTSAM_USE_SYSTEM_EIGEN=ON看看:

    # 1. gtsam/CMakelists.txt: use system Eigen
    -option(GTSAM_USE_SYSTEM_EIGEN "Find and use system-installed Eigen. If 'off', use the one bundled with GTSAM" OFF)
    +option(GTSAM_USE_SYSTEM_EIGEN "Find and use system-installed Eigen. If 'off', use the one bundled with GTSAM" ON)
    # 2. gtsam/cmake/GtsamBuildTypes: disable avx instruction set
    # below the line `list_append_cache(GTSAM_COMPILE_OPTIONS_PUBLIC "-march=native")`
    list_append_cache(GTSAM_COMPILE_OPTIONS_PUBLIC "-mno-avx")

    编译安装GTSAM,使用GTSAM自带的Eigen3.3.7:

    mkdir build
    cd build
    cmake .. -DGTSAM_USE_SYSTEM_EIGEN=OFF
    make -j6
    sudo make install

    编译SVO2.0:

    catkin build

    报错,是编译器版本较低,需要适配代码:

    Errors     << svo_global_map:make /home/yu/ros_projects/catkin_ws_svo2.0/logs/svo_global_map/build.make.000.log                                                                                            
    In file included from /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_global_map/src/gtsam/gtsam_optimizer.cpp:9:0:
    /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_global_map/include/svo/gtsam/gtsam_optimizer.h:63:57: error: field ‘latest_estimate_state_index_’ has incomplete type ‘std::atomic<int>’
       std::atomic<BundleId> latest_estimate_state_index_ {-1}; // Id of last state in estimate.
                                                             ^
    In file included from /usr/include/c++/5/bits/shared_ptr_atomic.h:33:0,
                     from /usr/include/c++/5/memory:83,
                     from /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_global_map/include/svo/gtsam/gtsam_optimizer.h:3,
                     from /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_global_map/src/gtsam/gtsam_optimizer.cpp:9:
    /usr/include/c++/5/bits/atomic_base.h:126:12: note: declaration of ‘struct std::atomic<int>’
         struct atomic;
                ^
    In file included from /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_global_map/src/gtsam/gtsam_optimizer.cpp:9:0:
    /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_global_map/include/svo/gtsam/gtsam_optimizer.h:69:21: error: field ‘quit_thread_’ has incomplete type ‘std::atomic<bool>’
       std::atomic<bool> quit_thread_;
                         ^
    In file included from /usr/include/c++/5/bits/shared_ptr_atomic.h:33:0,
                     from /usr/include/c++/5/memory:83,
                     from /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_global_map/include/svo/gtsam/gtsam_optimizer.h:3,
                     from /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_global_map/src/gtsam/gtsam_optimizer.cpp:9:
    /usr/include/c++/5/bits/atomic_base.h:126:12: note: declaration of ‘struct std::atomic<bool>’
         struct atomic;
                ^
    c++: internal compiler error: Killed (program cc1plus)
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See <file:///usr/share/doc/gcc-5/README.Bugs> for instructions.
    make[2]: *** [CMakeFiles/svo_global_map.dir/src/gtsam/gtsam_optimizer.cpp.o] Error 4
    make[2]: *** Waiting for unfinished jobs....
    c++: internal compiler error: Killed (program cc1plus)
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See <file:///usr/share/doc/gcc-5/README.Bugs> for instructions.
    make[2]: *** [CMakeFiles/svo_global_map.dir/src/global_map.cpp.o] Error 4
    make[1]: *** [CMakeFiles/svo_global_map.dir/all] Error 2
    make: *** [all] Error 2

    修改rpg_svo_pro_open/svo_global_map/include/svo/gtsam/gtsam_optimizer.h

    // 在文件开头添加
    #include <atomic>

    编译通过,但运行报错,没有报错信息。

    卸载使用GTSAM自带的Eigen3.3.7的版本,删除编译记录,重新编译安装GTSAM,使用系统自带的Eigen3.2.9:

    # 卸载使用GTSAM自带的Eigen3.3.7的版本
    sudo make uninstall
    
    # 重新编译使用系统Eigen3.2.9的版本
    cmake .. -DGTSAM_USE_SYSTEM_EIGEN=ON
    make -j6
    sudo make install

    编译SVO2.0:

    catkin build

    报错SVO2.0和GTSAM使用了不同的Eigen3版本:

    Errors     << svo_global_map:make /home/yu/ros_projects/catkin_ws_svo2.0/logs/svo_global_map/build.make.004.log                                                                                            
    In file included from /usr/local/include/gtsam/base/Matrix.h:27:0,
                     from /usr/local/include/gtsam/linear/NoiseModel.h:22,
                     from /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_global_map/include/svo/gtsam/gtsam_optimizer.h:12,
                     from /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_global_map/src/gtsam/gtsam_optimizer.cpp:9:
    /usr/local/include/gtsam/base/Vector.h:73:1: error: static assertion failed: Error: GTSAM was built against a different version of Eigen
     static_assert(
     ^
    In file included from /usr/local/include/gtsam/base/Matrix.h:27:0,
                     from /usr/local/include/gtsam/base/Manifold.h:22,
                     from /usr/local/include/gtsam/base/Lie.h:25,
                     from /usr/local/include/gtsam/base/VectorSpace.h:11,
                     from /usr/local/include/gtsam/geometry/Point2.h:20,
                     from /usr/local/include/gtsam/geometry/Cal3_S2.h:24,
                     from /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_global_map/include/svo/gtsam/graph_manager.h:15,
                     from /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_global_map/src/gtsam/graph_manager.cpp:1:
    /usr/local/include/gtsam/base/Vector.h:73:1: error: static assertion failed: Error: GTSAM was built against a different version of Eigen
     static_assert(
     ^
    In file included from /usr/local/include/gtsam/base/Matrix.h:27:0,
                     from /usr/local/include/gtsam/linear/GaussianFactor.h:24,
                     from /usr/local/include/gtsam/linear/JacobianFactor.h:21,
                     from /usr/local/include/gtsam/linear/RegularJacobianFactor.h:21,
                     from /usr/local/include/gtsam/slam/JacobianFactorQ.h:20,
                     from /usr/local/include/gtsam/slam/SmartFactorBase.h:23,
                     from /usr/local/include/gtsam/slam/SmartProjectionFactor.h:22,
                     from /usr/local/include/gtsam/slam/SmartProjectionPoseFactor.h:22,
                     from /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_global_map/src/global_map.cpp:6:
    /usr/local/include/gtsam/base/Vector.h:73:1: error: static assertion failed: Error: GTSAM was built against a different version of Eigen
     static_assert(
     ^
    make[2]: *** [CMakeFiles/svo_global_map.dir/src/gtsam/gtsam_optimizer.cpp.o] Error 1
    make[2]: *** Waiting for unfinished jobs....
    make[2]: *** [CMakeFiles/svo_global_map.dir/src/global_map.cpp.o] Error 1
    make[2]: *** [CMakeFiles/svo_global_map.dir/src/gtsam/graph_manager.cpp.o] Error 1
    make[1]: *** [CMakeFiles/svo_global_map.dir/all] Error 2
    make: *** [all] Error 2

    要让GTSAM使用SVO2.0一样的Eigen3,先查询到SVO2.0使用的Eigen3库的路径:

    SVO_EIGEN_PATH=$(find /home/yu/ros_projects/catkin_ws_svo2.0 -path "*/include/eigen3/Eigen/Core" 2>/dev/null | head -1 | xargs dirname | xargs dirname)
    echo "SVO Eigen 路径: $SVO_EIGEN_PATH"
    SVO Eigen 路径: /home/yu/ros_projects/catkin_ws_svo2.0/devel/include/eigen3

    修改gtsam/CMakeLists.txt,使用SVO2.0用Eigen3:

    if(GTSAM_USE_SYSTEM_EIGEN)
    else()
    	# Use bundled Eigen include path.
    	# Clear any variables set by FindEigen3
    	# 屏蔽,指定目录
    	#if(EIGEN3_INCLUDE_DIR)
    	#	set(EIGEN3_INCLUDE_DIR NOTFOUND CACHE STRING "" FORCE)
    	#endif()
    
    	# set full path to be used by external projects
    	# this will be added to GTSAM_INCLUDE_DIR by gtsam_extra.cmake.in
    	# 屏蔽,指定目录
    	#set(GTSAM_EIGEN_INCLUDE_FOR_INSTALL "include/gtsam/3rdparty/Eigen/")
    	message(STATUS "EIGEN3_INCLUDE_DIR=${EIGEN3_INCLUDE_DIR}")
    	set(GTSAM_EIGEN_INCLUDE_FOR_INSTALL "${EIGEN3_INCLUDE_DIR}")
    
    	# The actual include directory (for BUILD cmake target interface):
    	# 屏蔽,指定目录
    	#set(GTSAM_EIGEN_INCLUDE_FOR_BUILD "${CMAKE_SOURCE_DIR}/gtsam/3rdparty/Eigen/")
    	set(GTSAM_EIGEN_INCLUDE_FOR_BUILD "${EIGEN3_INCLUDE_DIR}")
    endif()

    卸载使用系统Eigen3.2.9版本的GTSAM,清空编译目录,重新编译安装使用SVO2.0的Eigen3。3.4版本的GTSAM:

    cmake .. -DEIGEN3_INCLUDE_DIR=/home/yu/ros_projects/catkin_ws_svo2.0/devel/include/eigen3

    重新编译SVO2.0:

    catkin build

    编译通过,但运行正常。

  • 运行SVO2.0(无global map)

    • 运行数据集

      # 终端1
      source ~/svo_ws/devel/setup.bash
      # launch svo
      roslaunch svo_ros euroc_vio_mono.launch
      
      # 终端2
      source ~/svo_ws/devel/setup.bash
      # run the EuRoC bag
      rosbag play V2_02_medium.bag -s 10

      报错,未知的参数v,并没有生成日志文件svo-2*.log

      ERROR: unknown command line flag 'v'
      [svo-2] process has died [pid 50362, exit code 1, cmd /home/yu/ros_projects/catkin_ws_svo2.0/devel/lib/svo_ros/svo_node --v=0 __name:=svo __log:=/home/yu/.ros/log/6204bd9e-e15f-11f0-9e05-000c29a2bada/svo-2.log].
      log file: /home/yu/.ros/log/6204bd9e-e15f-11f0-9e05-000c29a2bada/svo-2*.log

      euroc_vio_mono.launch中的节点参数--v=0未知:

        <node pkg="svo_ros" type="svo_node" name="svo" clear_params="true" output="screen" args="--v=0" >

      查看节点支持的参数:

      rosrun svo_ros svo_node --helpfull

      v开头的只有version一个参数:

      svo_node: Warning: SetUsageMessage() never called
      
        Flags from /home/yu/ros_projects/catkin_ws_svo2.0/src/rpg_svo_pro_open/svo_ceres_backend/src/ceres_backend_interface.cpp:
          -extrinsics_sigma_rel_orientation (Relative translation sigma (temporal) of
            camera extrinsics) type: double default: 0
          -extrinsics_sigma_rel_translation (Relative translation sigma (temporal) of
            camera extrinsics) type: double default: 0
      
      
      
        Flags from /home/yu/sources/gflags/src/gflags.cc:
          -flagfile (load flags from file) type: string default: ""
          -fromenv (set flags from the environment [use 'export FLAGS_flag1=value'])
            type: string default: ""
          -tryfromenv (set flags from the environment if present) type: string
            default: ""
          -undefok (comma-separated list of flag names that it is okay to specify on
            the command line even if the program does not define a flag with that
            name.  IMPORTANT: flags in this list that have arguments MUST use the
            flag=value format) type: string default: ""
      
        Flags from /home/yu/sources/gflags/src/gflags_completions.cc:
          -tab_completion_columns (Number of columns to use in output for tab
            completion) type: int32 default: 80
          -tab_completion_word (If non-empty, HandleCommandLineCompletions() will
            hijack the process and attempt to do bash-style command line flag
            completion on this value.) type: string default: ""
      
        Flags from /home/yu/sources/gflags/src/gflags_reporting.cc:
          -help (show help on all flags [tip: all flags can have two dashes])
            type: bool default: false
          -helpfull (show help on all flags -- same as -help) type: bool
            default: false currently: true
          -helpmatch (show help on modules whose name contains the specified substr)
            type: string default: ""
          -helpon (show help on the modules named by this flag value) type: string
            default: ""
          -helppackage (show help on all modules in the main package) type: bool
            default: false
          -helpshort (show help on only the main module for this program) type: bool
            default: false
          -helpxml (produce an xml version of help) type: bool default: false
          -version (show version and build info and exit) type: bool default: false

      支持参数列表里没有符合的,尝试删除该参数:

      <node pkg="svo_ros" type="svo_node" name="svo" clear_params="true" output="screen" >
    • 正常输出所有数据

      Theta -0.00171444
      Theta -0.00569899
      Theta 0.0142994
      Theta 0.00840861
      Will recompute 8 IMU terms.
      [ WARN] [1766645912.803956485]: Backend scale not stable.
      [ WARN] [1766645914.610110041]: Backend scale not stable.
      [ WARN] [1766645918.003401836]: Backend scale not stable.
      [ WARN] [1766645918.657674430]: Backend scale not stable.
      [ WARN] [1766645919.005680395]: Backend scale not stable.
      [ WARN] [1766645919.504601822]: Backend scale not stable.
      [ WARN] [1766645925.252817654]: Backend scale not stable.
      ^C[vis-3] killing on exit
      [svo-2] killing on exit
      [rosout-1] killing on exit
      [master] killing on exit
      shutting down processing monitor...
      ... shutting down processing monitor complete
      done
      [RUNNING]  Bag Time: 1403715418.863469   Duration: 137.145919 / 137.165852
      [RUNNING]  Bag Time: 1403715418.868505   Duration: 137.150954 / 137.165852
      [RUNNING]  Bag Time: 1403715418.873469   Duration: 137.155919 / 137.165852
      
      Done.
  • 运行SVO2.0(有global map)

    • 运行数据集

      # 终端1
      source ~/svo_ws/devel/setup.bash
      # launch svo
      roslaunch svo_ros euroc_global_map_mono.launch
      
      # 终端2
      source ~/svo_ws/devel/setup.bash
      # run the EuRoC bag
      rosbag play V2_02_medium.bag -s 10

      节点参数的错误不在此重复记录了。

    • 正常输出所有数据

      Conditional number threshold for points are negative, will not use the conditional number as a criteria.
      Use both IMU and relative constraints. Will only be used when the integration time is too long.
      E1225 17:25:30.152567 56743 global_map.cpp:124] Use the focal length of the first camera to scale error.Should implement for individual camera in the future.
      
      GraphManager: Initialized noise for default fixation:
      Point:
      isotropic dim=3 sigma=0.0001
      Pose:
      diagonal sigmas[1.74532925e-08; 1.74532925e-08; 1.74532925e-08; 1e-06; 1e-06; 1e-06];
      Visual Inertial inital pose:
        0.616850275             0             0             0             0             0
                  0   0.616850275             0             0             0             0
                  0             0 3.0461742e-16             0             0             0
                  0             0             0         1e-12             0             0
                  0             0             0             0         1e-12             0
                  0             0             0             0             0         1e-12
      GlobalMap: Initialized noise for immature states:
      - Relative Pose:
      diagonal sigmas[0.0872664626; 0.0872664626; 0.0872664626; 0.1; 0.1; 0.1];
      [ INFO] [1766712330.153263559]: SvoNode: Started IMU loop.
      [ INFO] [1766712330.156859983]: Found parameter: imu_topic, value: /imu0
      [ INFO] [1766712333.153772508]: SvoNode: Started Image loop.
      [ WARN] [1766712333.155132357]: Cannot find value for parameter: remote_key_topic, assigning default: svo/remote_key
      [ INFO] [1766712333.159636813]: Found parameter: cam0_topic, value: /cam0/image_raw
      [ INFO] [1766712394.764721967]: DepthFilter: RESET.
      [ INFO] [1766712394.943573665]: Init: Triangulated 167 points
      [ INFO:0] Initialize OpenCL runtime...
      [ WARN] [1766712405.372208624]: Backend scale not stable.
      [RUNNING]  Bag Time: 1403715418.868513   Duration: 137.150963 / 137.165852
      [RUNNING]  Bag Time: 1403715418.873474   Duration: 137.155923 / 137.165852
      [RUNNING]  Bag Time: 1403715418.878517   Duration: 137.160966 / 137.165852
      
      Done.
⚠️ **GitHub.com Fallback** ⚠️