Skip to content

Commit

Permalink
added ROS samples
Browse files Browse the repository at this point in the history
  • Loading branch information
slimeth committed Oct 20, 2020
1 parent d4e15e4 commit 5d5d03e
Show file tree
Hide file tree
Showing 27 changed files with 23,963 additions and 11 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ dist
*.so
__pycache__
build

# Samples
**/flightompl/data/*.txt
2 changes: 1 addition & 1 deletion flightlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ set(

message(STATUS "======> Setup Dependencies")
if(EIGEN_FROM_SYSTTEM)
find_package(Eigen3 3.3.4 QUIET)
find_package(Eigen3 3.3.4 QUIET EXACT REQUIRED)
if(EIGEN3_FOUND)
message(STATUS "Using system provided Eigen.")
message(${EIGEN3_INCLUDE_DIR})
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
105 changes: 102 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_SAMPLES "Building the samples" 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")
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,99 @@ target_link_libraries(flight_pilot_node
stdc++fs
)

# motion_planning

if(BUILD_SAMPLES)

# find all open3D stuff
message("Searching open3D in /usr/local/lib/cmake/")
find_package(Open3D HINTS /usr/local/lib/cmake/)
list(APPEND Open3D_LIBRARIES dl)

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()
endif ()

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

find_package(ompl REQUIRED)

link_directories(/usr/local/lib)
include_directories(${OMPL_INCLUDE_DIRS})

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
)

endif()

# racing

if(BUILD_SAMPLES)

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
)

endif()

# camera

if(BUILD_SAMPLES)

cs_add_executable(camera
src/camera/camera.cpp
)

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

endif()

# Finish
cs_install()
cs_export()
cs_export()
55 changes: 55 additions & 0 deletions flightros/include/flightros/camera/camera.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#pragma once
// ros
#include <cv_bridge/cv_bridge.h>
#include <image_transport/image_transport.h>
#include <ros/ros.h>

// 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>

// 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"

using namespace flightlib;

namespace camera {

// publisher
image_transport::Publisher rgb_pub_;
image_transport::Publisher depth_pub_;
image_transport::Publisher segmentation_pub_;
image_transport::Publisher opticalflow_pub_;
int counter = 0;

// 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::WAREHOUSE};
bool unity_ready_{false};
bool unity_render_{true};
RenderMessage_t unity_output_;
uint16_t receive_id_{0};
} // namespace camera
127 changes: 127 additions & 0 deletions flightros/include/flightros/motion_planning/motion_planning.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#pragma once

// standard libraries
#include <assert.h>
#include <Eigen/Dense>
#include <chrono>
#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 {

class manual_timer {
std::chrono::high_resolution_clock::time_point t0;
double timestamp{0.0};

public:
void start() { t0 = std::chrono::high_resolution_clock::now(); }
void stop() {
timestamp = std::chrono::duration<double>(
std::chrono::high_resolution_clock::now() - t0)
.count() *
1000.0;
}
const double &get() { return timestamp; }
};

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 5d5d03e

Please sign in to comment.