Skip to content

Commit

Permalink
Merge branch 'C++11' into ros2-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
cheneyuwu authored Oct 27, 2021
2 parents 0015f6c + e47e7d2 commit 2e34d62
Show file tree
Hide file tree
Showing 73 changed files with 337 additions and 284 deletions.
64 changes: 33 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,17 @@ if (NOT USE_AMENT)
set(PROJECT_VERSION 1.1.0)

# Find dependencies
find_package(Boost REQUIRED system)
find_package(OpenMP REQUIRED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
find_package(Eigen3 REQUIRED)
find_package(lgmath REQUIRED)
find_package(Eigen3 3.3.7 REQUIRED)
find_package(lgmath 1.1.0 REQUIRED)

# Build library
file(GLOB_RECURSE SOURCE_FILES "src/*.cpp")
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME}
PUBLIC
${Boost_LIBRARIES}
${OpenMP_LIBRARIES}
lgmath
PUBLIC lgmath
)
target_include_directories(${PROJECT_NAME}
PUBLIC
Expand All @@ -49,48 +45,53 @@ install(
DESTINATION include
)

install(TARGETS ${PROJECT_NAME}
install(
TARGETS ${PROJECT_NAME}
DESTINATION lib
EXPORT export_${PROJECT_NAME}
)

install(EXPORT export_${PROJECT_NAME}
FILE export_${PROJECT_NAME}.cmake
DESTINATION lib/cmake/${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
)

# Export
set(PROJECT_LIBRARY ${PROJECT_NAME})

include(CMakePackageConfigHelpers)
# generate the config file that is includes the exports
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "lib/cmake/example"
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
# generate the version file for the config file
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION "${Tutorial_VERSION_MAJOR}.${Tutorial_VERSION_MINOR}"
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
# install the configuration file
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
# export to build directory so no need to install in order to use find_package
export(
EXPORT ${PROJECT_NAME}Targets
FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake
)

# install export cmake files
install(
EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION lib/cmake/${PROJECT_NAME}
)
# export to build directory as well so no need to install in order to use find_package
export(EXPORT export_${PROJECT_NAME}
FILE "${CMAKE_CURRENT_BINARY_DIR}/export_${PROJECT_NAME}.cmake"

install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION lib/cmake/${PROJECT_NAME}
)

## ROS2 ament_cmake flow
else()

# Find dependencies
find_package(ament_cmake REQUIRED)
find_package(Boost REQUIRED system)
find_package(OpenMP REQUIRED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
Expand All @@ -101,15 +102,15 @@ find_package(lgmath REQUIRED)
# Libraries
file(GLOB_RECURSE SOURCE src/*.cpp)
add_library(${PROJECT_NAME} ${SOURCE})
ament_target_dependencies(${PROJECT_NAME} Boost Eigen3 OpenMP lgmath)
ament_target_dependencies(${PROJECT_NAME} Eigen3 OpenMP lgmath)
target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
ament_export_dependencies(eigen3_cmake_module)
ament_export_dependencies(Boost OpenMP Eigen3 lgmath)
ament_export_dependencies(OpenMP Eigen3 lgmath)

install(
DIRECTORY include/
Expand Down Expand Up @@ -142,6 +143,7 @@ add_executable(TrustRegionExample samples/TrustRegionExample.cpp)
add_executable(MotionDistortedP2PandCATrajPrior samples/MotionDistortedP2PandCATrajPrior.cpp)
add_executable(SimpleP2PandCATrajPrior samples/SimpleP2PandCATrajPrior.cpp)
add_executable(SimplePointCloudAlignment samples/SimplePointCloudAlignment.cpp)

if (USE_AMENT)

install(
Expand Down
9 changes: 8 additions & 1 deletion Config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
@PACKAGE_INIT@

include ( "${CMAKE_CURRENT_LIST_DIR}/export_steam.cmake" )
include(CMakeFindDependencyMacro)
find_dependency(Eigen3 3.3.7)
find_dependency(lgmath 1.1.0)

set (@PROJECT_NAME@_LIBRARY "@PROJECT_LIBRARY@")
set (@PROJECT_NAME@_LIBRARIES "@PROJECT_LIBRARY@")

include ( "${CMAKE_CURRENT_LIST_DIR}/@[email protected]" )
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@ CMD ["/bin/bash"]
ARG DEBIAN_FRONTEND=noninteractive

RUN apt update

RUN apt install -q -y curl gnupg2 lsb-release build-essential cmake
RUN apt install -q -y libboost-all-dev libomp-dev
RUN apt install -q -y libeigen3-dev
RUN apt install -q -y libeigen3-dev libboost-all-dev libomp-dev
8 changes: 4 additions & 4 deletions Dockerfile.ROS2
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM ros:foxy
FROM ros:galactic

CMD ["/bin/bash"]

ARG DEBIAN_FRONTEND=noninteractive

RUN apt update
RUN apt install -q -y curl gnupg2 lsb-release build-essential
RUN apt install -q -y libboost-all-dev libomp-dev
RUN apt install -q -y python3-colcon-core python3-colcon-common-extensions
RUN apt install -q -y curl gnupg2 lsb-release build-essential cmake
RUN apt install -q -y python3-colcon-core python3-colcon-common-extensions
RUN apt install -q -y libeigen3-dev libboost-all-dev libomp-dev
6 changes: 3 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pipeline {
stage('build deps (lgmath)') {
steps {
dir('lgmath') {
git branch: 'feature/eigen3', credentialsId: 'ea1fced4-b1ad-4389-b294-74b0d3a7f607', url: 'https://github.com/utiasASRL/lgmath.git'
git branch: 'master', url: 'https://github.com/utiasASRL/lgmath.git'
sh '''
mkdir build && cd build
cmake ..
Expand Down Expand Up @@ -59,9 +59,9 @@ pipeline {
stage('build deps (lgmath)') {
steps {
dir('lgmath') {
git branch: 'feature/eigen3', credentialsId: 'ea1fced4-b1ad-4389-b294-74b0d3a7f607', url: 'https://github.com/utiasASRL/lgmath.git'
git branch: 'master', url: 'https://github.com/utiasASRL/lgmath.git'
sh '''
source /opt/ros/foxy/setup.bash
source /opt/ros/galactic/setup.bash
colcon build --symlink-install --cmake-args "-DUSE_AMENT=ON"
touch COLGON_IGNORE
'''
Expand Down
87 changes: 59 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,69 +8,100 @@ STEAM (Simultaneous Trajectory Estimation and Mapping) Engine is an optimization

## Installation

### Hardware and Software Requirements
### Dependencies

- Compiler with C++17 support
- Compiler with C++17 support and OpenMP
- CMake (>=3.16)
- Boost (>=1.71.0)
- Eigen (>=3.3.7)
- CMake or ROS2(colcon+ament_cmake)
- Boost library
- OpenMP
- [lgmath](https://github.com/utiasASRL/lgmath.git)
- [lgmath (>=1.1.0)](https://github.com/utiasASRL/lgmath.git)
- (Optional) ROS2 Foxy or later (colcon+ament_cmake)

### Install c++ compiler, cmake, Boost and OpenMP
### Install c++ compiler, cmake and OpenMP

```bash
sudo apt -q -y install build-essential cmake libboost-all-dev libomp-dev
sudo apt -q -y install build-essential cmake libomp-dev
```

### Install Eigen (>=3.3.7)
### Install Boost

```bash
# using APT
sudo apt -q -y install libboost-all-dev

# OR from source
WORKSPACE=~/workspace # choose your own workspace directory
mkdir -p ${WORKSPACE}/boost && cd $_
wget --no-verbose https://boostorg.jfrog.io/artifactory/main/release/1.71.0/source/boost_1_71_0.tar.gz
tar xzf boost_1_71_0.tar.gz && cd boost_1_71_0
./bootstrap.sh --with-python=$(which python3)
./b2 cxxflags="-std=gnu++17" install
ldconfig
```

Eigen can be installed using APT
### Install Eigen (>=3.3.7)

```bash
# using APT
sudo apt -q -y install libeigen3-dev

# OR from source
WORKSPACE=~/workspace # choose your own workspace directory
mkdir -p ${WORKSPACE}/eigen && cd $_
git clone https://gitlab.com/libeigen/eigen.git . && git checkout 3.3.7
mkdir build && cd $_
cmake .. && make install # default install location is /usr/local/
```

If installed from source to a custom location then make sure `cmake` can find it.
- Note: if installed from source to a custom location then make sure `cmake` can find it.

### Build and install using `cmake`
### Install lgmath

Install [lgmath](https://github.com/utiasASRL/lgmath.git) using `cmake` before installing this library. If installed to a custom location then make sure `cmake` can find it.
Follow the instructions [here](https://github.com/utiasASRL/lgmath.git).

Clone this repo
### Build and install steam using `cmake`

```bash
WORKSPACE=~/workspace # choose your own workspace directory
# clone
mkdir -p ${WORKSPACE}/steam && cd $_
git clone https://github.com/utiasASRL/steam.git .
# build and install
mkdir -p build && cd $_
cmake ..
cmake --build .
cmake --install . # (optional) install, default location is /usr/local/
```

Preprocessor macros

- `STEAM_DEFAULT_NUM_OPENMP_THREADS=<num. threads>`: Default to 4. Define number of threads to be used by OpenMP in STEAM.
- `STEAM_USE_OBJECT_POOL`: Default to undefined. If defined then STEAM will use an object pool to improve performance but is no longer thread safe.

Build and install

```bash
mkdir -p build && cd $_
cmake ..
cmake --build .
cmake --install . # (optional) install, default location is /usr/local/
```

Note: `steamConfig.cmake` will be generated in both `build/` and `<install prefix>/lib/cmake/steam/` to be included in other projects.

### Build and install using `ROS2(colcon+ament_cmake)`
### Build examples

[samples/CMakeLists.txt](./samples/CMakeLists.txt) shows an example of how to add steam to your projects.

Clone both lgmath and this repository in the same directory
To build and run these samples:

```bash
git clone https://github.com/utiasASRL/lgmath.git
git clone https://github.com/utiasASRL/steam.git
cd ${WORKSPACE}/steam ## $WORKSPACE defined above
mkdir -p build_samples && cd $_
cmake ../samples
cmake --build . # Executables will be generated in build_samples
```

Source your ROS2 workspace and then
### Build and install steam using `ROS2(colcon+ament_cmake)`

```bash
WORKSPACE=~/workspace # choose your own workspace directory

mkdir -p ${WORKSPACE}/steam && cd $_
git clone https://github.com/utiasASRL/steam.git .

source <your ROS2 worspace that includes steam>
colcon build --symlink-install --cmake-args "-DUSE_AMENT=ON"
```

Expand Down
13 changes: 6 additions & 7 deletions include/steam/common/Time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#define STEAM_TIME_HPP

#include <iostream>
#include <boost/cstdint.hpp>

namespace steam {

Expand All @@ -20,11 +19,11 @@ namespace steam {
class Time {
public:
Time() : nsecs_(0) {}
Time(boost::int64_t nsecs) : nsecs_(nsecs) {}
Time(int64_t nsecs) : nsecs_(nsecs) {}
Time(double secs) : nsecs_(secs*1e9) {}
Time(boost::int32_t secs, boost::int32_t nsec) {
boost::int64_t t1 = (boost::int64_t) secs;
boost::int64_t t2 = (boost::int64_t) nsec;
Time(int32_t secs, int32_t nsec) {
int64_t t1 = (int64_t) secs;
int64_t t2 = (int64_t) nsec;
this->nsecs_ = t1*1000000000 + t2;
}

Expand All @@ -44,7 +43,7 @@ class Time {
/// Usually it makes sense to use this method after *this* has been reduced to a
/// duration between two times.
//////////////////////////////////////////////////////////////////////////////////////////////
const boost::int64_t& nanosecs() const {
const int64_t& nanosecs() const {
return nsecs_;
}

Expand Down Expand Up @@ -108,7 +107,7 @@ class Time {
/// seconds since epoch and 1e9 nsecs. Furthermore, a single base type, rather than
/// two combined unsigned int32s to allow nsecs to be used as a key in a std::map.
//////////////////////////////////////////////////////////////////////////////////////////////
boost::int64_t nsecs_;
int64_t nsecs_;

};

Expand Down
1 change: 0 additions & 1 deletion include/steam/common/Timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// system timer
#include <sys/time.h>
#include <iostream>
#include <boost/cstdint.hpp>

namespace steam {

Expand Down
4 changes: 2 additions & 2 deletions include/steam/evaluator/ErrorEvaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ template<int MEAS_DIM, // Dimension of the measurement error. Note the mea
int MAX_STATE_SIZE> // The maximum dimension of a single state variable perturbation
struct ErrorEvaluator{
typedef EvaluatorBase<Eigen::Matrix<double, MEAS_DIM, 1>,MEAS_DIM,MEAS_DIM,MAX_STATE_SIZE> type;
typedef boost::shared_ptr<type> Ptr;
typedef boost::shared_ptr<const type> ConstPtr;
typedef std::shared_ptr<type> Ptr;
typedef std::shared_ptr<const type> ConstPtr;
};

//////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions include/steam/evaluator/EvaluatorBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class EvaluatorBase
public:

/// Convenience typedefs
typedef boost::shared_ptr<EvaluatorBase<TYPE,LHS_DIM,INNER_DIM,MAX_STATE_DIM> > Ptr;
typedef boost::shared_ptr<const EvaluatorBase<TYPE,LHS_DIM,INNER_DIM,MAX_STATE_DIM> > ConstPtr;
typedef std::shared_ptr<EvaluatorBase<TYPE,LHS_DIM,INNER_DIM,MAX_STATE_DIM> > Ptr;
typedef std::shared_ptr<const EvaluatorBase<TYPE,LHS_DIM,INNER_DIM,MAX_STATE_DIM> > ConstPtr;

//////////////////////////////////////////////////////////////////////////////////////////////
/// \brief Default constructor
Expand Down
Loading

0 comments on commit 2e34d62

Please sign in to comment.