Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X as a library #4

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build
install
# Temporary/backup files
*~
*.sw*
Expand All @@ -7,3 +9,6 @@

# Formatting
.clang-format

CMakeCache.txt
CMakeFiles/*
135 changes: 87 additions & 48 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,44 +1,47 @@
cmake_minimum_required(VERSION 3.16)
project(x VERSION 1.1.0)

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()

#################################################################################
# User build settings

set(DUAL_THREAD true) # Set true to process image and inertial data on different
OPTION(MULTI_THREAD "Multi thread" ON) # Set true to process image and inertial data on different
# threads
set(VERBOSE true) # Set false to disable all publishing and standard output

option(VERBOSE "Publish std out and other data" ON) # Set false to disable all publishing and standard output
# stream, except pose at update rate. That will improve runtime.
set(TIMING false) # Set true to enable timers
set(PROFILING false) # Set true to disable compiler flags which are not

option(TIMING "Publish timing information" OFF) # Set true to enable timers

option(PROFILING "Enable profiling flags" OFF) # Set true to disable compiler flags which are not
# compatible with Callgrind profiling tool.
set(UNIT_TESTS false) # Set true to enable unit tests

#################################################################################
option(UNIT_TESTS "Build unit tests" OFF) # Set true to enable unit tests

cmake_minimum_required(VERSION 2.8.3)
project(x)
set (CMAKE_BUILD_TYPE Release)
#################################################################################

# Set definitions
if(DUAL_THREAD)
add_definitions(-DDUAL_THREAD)
if(MULTI_THREAD)
message("Multi-thread: ON")
add_definitions(-DMULTI_THREAD)
endif()
if(VERBOSE)
message("Verbose: ON")
add_definitions(-DVERBOSE)
endif()
if(TIMING)
message("Timing: ON")
add_definitions(-DTIMING)
endif()
if(UNIT_TESTS)
message("Unit Tests: ON")
add_definitions(-DRUN_UNIT_TESTS)
endif()
if (CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-DDEBUG -DDEBUGMSF)
elseif (CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
# Enable asserts
add_definitions(-UNDEBUG)
endif()
add_definitions(-D_LINUX -D_REENTRANT)

# Eigen plugin
add_definitions(-DEIGEN_MATRIXBASE_PLUGIN=<x/common/eigen_matrix_base_plugin.h>)
add_definitions(-D_LINUX -D_REENTRANT)

# Look for OpenCV >= 3.3.1
find_package(OpenCV 4 QUIET)
Expand All @@ -49,21 +52,14 @@ if(NOT ${OpenCV_FOUND})
endif()
endif()

find_package(catkin REQUIRED COMPONENTS
cmake_modules
)

# Eigen plugin
add_definitions(-DEIGEN_MATRIXBASE_PLUGIN=<x/common/eigen_matrix_base_plugin.h>)
find_package(Eigen3 REQUIRED)

# Set build flags, depending on the architecture
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")

if (CMAKE_BUILD_TYPE MATCHES Debug)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
endif()

if (CMAKE_BUILD_TYPE MATCHES Release)

message("Release Mode")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")

if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") # tested on Jetson TX2
Expand All @@ -75,30 +71,25 @@ if (CMAKE_BUILD_TYPE MATCHES Release)
if (${PROFILING} MATCHES false)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -funsafe-loop-optimizations -fsee -funroll-loops -fno-math-errno -funsafe-math-optimizations -ffinite-math-only -fno-signed-zeros")
endif()


elseif (CMAKE_BUILD_TYPE MATCHES Debug)
message("Debug Mode")
add_definitions(-DDEBUG -DDEBUGMSF)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
elseif (CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
message("Release with Debug Info Mode")
# Enable asserts
add_definitions(-UNDEBUG)
endif()

# For downstream packages in catkin
set(EIGEN3_INCLUDE_DIRS ${EIGEN3_INCLUDE_DIR})
set(EIGEN3_LIBRARIES ${EIGEN3_LIBRARIES})

# Configure this package
catkin_package(
DEPENDS EIGEN3
INCLUDE_DIRS include ${EIGEN3_INCLUDE_DIR}
LIBRARIES x
)

## Package internal and additional locations of header files
## Separating the projects include directory from {catkin_INCLUDE_DIRS}
## allows to tag that with SYSTEM, which disables GCC warnings for
## these (all the ros header, opencv, ..)
include_directories (include)

include_directories (SYSTEM
${OpenCV_INCLUDE_DIRS}
${catkin_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR}
${EIGEN3_INCLUDE_DIRS}
)

set (SOURCE
Expand All @@ -122,13 +113,61 @@ set (SOURCE
src/x/vision/timing.cpp
src/x/vision/tracker.cpp
src/x/vision/triangulation.cpp

)

add_library (x ${SOURCE})
add_library(x ${SOURCE})

# Additional libraries to link against
target_link_libraries(x
${OpenCV_LIBRARIES}
${catkin_LIBRARIES}
${EIGEN3_LIBRARIES}
)

# Uninstall Target
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/xUninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/xUninstall.cmake" IMMEDIATE @ONLY)
add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/xUninstall.cmake")

set(CMAKE_INSTALL_LIBDIR lib)

# Generate pkg-config file
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc @ONLY)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

# Cmake find_package() support.
set(CMAKE_EXPORT_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
include(CMakePackageConfigHelpers)

install(TARGETS x EXPORT xTargets)
install(EXPORT xTargets
DESTINATION ${CMAKE_EXPORT_DESTINATION}
)
install(DIRECTORY include/ DESTINATION include)
configure_package_config_file(xConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/xConfig.cmake
INSTALL_DESTINATION ${CMAKE_EXPORT_DESTINATION}
)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/xConfigVersion.cmake
COMPATIBILITY SameMajorVersion
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/xConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/xConfigVersion.cmake
DESTINATION ${CMAKE_EXPORT_DESTINATION}
)

# Support automatic RPM/DEB generation via CPack
SET(CPACK_CMAKE_GENERATOR ${CMAKE_GENERATOR})
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_PACKAGE_RELEASE 1)
set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_PACKAGE_VENDOR "JPL-California Institute of Technology")
set(CPACK_PACKAGE_DESCRIPTION "Generic C++ library for vision-based navigation, with multi-sensor fusion capabilities for thermal, range, solar and GPS measurements.")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${CPACK_PACKAGE_DESCRIPTION})
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}.${CMAKE_SYSTEM_PROCESSOR}")
set(CPACK_GENERATOR "RPM" "DEB")
set(CPACK_RPM_PACKAGE_AUTOREQ 1)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS 1)

include(CPack)
14 changes: 0 additions & 14 deletions package.xml

This file was deleted.

4 changes: 2 additions & 2 deletions src/x/ekf/ekf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ State Ekf::processUpdateMeasurement() {
}

void Ekf::lock() {
#ifdef DUAL_THREAD
#ifdef MULTI_THREAD
mutex_.lock();
#endif
}

void Ekf::unlock() {
#ifdef DUAL_THREAD
#ifdef MULTI_THREAD
mutex_.unlock();
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion src/x/vio/vio_updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void VioUpdater::constructUpdate(const State& state,
/* Range-SLAM */

size_t rows_lrf = 0;
Matrix h_lrf, res_lrf;
Matrix h_lrf = Matrix::Zero(0, P.cols()), res_lrf = Matrix::Zero(0, 1);
Eigen::VectorXd r_lrf_diag;

if (measurement_.range.timestamp > 0.1 && slam_trks_.size()) {
Expand Down
2 changes: 1 addition & 1 deletion src/x/vision/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Feature Camera::normalize(const Feature& feature) const
feature.getX() * inv_fx_ - cx_n_,
feature.getY() * inv_fy_ - cy_n_);
normalized_feature.setXDist(feature.getXDist() * inv_fx_ - cx_n_);
normalized_feature.setYDist(feature.getYDist() * inv_fx_ - cx_n_);
normalized_feature.setYDist(feature.getYDist() * inv_fy_ - cy_n_);

return normalized_feature;
}
Expand Down
11 changes: 11 additions & 0 deletions x.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@

Name: @PROJECT_NAME@
Description: Generic C++ library for vision-based navigation, with multi-sensor fusion capabilities for thermal, range, solar and GPS measurements.
Version: @PROJECT_VERSION@
Requires: opencv2 >= 3.3.1, libzstd
Libs: @SYSTEM_THREAD_LIBS@
Cflags: -I${includedir}
60 changes: 60 additions & 0 deletions xConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# ===================================================================================
# @PROJECT_NAME@ CMake configuration file
#
# ** File generated automatically, do not modify **
#
# Usage from an external project:
# In your CMakeLists.txt, add these lines:
#
# FIND_PACKAGE(@PROJECT_NAME@ REQUIRED )
# TARGET_LINK_LIBRARIES(MY_TARGET_NAME ${@PROJECT_NAME@_LIBS})
#
# This file will define the following variables:
# - @PROJECT_NAME@_LIBS : The list of libraries to links against.
# - @PROJECT_NAME@_LIB_DIR : The directory where lib files are. Calling LINK_DIRECTORIES
# with this path is NOT needed.
# - @PROJECT_NAME@_VERSION : The version of this PROJECT_NAME build. Example: "1.2.0"
# - @PROJECT_NAME@_VERSION_MAJOR : Major version part of VERSION. Example: "1"
# - @PROJECT_NAME@_VERSION_MINOR : Minor version part of VERSION. Example: "2"
# - @PROJECT_NAME@_VERSION_PATCH : Patch version part of VERSION. Example: "0"
#
# ===================================================================================

# Look for OpenCV >= 3.3.1
find_package(OpenCV 4 QUIET)
if(NOT ${OpenCV_FOUND})
find_package(OpenCV 3.3.1 QUIET)
if(NOT ${OpenCV_FOUND})
message(FATAL_ERROR "OpenCV >= 3.3.1 required.")
endif()
endif()

# Eigen plugin
add_definitions(-DEIGEN_MATRIXBASE_PLUGIN=<x/common/eigen_matrix_base_plugin.h>)

find_package(Eigen3 REQUIRED)
if(NOT ${Eigen3_FOUND})
message(FATAL_ERROR "Eigen3 required.")
endif()

@PACKAGE_INIT@

include_directories("@CMAKE_INSTALL_PREFIX@/include"
${OpenCV_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIRS})
set(@PROJECT_NAME@_INCLUDE_DIRS "@CMAKE_INSTALL_PREFIX@/include"
${OpenCV_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIRS})
check_required_components(x)

LINK_DIRECTORIES("@CMAKE_INSTALL_PREFIX@/lib")
set(@PROJECT_NAME@_LIB_DIR "@CMAKE_INSTALL_PREFIX@/lib")

set(@PROJECT_NAME@_LIBRARIES @REQUIRED_LIBRARIES@ @PROJECT_NAME@@PROJECT_DLLVERSION@)

set(@PROJECT_NAME@_FOUND YES)
set(@PROJECT_NAME@_FOUND "YES")
set(@PROJECT_NAME@_VERSION @PROJECT_VERSION@)
set(@PROJECT_NAME@_VERSION_MAJOR @PROJECT_VERSION_MAJOR@)
set(@PROJECT_NAME@_VERSION_MINOR @PROJECT_VERSION_MINOR@)
set(@PROJECT_NAME@_VERSION_PATCH @PROJECT_VERSION_PATCH@)
28 changes: 28 additions & 0 deletions xUninstall.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -----------------------------------------------
# File that provides "make uninstall" target
# We use the file 'install_manifest.txt'
# -----------------------------------------------
IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
MESSAGE(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"")
ENDIF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")

FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
STRING(REGEX REPLACE "\n" ";" files "${files}")
FOREACH(file ${files})
MESSAGE(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
IF(EXISTS "$ENV{DESTDIR}${file}")
EXEC_PROGRAM(
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
OUTPUT_VARIABLE rm_out
RETURN_VALUE rm_retval
)
EXECUTE_PROCESS(COMMAND rm -rf $ENV{DESTDIR}${file})
IF(NOT "${rm_retval}" STREQUAL 0)
MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"")
ENDIF(NOT "${rm_retval}" STREQUAL 0)
ELSE(EXISTS "$ENV{DESTDIR}${file}")
MESSAGE(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.")
ENDIF(EXISTS "$ENV{DESTDIR}${file}")
ENDFOREACH(file)