Skip to content

Commit

Permalink
setting base code
Browse files Browse the repository at this point in the history
  • Loading branch information
yun-long committed Aug 10, 2020
1 parent a240f9c commit 0d42f87
Show file tree
Hide file tree
Showing 78 changed files with 15,856 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
BasedOnStyle: Google
ColumnLimit: 80
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
IndentWidth: 2
Language: Cpp
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
SortUsingDeclarations: true
SpaceAfterTemplateKeyword: false
SpaceInEmptyParentheses: false
Standard: Cpp11
TabWidth: 2
UseTab: Never
---
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
.sass-cache
.vscode/*
!.vscode/extensions.json
externals/*
dist
*.egg-info
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM ubuntu:18.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
python3 python3-dev python3-pip \
cmake \
git \
ca-certificates \
libzmqpp-dev \
libopencv-dev \
&& rm -rf /var/lib/apt/lists/*

RUN echo "export FLIGHTMARE_DIR=/__w/flightmare/flightmare" >> ~/.bashrc
RUN /bin/bash -c "source ~/.bashrc"
RUN echo $FLIGHTMARE_DIR

Binary file removed docs/images/flightmare_envs.png
Binary file not shown.
5 changes: 5 additions & 0 deletions flightlib/.vscode/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
extensions.json
251 changes: 251 additions & 0 deletions flightlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
cmake_minimum_required(VERSION 3.0)

project(flightlib VERSION 0.1.0)

message(STATUS "====================== !Flightmare! ======================")

################################################################################
# Options
################################################################################
option(BUILD_TESTS "Building the tests" ON)
option(BUILD_BENCH "Building the benchmark." OFF)
option(ENABLE_FAST "Build with optimizations for speed" ON)
option(ENABLE_BLAS "Build using BLAS and LAPACK libraries" OFF)
option(ENABLE_PARALLEL "Build using openmp parallelization" ON)
option(EIGEN_FROM_SYSTTEM "Use the system-provided Eigen" ON)
set(
EIGEN_ALTERNATIVE "" CACHE STRING
"Path to alternative Eigen, autodownload if blank"
)

################################################################################
# Finding Dependencies
################################################################################

message(STATUS "======> Setup Dependencies")
if(EIGEN_FROM_SYSTTEM)
find_package(Eigen3 3.3.4 QUIET)
if(EIGEN3_FOUND)
message(STATUS "Using system provided Eigen.")
else()
message(STATUS "No sufficient Eigen version (3.3.4) found.")
message(STATUS "Restoring to download Eigen sources.")
include(cmake/eigen.cmake)
endif()
elseif(EIGEN_ALTERNATIVE STREQUAL "")
include(cmake/eigen.cmake)
else()
set(EIGEN_INCLUDE_DIR ${EIGEN_ALTERNATIVE})
endif()

# Including dependencies
include(cmake/pybind11.cmake)
include(cmake/yaml.cmake)

# Including dependencies
find_package(OpenCV REQUIRED)
find_package(OpenMP REQUIRED)

if(ENABLE_BLAS)
set(BLA_VENDOR "Generic")
find_package(BLAS REQUIRED)
if(BLAS_FOUND)
message(STATUS "Found BLAS: ${BLAS_LIBRARIES}")
else()
message(ERROR "Could not enable BLAS because BLAS was not found")
endif()
find_package(LAPACK REQUIRED)
if(LAPACK_FOUND)
message(STATUS "Found Lapack: ${LAPACK_LIBRARIES}")
else()
message(ERROR "Could not enable LAPACK because LAPACK was not found")
endif()
endif()

# Check for ccache
if(NOT DEFINED CATKIN_DEVEL_PREFIX)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
else()
message(INFO "Build time could be improved with ccache!")
message(INFO " sudo apt install ccache")
endif()
endif()

################################################################################
# Setup Compilation
################################################################################
message(STATUS "======> Setup Compilation")

add_definitions(-std=c++17)
add_definitions(-DEIGEN_STACK_ALLOCATION_LIMIT=1048576)
include_directories(${EIGEN_INCLUDE_DIR} "tests")

# Set default build type
if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()
endif()

# Add c++ flags
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -fPIC -Wall -DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -fPIC -Wall -g ")

# Architectural flags
if("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
message(STATUS "Using ARMv7 optimized flags!")
set(CMAKE_CXX_ARCH_FLAGS " -Wno-psabi -march=armv7-a -mfpu=neon -mfloat-abi=hard -funsafe-math-optimizations")
elseif("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
message(STATUS "Using ARM aarch64 optimized flags!")
set(CMAKE_CXX_ARCH_FLAGS " -Wno-psabi -march=armv8-a+crypto -mcpu=cortex-a57+crypto")
else()
set(CMAKE_CXX_ARCH_FLAGS " -march=native")
endif()

# Optimized flags
if(ENABLE_FAST)
message(STATUS "Enabling fast optimization flags!")
set(CMAKE_CXX_FAST_FLAGS " -Ofast")
else()
set(CMAKE_CXX_FAST_FLAGS " -O0")
endif()

# Parallelization Flags
if(ENABLE_PARALLEL)
message(STATUS "Enabling parallelization!")
set(CMAKE_CXX_PAR_FLAGS " -fopenmp")
else()
set(CMAKE_CXX_PAR_FLAGS " -DEIGEN_DONT_PARALLELIZE")
endif()

# BLAS Flags
if(BLAS_FOUND AND LAPACK_FOUND)
message(STATUS "Enabling BLAS and LAPACK")
set(CMAKE_CXX_BLAS_FLAGS " -DEIGEN_USE_BLAS -DEIGEN_USE_LAPACK -DEIGEN_USE_LAPACKE")
else()
set(CMAKE_CXX_BLAS_FLAGS "")
endif()

# Summarize Flags
set(CMAKE_CXX_FLAGS_RELEASE
"${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FAST_FLAGS} ${CMAKE_CXX_ARCH_FLAGS} ${CMAKE_CXX_PAR_FLAGS} ${CMAKE_CXX_BLAS_FLAGS}")
string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
message(STATUS "The activated CXX RELEASE configuration is:\n ${CMAKE_CXX_FLAGS_RELEASE}")
message(STATUS "The activated CXX DEBUG configuration is:\n ${CMAKE_CXX_FLAGS_DEBUG}")

################################################################################
# Specify Build Resources
################################################################################
message(STATUS "======> Setup Build ")

# Create file lists for flightlib
file(GLOB_RECURSE FLIGHTLIB_SOURCES
src/bridges/*.cpp
src/dynamics/*.cpp
src/objects/*.cpp
src/sensors/*.cpp
src/envs/*.cpp
src/common/*.cpp
)

# Create file lists for flightlib tests
file(GLOB_RECURSE FLIGHTLIB_TEST_SOURCES
tests/bridges/*.cpp
tests/dynamics/*.cpp
tests/objects/*.cpp
tests/sensors/*.cpp
tests/envs/*.cpp
tests/common/*.cpp
)

# Create file lists for flightlib_gym tests
file(GLOB_RECURSE FLIGHTLIB_GYM_SOURCES
src/wrapper/*.cpp
)

file(GLOB_RECURSE FLIGHTLIB_GYM_TEST_SOURCES
tests/wrapper/*.cpp
)

################################################################################
# Optional Catkin Build
################################################################################

if(DEFINED CATKIN_DEVEL_PREFIX)
message(STATUS "======> Building with -- catkin -- ")
include(cmake/catkin.cmake)
return()
endif()

################################################################################
# Setup Build
################################################################################

# Setup Testing and Benchmark
if(BUILD_TESTS OR BUILD_BENCH)
include(cmake/gtest.cmake)
enable_testing()
endif()

# Library and Executables
include_directories(include)

if(NOT FLIGHTLIB_SOURCES)
set(LIBRARY_NAME)
else()
# flightlib
add_library(${PROJECT_NAME} ${FLIGHTLIB_SOURCES})
target_link_libraries(${PROJECT_NAME}
${OpenCV_LIBRARIES}
yaml-cpp
zmq
zmqpp)
set(LIBRARY_NAME ${PROJECT_NAME})
set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
endif()

if(FLIGHTLIB_GYM_SOURCES)
# flightlib_gym (python3 binding with Pybind11)
pybind11_add_module(flightgym MODULE
${FLIGHTLIB_GYM_SOURCES})
target_include_directories(flightgym PUBLIC
${PROJECT_SOURCE_DIR}/externals/pybind11-src/include
${PROJECT_SOURCE_DIR}/include)
target_link_libraries(flightgym PRIVATE ${LIBRARY_NAME})
endif()

if(ENABLE_BLAS AND BLAS_FOUND AND LAPACK_FOUND)
message(STATUS "Linking standard BLAS ${BLAS_LIBRARIES}")
target_link_libraries(${LIBRARY_NAME}
${BLAS_LIBRARIES}
${LAPACK_LIBRARIES}
${LAPACKE_LIBRARIES}
)
endif()

# Build tests
if(BUILD_TESTS AND FLIGHTLIB_GYM_TEST_SOURCES)
add_executable(test_gym ${FLIGHTLIB_GYM_TEST_SOURCES})
target_link_libraries(test_gym
${LIBRARY_NAME}
gtest
gtest_main
)
add_test(test_gym test_gym)
endif()

# Build tests
if(BUILD_TESTS AND FLIGHTLIB_TEST_SOURCES)
add_executable(test_lib ${FLIGHTLIB_TEST_SOURCES})
target_link_libraries(test_lib PUBLIC
${LIBRARY_NAME}
gtest
gtest_main
)
add_test(test_lib test_lib)
endif()


message(STATUS "================ !Done. No more nightmare! ================")
4 changes: 4 additions & 0 deletions flightlib/build/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
DisableFormat: true
SortIncludes: false
---
5 changes: 5 additions & 0 deletions flightlib/build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
!.clang-format
33 changes: 33 additions & 0 deletions flightlib/cmake/agilib.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Download and unpack agilicious at configure time
message(STATUS "Getting RPG agilicious...")

configure_file(
cmake/agilib_download.cmake
${PROJECT_SOURCE_DIR}/externals/agilib-download/CMakeLists.txt)

execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/externals/agilib-download/
OUTPUT_QUIET
ERROR_QUIET)
if(result)
message(FATAL_ERROR "CMake step for agilib-cpp failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/externals/agilib-download
OUTPUT_QUIET
ERROR_QUIET)
if(result)
message(FATAL_ERROR "Build step for agilib failed: ${result}")
endif()

message(STATUS "Agilicious downloaded!")

add_subdirectory(${PROJECT_SOURCE_DIR}/externals/agilib-src/agilib
${PROJECT_SOURCE_DIR}/externals/agilib-build
EXCLUDE_FROM_ALL)
target_compile_options(agilib PRIVATE -w)

include_directories(SYSTEM "${PROJECT_SOURCE_DIR}/externals/agilib-src/agilib/include")
link_directories("${PROJECT_SOURCE_DIR}/externals/agilib-build")
17 changes: 17 additions & 0 deletions flightlib/cmake/agilib_download.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.0)

project(agilib-download NONE)

include(ExternalProject)

ExternalProject_Add(agilib
GIT_REPOSITORY [email protected]:uzh-rpg/agilicious.git
GIT_TAG master
SOURCE_DIR "${PROJECT_SOURCE_DIR}/externals/agilib-src"
BINARY_DIR "${PROJECT_SOURCE_DIR}/externals/agilib-bin"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
UPDATE_DISCONNECTED ON
)
25 changes: 25 additions & 0 deletions flightlib/cmake/eigen.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Download and unpack eigen at configure time
message(STATUS "Getting Eigen...")

configure_file(
cmake/eigen_download.cmake
${PROJECT_SOURCE_DIR}/externals/eigen/CMakeLists.txt)

execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/externals/eigen
OUTPUT_QUIET)
if(result)
message(FATAL_ERROR "Download of Eigen failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/externals/eigen
OUTPUT_QUIET)
if(result)
message(FATAL_ERROR "Build step for eigen failed: ${result}")
endif()

message(STATUS "Eigen downloaded!")

set(EIGEN_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/externals/eigen)
Loading

0 comments on commit 0d42f87

Please sign in to comment.