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

Split all gympp resources to a separated folder #157

Merged
Merged
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
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -107,9 +107,6 @@ endif()
# Dependencies
add_subdirectory(deps)

# Add the C++ sources subdirectory
add_subdirectory(gympp)

# ========
# IGNITION
# ========
@@ -118,6 +115,11 @@ find_package(ignition-gazebo3 COMPONENTS all)
option(GYMIGNITION_USE_IGNITION
"Build C++ code depending on Ignition Robotics" ${ignition-gazebo3_FOUND})

# Add the C++ sources subdirectories
add_subdirectory(cpp/gympp/base)
add_subdirectory(cpp/gympp/gazebo)
add_subdirectory(cpp/gympp/plugins)

# Add the targets depending on Ignition Robotics
if(${GYMIGNITION_USE_IGNITION})
add_subdirectory(ignition)
6 changes: 4 additions & 2 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -35,11 +35,13 @@ swig_add_library(${swig_name}
SOURCES ${swig_name}.i)

target_link_libraries(${swig_name} PUBLIC
gympp
IgnitionRobot
RobotSingleton
GymFactory
IgnitionEnvironment
GazeboEnvironment
RobotSingleton
GazeboWrapper
IgnitionRobot
${PYTHON_LIBRARIES})

set_property(TARGET ${swig_name} PROPERTY
88 changes: 44 additions & 44 deletions bindings/gympp_bindings.i
Original file line number Diff line number Diff line change
@@ -2,15 +2,15 @@

%{
#define SWIG_FILE_WITH_INIT
#include "gympp/Common.h"
#include "gympp/Environment.h"
#include "gympp/gazebo/IgnitionEnvironment.h"
#include "gympp/base/Common.h"
#include "gympp/base/Environment.h"
#include "gympp/base/Robot.h"
#include "gympp/base/Space.h"
#include "gympp/gazebo/GazeboEnvironment.h"
#include "gympp/gazebo/GazeboWrapper.h"
#include "gympp/gazebo/GymFactory.h"
#include "gympp/gazebo/Metadata.h"
#include "gympp/gazebo/RobotSingleton.h"
#include "gympp/GymFactory.h"
#include "gympp/Metadata.h"
#include "gympp/Robot.h"
#include "gympp/Space.h"
#include <cstdint>
%}

@@ -34,46 +34,46 @@
%template(Array4d) std::array<double, 4>;
%template(Array6d) std::array<double, 6>;

%include "gympp/Common.h"
%template(BufferContainer_i) gympp::BufferContainer<int>;
%template(BufferContainer_u) gympp::BufferContainer<size_t>;
%template(BufferContainer_f) gympp::BufferContainer<float>;
%template(BufferContainer_d) gympp::BufferContainer<double>;
%template(get_i) gympp::data::Sample::get<int>;
%template(get_u) gympp::data::Sample::get<size_t>;
%template(get_f) gympp::data::Sample::get<float>;
%template(get_d) gympp::data::Sample::get<double>;
%template(getBuffer_i) gympp::data::Sample::getBuffer<int>;
%template(getBuffer_u) gympp::data::Sample::getBuffer<size_t>;
%template(getBuffer_f) gympp::data::Sample::getBuffer<float>;
%template(getBuffer_d) gympp::data::Sample::getBuffer<double>;
%include "gympp/base/Common.h"
%template(BufferContainer_i) gympp::base::BufferContainer<int>;
%template(BufferContainer_u) gympp::base::BufferContainer<size_t>;
%template(BufferContainer_f) gympp::base::BufferContainer<float>;
%template(BufferContainer_d) gympp::base::BufferContainer<double>;
%template(get_i) gympp::base::data::Sample::get<int>;
%template(get_u) gympp::base::data::Sample::get<size_t>;
%template(get_f) gympp::base::data::Sample::get<float>;
%template(get_d) gympp::base::data::Sample::get<double>;
%template(getBuffer_i) gympp::base::data::Sample::getBuffer<int>;
%template(getBuffer_u) gympp::base::data::Sample::getBuffer<size_t>;
%template(getBuffer_f) gympp::base::data::Sample::getBuffer<float>;
%template(getBuffer_d) gympp::base::data::Sample::getBuffer<double>;

%include "optional.i"
%template(Optional_i) std::optional<int>;
%template(Optional_u) std::optional<size_t>;
%template(Optional_f) std::optional<float>;
%template(Optional_d) std::optional<double>;
%template(Optional_state) std::optional<gympp::State>;
%template(Optional_sample) std::optional<gympp::data::Sample>;
%template(Optional_state) std::optional<gympp::base::State>;
%template(Optional_sample) std::optional<gympp::base::data::Sample>;

%include <std_shared_ptr.i>
%shared_ptr(gympp::spaces::Space)
%shared_ptr(gympp::spaces::Box)
%shared_ptr(gympp::spaces::Discrete)
%include "gympp/Space.h"
%shared_ptr(gympp::base::spaces::Space)
%shared_ptr(gympp::base::spaces::Box)
%shared_ptr(gympp::base::spaces::Discrete)
%include "gympp/base/Space.h"

%shared_ptr(gympp::Environment)
%shared_ptr(gympp::base::Environment)
%shared_ptr(gympp::gazebo::GazeboWrapper)
%shared_ptr(gympp::gazebo::IgnitionEnvironment)
%shared_ptr(gympp::gazebo::GazeboEnvironment)
%include "ignition/common/SingletonT.hh"
%ignore ignition::common::SingletonT<gympp::GymFactory>::myself;
%template(GymFactorySingleton) ignition::common::SingletonT<gympp::GymFactory>;
%ignore ignition::common::SingletonT<gympp::gazebo::GymFactory>::myself;
%template(GymFactorySingleton) ignition::common::SingletonT<gympp::gazebo::GymFactory>;

%include "gympp/Environment.h"
%include "gympp/base/Environment.h"
%include "gympp/gazebo/GazeboWrapper.h"
%include "gympp/gazebo/IgnitionEnvironment.h"
%include "gympp/gazebo/GazeboEnvironment.h"

%extend gympp::Robot {
%extend gympp::base::Robot {
bool setdt(const double dt) {
return $self->setdt(std::chrono::duration<double>(dt));
}
@@ -84,24 +84,24 @@
}

%include "weak_ptr.i"
%shared_ptr(gympp::Robot)
%template(RobotWeakPtr) std::weak_ptr<gympp::Robot>;
%shared_ptr(gympp::base::Robot)
%template(RobotWeakPtr) std::weak_ptr<gympp::base::Robot>;

%ignore gympp::Robot::dt;
%ignore gympp::Robot::setdt(const StepSize&);
%include "gympp/Robot.h"
%template(Vector_contact) std::vector<gympp::ContactData>;
%ignore gympp::base::Robot::dt;
%ignore gympp::base::Robot::setdt(const StepSize&);
%include "gympp/base/Robot.h"
%template(Vector_contact) std::vector<gympp::base::ContactData>;

%inline %{
std::shared_ptr<gympp::gazebo::IgnitionEnvironment> envToIgnEnv(gympp::EnvironmentPtr env) {
return std::dynamic_pointer_cast<gympp::gazebo::IgnitionEnvironment>(env);
std::shared_ptr<gympp::gazebo::GazeboEnvironment> envToGazeboEnvironment(gympp::base::EnvironmentPtr env) {
return std::dynamic_pointer_cast<gympp::gazebo::GazeboEnvironment>(env);
}

std::shared_ptr<gympp::gazebo::GazeboWrapper> envToGazeboWrapper(gympp::EnvironmentPtr env) {
std::shared_ptr<gympp::gazebo::GazeboWrapper> envToGazeboWrapper(gympp::base::EnvironmentPtr env) {
return std::dynamic_pointer_cast<gympp::gazebo::GazeboWrapper>(env);
}
%}

%include "gympp/Metadata.h"
%include "gympp/GymFactory.h"
%include "gympp/gazebo/Metadata.h"
%include "gympp/gazebo/GymFactory.h"
%include "gympp/gazebo/RobotSingleton.h"
91 changes: 91 additions & 0 deletions cpp/gympp/base/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved.
# This software may be modified and distributed under the terms of the
# GNU Lesser General Public License v2.1 or any later version.

# =====
# GYMPP
# =====

add_library(gympp
include/gympp/base/Environment.h
include/gympp/base/Common.h
include/gympp/base/Log.h
include/gympp/base/Random.h
include/gympp/base/Space.h
include/gympp/base/Robot.h
Space.cpp
Random.cpp)

find_package(ignition-common3 QUIET)

if(ignition-common3_FOUND)
target_compile_definitions(gympp PUBLIC USE_IGNITION_LOGS)
target_link_libraries(gympp PUBLIC
ignition-common3::ignition-common3)
endif()

file(GLOB_RECURSE GYMPP_HEADERS_INSTALL include/*.h)

if(NOT CMAKE_BUILD_TYPE STREQUAL "PyPI")
set_target_properties(gympp PROPERTIES
PUBLIC_HEADER "${GYMPP_HEADERS_INSTALL}")
endif()

target_include_directories(gympp PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

# ====
# TASK
# ====

add_library(Task INTERFACE)
target_sources(Task INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/include/gympp/base/Task.h)

target_include_directories(Task INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

target_link_libraries(Task INTERFACE gympp)

if(NOT CMAKE_BUILD_TYPE STREQUAL "PyPI")
set_target_properties(Task PROPERTIES
PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include/gympp/base/Task.h)
endif()

# ==============
# TASK SINGLETON
# ==============

add_library(TaskSingleton
include/gympp/base/TaskSingleton.h
TaskSingleton.cpp)

target_include_directories(TaskSingleton PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

target_link_libraries(TaskSingleton
PRIVATE
gympp
Task)

if(NOT CMAKE_BUILD_TYPE STREQUAL "PyPI")
set_target_properties(TaskSingleton PROPERTIES
PUBLIC_HEADER include/gympp/base/TaskSingleton.h)
endif()

# ===================
# INSTALL THE TARGETS
# ===================

if(NOT CMAKE_BUILD_TYPE STREQUAL "PyPI")
install(
TARGETS gympp Task TaskSingleton
EXPORT gympp
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gympp/base)
endif()
10 changes: 5 additions & 5 deletions gympp/src/Random.cpp → cpp/gympp/base/Random.cpp
Original file line number Diff line number Diff line change
@@ -6,30 +6,30 @@
* GNU Lesser General Public License v2.1 or any later version.
*/

#include "gympp/Random.h"
#include "gympp/base/Random.h"
#include <random>

static std::random_device rd;
static size_t Seed = rd();
static std::default_random_engine Engine(Seed);

gympp::Random& gympp::Random::instance()
gympp::base::Random& gympp::base::Random::instance()
{
static Random random;
return random;
}

size_t gympp::Random::seed()
size_t gympp::base::Random::seed()
{
return Seed;
}

std::default_random_engine& gympp::Random::engine()
std::default_random_engine& gympp::base::Random::engine()
{
return Engine;
}

void gympp::Random::setSeed(size_t seed)
void gympp::base::Random::setSeed(size_t seed)
{
Seed = seed;
Engine = std::default_random_engine(seed);
10 changes: 5 additions & 5 deletions gympp/src/Space.cpp → cpp/gympp/base/Space.cpp
Original file line number Diff line number Diff line change
@@ -6,17 +6,17 @@
* GNU Lesser General Public License v2.1 or any later version.
*/

#include "gympp/Space.h"
#include "gympp/Log.h"
#include "gympp/Random.h"
#include "gympp/base/Space.h"
#include "gympp/base/Log.h"
#include "gympp/base/Random.h"

#include <cassert>
#include <ostream>
#include <random>
#include <utility>
#include <vector>

using namespace gympp::spaces;
using namespace gympp::base::spaces;

// ===
// BOX
@@ -148,7 +148,7 @@ Discrete::Sample Discrete::sample()
std::uniform_int_distribution<> distr(0, static_cast<int>(pImpl->n) - 1);

// Create the buffer
auto buffer = gympp::BufferContainer<Type>::type(1, Type{});
auto buffer = gympp::base::BufferContainer<Type>::type(1, Type{});

// Fill it with data
buffer[0] = distr(Random::engine());
Original file line number Diff line number Diff line change
@@ -6,14 +6,14 @@
* GNU Lesser General Public License v2.1 or any later version.
*/

#include "gympp/gazebo/TaskSingleton.h"
#include "gympp/Log.h"
#include "gympp/gazebo/Task.h"
#include "gympp/base/TaskSingleton.h"
#include "gympp/base/Log.h"
#include "gympp/base/Task.h"

#include <cassert>
#include <ostream>

using namespace gympp::gazebo;
using namespace gympp::base;

class TaskSingleton::Impl
{
@@ -22,10 +22,12 @@ class TaskSingleton::Impl
};

TaskSingleton::TaskSingleton()
: pImpl{new Impl(), [](Impl* impl) { delete impl; }}
: pImpl{new Impl()}
{}

gympp::gazebo::TaskSingleton& TaskSingleton::get()
TaskSingleton::~TaskSingleton()= default;

gympp::base::TaskSingleton& TaskSingleton::get()
{
static TaskSingleton instance;
return instance;
Loading