Skip to content

Commit

Permalink
Jiminy 1.4.2 (#212)
Browse files Browse the repository at this point in the history
* [misc] Reorder warning compile flags.
* [misc] Fix several coding style issues.
* [misc] Minor README update.
* [misc] Remove unused toys models.
* [examples] Use pinocchio::neutral instead of Zero to get neutral config.
* [core] Fix segfault when writing log while no data is available.
* [core] Refresh model proxies automatically when position/velocities bounds are modified.
* [core] Rename 'motor_inertia' in 'motors_inertias' for API consistency.
* [core] Add getter for max simulation duration.
* [python/simulator] Fix bug during initial state retrieval.
* [gym] Improve internal buffer management. Add several assertion checks at gym env instantiation. Minor bug fixes. 
* [gym] Improvement documentation.
* [gym] Refactor Acrobot and Cartpole RL envs in accordance to official OpenAI Gym implementations.

Co-authored-by: Alexis Duburcq <[email protected]>
duburcqa and Alexis Duburcq authored Oct 16, 2020
1 parent 85a5cc6 commit 0440ac9
Showing 43 changed files with 1,677 additions and 1,551 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
cmake_minimum_required(VERSION 3.10)

# Set the build version
set(BUILD_VERSION 1.4.1)
set(BUILD_VERSION 1.4.2)

# Add definition of Jiminy version for C++ headers
add_definitions("-DJIMINY_VERSION=\"${BUILD_VERSION}\"")
@@ -21,7 +21,7 @@ include(${CMAKE_SOURCE_DIR}/build_tools/cmake/buildPythonWheel.cmake)
# Set the compilation flags
if(NOT WIN32)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -ftemplate-backtrace-limit=0 ${WARN_FULL}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DNDEBUG -O3 ${WARN_FULL} -Wno-non-virtual-dtor -Wno-deprecated-declarations -Wno-unused-parameter -Wfatal-errors -Werror")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DNDEBUG -O3 -Wfatal-errors -Werror ${WARN_FULL} -Wno-non-virtual-dtor -Wno-deprecated-declarations -Wno-unused-parameter")
else()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} /EHsc /bigobj -g /Wall")
# It would be great to have the same quality standard for Windows but
4 changes: 2 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ Installing the Python packages `tianshou==0.3.0` is required to run some of the
python -m pip install tianshou
```

##### (optional) ray[rllib]
##### (optional) ray\[rllib\]

Installing the Python packages `ray==1.0.0` are required to run some of the provided examples, though it is not required to use gym_jiminy. It can be easily installed using `pip` for any OS and Python 3.6/3.7/3.8. The installation instructions are available [here](https://docs.ray.io/en/master/installation.html).

@@ -178,7 +178,7 @@ See this tutorial: <https://towardsdatascience.com/installing-tensorflow-with-cu

Once done, `Pytorch` can be installed following the official "getting started" instructions: <https://pytorch.org/get-started/locally/>

##### (optional) stable_baselines3 / Ray[Rllib] / Tianshou
##### (optional) stable_baselines3 / ray\[rllib\] / tianshou

Installing the Python packages `stable_baselines3`, `tianshou`, `ray` are required to run all the provided examples, though they are not required to use gym_jiminy. They can easily be installed using `pip`. Pick the one you prefer!

21 changes: 5 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -17,48 +17,37 @@ Jiminy is built around [Pinocchio](https://github.com/stack-of-tasks/pinocchio),

- **build an efficient and flexible platform for machine learning in robotics.**

Beside a strong focus on performance to answer machine learning's need for running computationally demanding distributed simulations, Jiminy offers convenience tools for learning via a dedicated learning-oriented Gym-Jiminy ([see below](#jiminy-learning)). It is fully compliant with `gym` standard API and provides an highly customizable wrapper to interface any robotics system with state-of-the-art learning frameworks.
Beside a strong focus on performance to answer machine learning's need for running computationally demanding distributed simulations, Jiminy offers convenience tools for learning via a dedicated learning-oriented [Gym-Jiminy](#jiminy-learning). It is fully compliant with `gym` standard API and provides an highly customizable wrapper to interface any robotics system with state-of-the-art learning frameworks.

## Key features

### General

- Simulation of multi-body systems using minimal coordinates and Lagrangian dynamics.

- Comprehensive API for computing dynamic quantities and their derivatives, exposing and
extending Pinocchio API.

- Comprehensive API for computing dynamic quantities and their derivatives, exposing and extending Pinocchio.
- C++ core with full python bindings, providing frontend API parity between both languages.

- Designed with machine learning in mind, with seemless wrapping of robots in `gym` environments using one-liners. Jiminy provides both the physical engine and the robot model (including sensors) required for learning.

- Easy to install: a simple `python -m pip install jiminy_py` is all that is needed to get you started !

- Easy to install: `pip` is all that is needed to get you [started](#getting-started) !
- Dedicated integration in jupyter notebook working out-of-the-box - including 3D rendering using [Meshcat](https://github.com/rdeits/MeshCat.jl). This facilitates working on remote headless environnement such as machine learning clusters.

- Rich simulation log output, easily customizable for recording, introspection and debugging. The simulation log is made available in RAM directly for fast access, and can be exported as CSV or binary data.

- Available for both Linux and Windows platform.

### Physics

- Support contact and collision with the ground, using either a fixed set of contact points or collision meshes and primitives, through spring-damper reaction forces and friction model.

- Able to simulate multiple articulated systems simultaneously, interacting with each other, to support use cases such as multi-agent reinforcement learning or swarm robotics.

- Support of compliant joints with spring-damper dynamics, to model joint elasticity, a common phenomenon particularly in legged robotics.

- Simulate both continuous or discrete-time controller, with possibly different controller and sensor update frequencies.

A more complete list of features, development status, and changelog are available on the [wiki](https://github.com/Wandercraft/jiminy/wiki).

**The Doxygen documentation is available on [Github.io](https://wandercraft.github.io/jiminy/) and locally in `docs/index.html`.**

# Jiminy learning
# Gym Jiminy

## Description

Gym Jiminy is fully compliant with the now standard reinforcement learning API provided by [Open AI Gym](https://github.com/openai/gym). Additionally, it offers a generic and easily configurable learning environment for learning locomotion tasks, with minimal intervention from the user, who usually only needs to provide the robot's [URDF](https://wiki.ros.org/urdf) file. Furthermore, Gym Jiminy enables easy modification of many aspects of the simulation to provide richer exploration and ensure robust learning. This ranges from external perturbation forces to sensor noise and bias, including randomization of masses and inertias, ground friction model or even gravity itself. Note that learning can
Gym Jiminy is an interface between Jiminy simulator and reinforcement learning frameworks. It is fully compliant with now standard [Open AI Gym](https://github.com/openai/gym) API. Additionally, it offers a generic and easily configurable learning environment for learning locomotion tasks, with minimal intervention from the user, who usually only needs to provide the robot's [URDF](https://wiki.ros.org/urdf) file. Furthermore, Gym Jiminy enables easy modification of many aspects of the simulation to provide richer exploration and ensure robust learning. This ranges from external perturbation forces to sensor noise and bias, including randomization of masses and inertias, ground friction model or even gravity itself. Note that learning can
easily be done on any high-level dynamics features, or restricted to mock sensor data for end-to-end learning.

Gym is cross-platform and compatible out-of-the-box with most Reinforcement Learning frameworks implementing standard algorithms. For instance, [Stable Baselines 3](https://github.com/DLR-RM/stable-baselines3), [RL Coach](https://github.com/NervanaSystems/coach), [Tianshou](https://github.com/thu-ml/tianshou), or [Rllib](https://github.com/ray-project/ray). `RL Coach` leverages the open-source Machine Learning framework [Tensorflow](https://github.com/tensorflow/tensorflow) as backend, `Stable Baselines 3` and `Tianshou` use its counterpart [Pytorch](https://pytorch.org/), and `Rllib` supports both. A few learning examples relying on those packages are also provided.
2 changes: 1 addition & 1 deletion build_tools/cmake/base.cmake
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ set(WARN_FULL "-Wall -Wextra -Weffc++ -pedantic -pedantic-errors \
-Wmissing-noreturn -Wpacked -Wpointer-arith \
-Wredundant-decls -Wshadow -Wstack-protector \
-Wstrict-aliasing=2 -Wswitch-default -Wswitch-enum \
-Wunreachable-code -Wunused -Wunused-parameter"
-Wunreachable-code -Wunused"
)

# Shared libraries need PIC
1 change: 1 addition & 0 deletions build_tools/cmake/buildPythonWheel.cmake
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ function(buildPythonWheel TARGET_PATH)
install(CODE "cmake_policy(SET CMP0053 NEW)
cmake_policy(SET CMP0011 NEW)
set(PROJECT_VERSION ${BUILD_VERSION})
set(SOURCE_DIR ${CMAKE_SOURCE_DIR})
file(GLOB_RECURSE src_file_list FOLLOW_SYMLINKS
LIST_DIRECTORIES false
RELATIVE \"${CMAKE_SOURCE_DIR}/${TARGET_DIR}\"
6 changes: 3 additions & 3 deletions build_tools/doc_cpp/Mainpage.md
Original file line number Diff line number Diff line change
@@ -6,10 +6,10 @@ This page contains only the Doxygen documentation for C++ code. It is automatica

## Usage

This documentation groups together all the native C++ code, that is part of the Jiminy project.
This documentation groups together all the native C++ code, that is part of the Jiminy project.

- Documentation for the package sources is available by three different tabs:

- [Packages](./namespaces.html), where file are sorted by C++ package.
- [Classes](./annotated.html), where only C++ classes are listed.
- [Files](./files.html), where one may browse the file directory tree directly.
This is the most complete reference (i.e. some file might be inaccessible from the other two interfaces).
- [Files](./files.html), where one may browse the file directory tree directly. This is the most complete reference. Indeed, some file might be inaccessible from the other two interfaces.
56 changes: 11 additions & 45 deletions build_tools/doc_py/Mainpage.md
Original file line number Diff line number Diff line change
@@ -6,48 +6,14 @@ This page contains only the Doxygen documentation for Python code. It is automat

## Usage

This documentation groups together all the native Python code and bindings, that is part of the jiminy project.
The source code is split in several python packages, each containing both source code for the package
and command line scripts, both of which are covered here.

- For a list of command-line tools (standalone scripts that can be called from the command line), refer to the
[Command Line Scripts](./group__scripts.html) page.

- Documentation for the package sources is available by three different tabs:
- [Packages](./namespaces.html), where file are sorted by python package.
- [Classes](./annotated.html), where only python classes are listed.
- [Files](./files.html), where one may browse the file directory tree directly.
This is the most complete reference (i.e. some file might be inaccessible from the other two interfaces).

- Python bindings of the C++ source code are documented as well: typically look for \<ClassName\>Visitor class.

## Contributing to this documentation

Here are some guidelines on how this documentation is generated:

- doxygen is used to parse the documentation, thus everything works like in C code:
- use triple-double quote comment (""") to start and end a doxygen comment block.
- comments must be placed after the declaration of the function they comment, or the class creation.
- all [special commands](https://www.stack.nl/~dimitri/doxygen/manual/commands.html) are available. For declaring
a command, \\ or \@ character can be used: for backward compatibility with previously written code, please use
\@ symbol only in python. Here is an example:

def answer(the_question):
"""
\@brief Gives the answer to The question.
\@details This function gives the answer life, the universe and everything.
\@note Not everybody might be psychologically ready for the answer.
\@param question The question.
\@return 42
"""
return 42

- File parsed: the following file are parsed:
- all python files (files with extension .py) in jiminy, **except** \__init__.py and setup.py files and
files in a build (sub)directory or in a unit (sub)directory.
- all files in a scripts directory, regardless of extension (command line scripts have no extensions). Files
without extensions are considered to be python scripts.
- .h files inside a directory named python.

- To add a file to the [Command Line Scripts](./group__scripts.html) page, simply add `\@ingroup scripts` at the top of
the file.
This documentation groups together all the native Python code and bindings, that is part of the jiminy project. The source code is split in several python packages, each containing both source code for the package and command line scripts, both of which are covered here.

- For a list of command-line tools (standalone scripts that can be called from the command line), refer to the [Command Line Scripts](./group__scripts.html) page.

- Documentation for the package sources is available by three different tabs:

- [Packages](./namespaces.html), where file are sorted by python package.
- [Classes](./annotated.html), where only python classes are listed.
- [Files](./files.html), where one may browse the file directory tree directly. This is the most complete reference. Indeed, some file might be inaccessible from the other two interfaces.

- Python bindings of the C++ source code are documented as well: typically look for \<ClassName\>Visitor class.
8 changes: 4 additions & 4 deletions core/include/jiminy/core/Utilities.h
Original file line number Diff line number Diff line change
@@ -334,6 +334,10 @@ namespace jiminy
std::vector<int32_t> & jointsVelocityIdx,
bool_t const & firstJointIdxOnly = false);

hresult_t isPositionValid(pinocchio::Model const & model,
vectorN_t const & position,
bool_t & isValid);

hresult_t insertFlexibilityInModel(pinocchio::Model & modelInOut,
std::string const & childJointNameIn,
std::string const & newJointNameIn);
@@ -396,10 +400,6 @@ namespace jiminy
uint32_t const & firstBlockLength,
uint32_t const & secondBlockStart,
uint32_t const & secondBlockLength);

void catInPlace(std::vector<vectorN_t> const & xList,
vectorN_t & xCat);
vectorN_t cat(std::vector<vectorN_t> const & xList);
}

#include "jiminy/core/Utilities.tpp"
1 change: 1 addition & 0 deletions core/include/jiminy/core/engine/EngineMultiRobot.h
Original file line number Diff line number Diff line change
@@ -428,6 +428,7 @@ namespace jiminy
systemState_t const * & systemState) const;
stepperState_t const & getStepperState(void) const;
bool_t const & getIsSimulationRunning(void) const;
float64_t getMaxSimulationDuration(void) const;

void getLogDataRaw(std::vector<std::string> & header,
std::vector<float64_t> & timestamps,
2 changes: 1 addition & 1 deletion core/include/jiminy/core/robot/Robot.h
Original file line number Diff line number Diff line change
@@ -171,7 +171,7 @@ namespace jiminy
std::vector<std::string> const & getSensorsNames(std::string const & sensorType) const;

vectorN_t getEffortLimit(void) const;
vectorN_t getMotorInertia(void) const;
vectorN_t getMotorsInertias(void) const;

std::vector<std::string> const & getMotorEffortFieldnames(void) const;
// Getters without 'get' prefix for consistency with pinocchio C++ API
2 changes: 1 addition & 1 deletion core/include/jiminy/core/stepper/LieGroup.h
Original file line number Diff line number Diff line change
@@ -434,7 +434,7 @@ namespace Eigen
StateDerivative<vectorN_t> difference(StateBase<OtherDerived> const & other) const
{
assert(robot() == std::forward<StateBase<OtherDerived> const &>(other).robot());
StateDerivative<vectorN_t> dx(robot(), other.v());
StateDerivative<vectorN_t> dx(robot());
pinocchio::difference(robot()->pncModel_, q(), other.q(), dx.v());
dx.a() = v() - other.v();
return dx;
4 changes: 4 additions & 0 deletions core/include/jiminy/core/telemetry/TelemetryRecorder.h
Original file line number Diff line number Diff line change
@@ -42,6 +42,10 @@ namespace jiminy
/// \return Max time, in second.
float64_t getMaximumLogTime(void) const;

/// \brief Get the maximum time that can be logged with the given precision.
/// \return Max time, in second.
static float64_t getMaximumLogTime(float64_t const & timeLoggingPrecision);

////////////////////////////////////////////////////////////////////////
/// \brief Reset the recorder.
////////////////////////////////////////////////////////////////////////
65 changes: 36 additions & 29 deletions core/src/Utilities.cc
Original file line number Diff line number Diff line change
@@ -149,7 +149,7 @@ namespace jiminy
class AppendBoostVariantToJson : public boost::static_visitor<>
{
public:
AppendBoostVariantToJson(Json::Value & root) :
explicit AppendBoostVariantToJson(Json::Value & root) :
root_(root),
field_()
{
@@ -1137,6 +1137,41 @@ namespace jiminy
return returnCode;
}

hresult_t isPositionValid(pinocchio::Model const & model,
vectorN_t const & position,
bool_t & isValid)
{
if (model.nq != position.size())
{
std::cout << "Error - isPositionValid - Size of configuration vector inconsistent with model." << std::endl;
return hresult_t::ERROR_BAD_INPUT;
}

// First, check that the position is normalized
vectorN_t positionNormalized = position;
pinocchio::normalize(model, positionNormalized);
if (((positionNormalized.array() - position.array()).abs() > EPS).any())
{
isValid = false;
return hresult_t::SUCCESS;
}

/* Normalize is not enough since it does not handle the case where
the norm of a joint position is zero. Self difference is used in
such a case, because it should be different from zero (since the
norm does not make sense in the first place). */
vectorN_t selfDifference(model.nv);
pinocchio::difference(model, position, position, selfDifference);
if ((selfDifference.array().abs() > EPS).any())
{
isValid = false;
return hresult_t::SUCCESS;
}

isValid = true;
return hresult_t::SUCCESS;
}

void switchJoints(pinocchio::Model & modelInOut,
uint32_t const & firstJointIdx,
uint32_t const & secondJointIdx)
@@ -1414,32 +1449,4 @@ namespace jiminy
return 0.0;
}
}
vectorN_t cat(std::vector<vectorN_t> const & xList)
{
vectorN_t xCat;

// Initialize the vector the cumilative size
uint32_t xCumSize = 0U;
for (vectorN_t const & x : xList)
{
xCumSize += x.size();
}
xCat.resize(xCumSize);

catInPlace(xList, xCat);

return xCat;
}

void catInPlace(std::vector<vectorN_t> const & xList,
vectorN_t & xCat)
{
uint32_t xIdx = 0U;
for (vectorN_t const & x : xList)
{
uint32_t const xSize = x.size();
xCat.segment(xIdx, xSize) = x;
xIdx += xSize;
}
}
}
Loading

0 comments on commit 0440ac9

Please sign in to comment.