Skip to content

Commit

Permalink
Merge pull request uzh-rpg#42 from uzh-rpg/dev/samples
Browse files Browse the repository at this point in the history
Dev/samples
  • Loading branch information
yun-long authored Nov 18, 2020
2 parents 4b8f535 + 7b85588 commit 87f4712
Show file tree
Hide file tree
Showing 28 changed files with 23,781 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
_posts
_site
.vscode/*
**/.vscode/*
!.vscode/extensions.json
externals/*
dist
*.egg-info
*.so
__pycache__
build
_build
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ Installation instructions can be found in our [Wiki](https://github.com/uzh-rpg/
If you use this code in a publication, please cite the following paper **[PDF](https://arxiv.org/abs/2009.00563)**

```
@article{yunlong2020flightmare,
title={Flightmare: A Flexible Quadrotor Simulator},
author={Song, Yunlong and Naji, Selim and Kaufmann, Elia and Loquercio, Antonio and Scaramuzza, Davide},
journal={arXiv preprint arXiv:2009.00563},
year={2020}
@article{song2020flightmare,
title={Flightmare: A Flexible Quadrotor Simulator},
author={Song, Yunlong and Naji, Selim and Kaufmann, Elia and Loquercio, Antonio and Scaramuzza, Davide},
booktitle={Conference on Robot Learning},
year={2020}
}
```

Expand Down
2 changes: 1 addition & 1 deletion flightlib/cmake/eigen_download.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(eigen-external)
include(ExternalProject)
ExternalProject_Add(eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG master
GIT_TAG 3.3.4
SOURCE_DIR "${PROJECT_SOURCE_DIR}/externals/eigen/eigen3"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
Expand Down
1 change: 0 additions & 1 deletion flightlib/include/flightlib/bridges/unity_bridge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

// std libs
#include <unistd.h>
#include <chrono>
#include <experimental/filesystem>
#include <fstream>
#include <map>
Expand Down
14 changes: 10 additions & 4 deletions flightlib/include/flightlib/bridges/unity_message_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ using json = nlohmann::json;
namespace flightlib {

enum UnityScene {
WAREHOUSE = 0,
GARAGE = 1,
TUNELS = 2,
INDUSTRIAL = 0,
WAREHOUSE = 1,
GARAGE = 2,
TUNELS = 4,
NATUREFOREST = 3,
// total number of environment
SceneNum = 4
SceneNum = 5
};

// Unity Camera, should not be used alone.
Expand All @@ -38,6 +39,9 @@ struct Camera_t {
int width{1024};
int height{768};
Scalar fov{70.0f};
// Clip Planes for the different layers
std::vector<Scalar> near_clip_plane{0.01, 0.01, 0.01, 0.01};
std::vector<Scalar> far_clip_plane{1000.0, 100.0, 1000.0, 1000.0};
Scalar depth_scale{0.20}; // 0.xx corresponds to xx cm resolution
// metadata
bool is_depth{false};
Expand Down Expand Up @@ -135,6 +139,8 @@ inline void to_json(json &j, const Camera_t &o) {
{"width", o.width},
{"height", o.height},
{"fov", o.fov},
{"nearClipPlane", o.near_clip_plane},
{"farClipPlane", o.far_clip_plane},
{"T_BC", o.T_BC},
{"isDepth", o.is_depth},
{"enabledLayers", o.enabled_layers},
Expand Down
3 changes: 2 additions & 1 deletion flightlib/include/flightlib/json/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5733,7 +5733,8 @@ class basic_json {
if (lhs_type == rhs_type) {
switch (lhs_type) {
case value_t::array: {
return *lhs.m_value.array < *rhs.m_value.array;
// fix: https://github.com/nlohmann/json/issues/590
return (*lhs.m_value.array) < *rhs.m_value.array;
}
case value_t::object: {
return *lhs.m_value.object < *rhs.m_value.object;
Expand Down
104 changes: 101 additions & 3 deletions flightros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ find_package(catkin_simple REQUIRED)

find_package(OpenCV REQUIRED)

option(BUILD_MP "Build Motion Planning" OFF)

catkin_simple()

# Setup Default Build Type as Release
Expand All @@ -27,13 +29,17 @@ endif ()
# Setup General C++ Flags
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DEIGEN_STACK_ALLOCATION_LIMIT=1048576")
# otherwise double free or corruption (out) error when running racing or motion_planning example
add_compile_options(-O3)

# Setup Release and Debug flags
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_ARCH_FLAGS} -Wall -DNDEBUG -fPIC")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -Wall -g")

#pilot

cs_add_library(flight_pilot
src/flight_pilot.cpp
src/pilot/flight_pilot.cpp
)

target_link_libraries(flight_pilot
Expand All @@ -43,7 +49,7 @@ target_link_libraries(flight_pilot
)

cs_add_executable(flight_pilot_node
src/flight_pilot_node.cpp
src/pilot/flight_pilot_node.cpp
)

target_link_libraries(flight_pilot_node
Expand All @@ -52,6 +58,98 @@ target_link_libraries(flight_pilot_node
stdc++fs
)

# motion_planning

if(BUILD_MP)

find_package(OpenMP)
if (OpenMP_CXX_FOUND)
message("Found OpenMP ${OpenMP_CXX_FOUND} ${OpenMP_VERSION} ${OpenMP_CXX_VERSION_MAJOR} ${Open3D_VERSION} OpenMP::OpenMP_CXX")
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
else ()
message("OpenMP not found")
endif ()

# Open3D
find_package(Open3D)
if (Open3D_FOUND)
message("Found Open3D ${Open3D_VERSION}")
list(APPEND Open3D_LIBRARIES dl)
# link_directories must be before add_executable
link_directories(${Open3D_LIBRARY_DIRS})
else ()
message("Open3D not found")
endif ()

find_package(ompl REQUIRED)
if (OMPL_FOUND)
message("Found OMPL ${OMPL_VERSION}")
include_directories(${OMPL_INCLUDE_DIRS})

else ()
message("OMPL not found")
endif ()

if (OpenMP_CXX_FOUND AND Open3D_FOUND AND OMPL_FOUND)
cs_add_executable(motion_planning
src/motion_planning/motion_planning.cpp
)
target_include_directories(motion_planning PUBLIC ${Open3D_INCLUDE_DIRS})

target_link_libraries(motion_planning
${catkin_LIBRARIES}
${OpenCV_LIBRARIES}
stdc++fs
ompl
${Open3D_LIBRARIES}
OpenMP::OpenMP_CXX
zmq
zmqpp
)
else ()
message("Failed to build motion planning")
endif ()

endif()

# racing


catkin_package(
LIBRARIES
CATKIN_DEPENDS
)

cs_add_executable(racing
src/racing/racing.cpp
)

target_link_libraries(racing
${catkin_LIBRARIES}
${OpenCV_LIBRARIES}
stdc++fs
zmq
zmqpp
)

# camera

cs_add_executable(camera
src/camera/camera.cpp
)

target_link_libraries(camera
${catkin_LIBRARIES}
${OpenCV_LIBRARIES}
stdc++fs
zmq
zmqpp
)

# Finish
cs_install()
cs_export()
cs_export()
109 changes: 109 additions & 0 deletions flightros/include/flightros/motion_planning/motion_planning.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// standard libraries
#include <assert.h>
#include <Eigen/Dense>
#include <cmath>
#include <cstring>
#include <experimental/filesystem>
#include <fstream>
#include <iostream>
#include <iterator>
#include <sstream>
#include <thread>
#include <vector>

// Open3D
#include <Open3D/Geometry/KDTreeFlann.h>
#include <Open3D/Geometry/PointCloud.h>
#include <Open3D/IO/ClassIO/PointCloudIO.h>

// OMPL
#include <ompl/base/SpaceInformation.h>
#include <ompl/base/spaces/SE3StateSpace.h>
#include <ompl/config.h>
#include <ompl/geometric/SimpleSetup.h>
#include <ompl/geometric/planners/rrt/RRTConnect.h>

// TinyPly
#define TINYPLY_IMPLEMENTATION
#include "tinyply.h"

// flightlib
#include "flightlib/bridges/unity_bridge.hpp"
#include "flightlib/bridges/unity_message_types.hpp"
#include "flightlib/common/quad_state.hpp"
#include "flightlib/common/types.hpp"
#include "flightlib/objects/quadrotor.hpp"
#include "flightlib/sensors/rgb_camera.hpp"

// ros
#include <ros/ros.h>

namespace ob = ompl::base;
namespace og = ompl::geometric;

using namespace flightlib;

namespace motion_planning {

struct float2 {
float x, y;
};
struct float3 {
float x, y, z;
};
struct double3 {
double x, y, z;
};
struct uint3 {
uint32_t x, y, z;
};
struct uint4 {
uint32_t x, y, z, w;
};
std::vector<float3> verts;
float range = 1;
bool solution_found = false;
bool trajectory_found = false;

std::vector<float3> readPointCloud();
float3 min_bounds;
float3 max_bounds;

Eigen::Vector3d stateToEigen(const ompl::base::State *state);

std::vector<ompl::base::State *> path_;
std::vector<Eigen::Vector3d> vecs_;

void getBounds();

void plan();

bool isStateValid(const ob::State *state);

bool isInRange(float x, float y, float z);

open3d::geometry::KDTreeFlann kd_tree_;
Eigen::MatrixXd points_;
bool searchRadius(const Eigen::Vector3d &query_point, const double radius);

void executePath();

// void setupQuad();
bool setUnity(const bool render);
bool connectUnity(void);

// unity quadrotor
std::shared_ptr<Quadrotor> quad_ptr_;
std::shared_ptr<RGBCamera> rgb_camera_;
QuadState quad_state_;

// Flightmare(Unity3D)
std::shared_ptr<UnityBridge> unity_bridge_ptr_;
SceneID scene_id_{UnityScene::NATUREFOREST};
bool unity_ready_{false};
bool unity_render_{true};
RenderMessage_t unity_output_;
uint16_t receive_id_{0};


} // namespace motion_planning
Loading

0 comments on commit 87f4712

Please sign in to comment.