cartographer-project / cartographer

Cartographer is a system that provides real-time simultaneous localization and mapping (SLAM) in 2D and 3D across multiple platforms and sensor configurations.
Apache License 2.0
7.09k stars 2.25k forks source link

How to run cartographer stand-alone without being a submodule #1777

Closed JakeInit closed 3 years ago

JakeInit commented 3 years ago

I have been able to run cartographer without ROS while using it as a submodule by using:

`set(CARTOGRAPHER_CONFIGURATION_FILES_DIRECTORY "${PROJECT_SOURCE_DIR}/cartographer/configuration_files" CACHE PATH ".lua config file directory")

add_subdirectory(cartographer)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/modules/")

find_package(cartographer REQUIRED)`

in cmake/module, file Findcartographer.cmake contains

`set(CARTOGRAPHER_CMAKE_DIR "${cartographer_SOURCE_DIR}/cmake") message(STATUS "Cartographer Source Directory = " ${cartographer_SOURCE_DIR})

include(FindPackageHandleStandardArgs) find_package_handle_standard_args(cartographer DEFAULT_MSG cartographer_SOURCE_DIR)`

This method runs without any issue. My system is Ubuntu 18.04. I have received a new requirement that the project run it without it being a sub-module. I have followed the directions from

https://google-cartographer.readthedocs.io/en/latest/

This is followed all the way up to the actual cartographer install step. First I attempt to install abseil-cpp.

git clone https://github.com/abseil/abseil-cpp.git cd abseil-cpp mkdir build cd build cmake -G Ninja \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ -DCMAKE_INSTALL_PREFIX=/usr/local/stow/absl \ .. ninja sudo ninja install cd /usr/local/stow sudo stow absl

I am using the latest master branch of abseil-cpp. Is their any problem with this? I know that cartographer's install script uses a specific commit id at checkout.

Now I install cartographer similar to how it is done in the read the docs link.

git clone https://github.com/cartographer-project/cartographer.git git checkout c5416068dd06ac4ca732ed53db225204b25ec05b cd cartographer mkdir build cd build cmake .. -G Ninja ninja CTEST_OUTPUT_ON_FAILURE=1 ninja test sudo ninja install

I specifically checkout a certain commit just to try and avoid running into library functions getting outdated in my current code. All the install steps above seem to work without issue. Then in my cmakeLists.txt file for my project I have,

`find_package(cartographer REQUIRED)

if(cartographer_FOUND) message(STATUS "Cartographer Found!!") endif(cartographer_FOUND)

set(CARTOGRAPHER_CONFIGURATION_FILES_DIRECTORY ${cartographer_DIR}/configuration_files CACHE PATH ".lua config file directory")

include(FindPackageHandleStandardArgs) find_package_handle_standard_args(cartographer DEFAULT_MSG cartographer_DIR)

message(STATUS "Cartographer CMAKE Directory = " ${CARTOGRAPHER_CMAKE_DIR}) message(STATUS "Cartographer Source Directory = " ${cartographer_DIR}) message(STATUS "Cartographer Config Directory = " ${CARTOGRAPHER_CONFIGURATION_FILES_DIRECTORY}) message(STATUS "Cartographer Module Directory = " ${CMAKE_MODULE_PATH})`

The output from cmake in this section gives

"-- Found installed version of Eigen: /usr/lib/cmake/eigen3 -- Found required Ceres dependency: Eigen version 3.3.4 in /usr/include/eigen3 -- Found required Ceres dependency: glog -- Found installed version of gflags: /usr/lib/x86_64-linux-gnu/cmake/gflags -- Detected gflags version: 2.2.1 -- Found required Ceres dependency: gflags -- Ceres version 1.14.0 detected here: /usr/local was built with C++11. Ceres target will add C++11 flags to compile options for targets using it. -- Found Ceres version: 1.14.0 installed in: /usr/local with components: [EigenSparse, SparseLinearAlgebraLibrary, LAPACK, SuiteSparse, CXSparse, SchurSpecializations, C++11, OpenMP, Multithreading] -- Cartographer Found!! -- Cartographer CMAKE Directory = /usr/local/share/cartographer/cmake -- Cartographer Source Directory = /usr/local/share/cartographer -- Cartographer Config Directory = /usr/local/share/cartographer/configuration_files -- Cartographer Module Directory = /usr/local/share/cartographer/cmake/modules"

Searches for linking abseil brought me to a file called FindAbseil.cmake. This file looks like it creates the library. I did try to add the file to the cartographer repo under cmake/modules and then rerun cmake, ninja, and ninja install commands. Being a module would it be more appropriate to use find_package(Abseil REQUIRED MODULE)?

JakeInit commented 3 years ago

The above works without any issue. I just found that as long as the abseil install step is done first, and then cartogrpaher is built, there are not any issues and the FindAbseil.cmake is not necessary.