Skip to content
Wenhao Yu edited this page Jan 29, 2019 · 21 revisions

DartEnv

Openai Gym with Dart support

About

DartEnv provides 3D multi-body simulation environments based on the openai gym environment. The physics simulation is carried out by Dart and PyDart2, which is a python binding for Dart.

Use DartEnv as separate codebase from OpenAI Gym

Here's a repo created by Benjamin Chasnov that separates out the dart environments from gym: https://github.com/DartEnv/gym-dart. You may find this helpful if you have already installed gym.

Installation:

1. Install Dart

Prerequisites For Mac OSX

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    brew cask install xquartz
    brew install dartsim --only-dependencies
    brew install cmake
    brew install ode # ignore this if it tells you ode has already been installed

Prerequisites for Ubuntu

    sudo apt-get install build-essential cmake pkg-config git
    sudo apt-get install libeigen3-dev libassimp-dev libccd-dev libfcl-dev libboost-regex-dev libboost-system-dev
    sudo apt-get install libopenscenegraph-dev
    sudo apt-get install libbullet-dev
    sudo apt-get install liburdfdom-dev
    sudo apt-get install libnlopt-dev
    sudo apt-get install libxi-dev libxmu-dev freeglut3-dev
    sudo apt-get install libode-dev # ignore this if it tells you ode has already been installed

Note for Ubuntu 14.04 Trusty:

To correctly handle collision for capsule shape, ODE(Open Dynamics Engine) is required. However, currently, libode-dev seems to be broken on Trusty if installed from apt-get. To use capsule shape, please go to ODE download for installing ODE from source.

Download and install Dart

    git clone git://github.com/dartsim/dart.git
    cd dart
    git checkout tags/v6.3.0
    mkdir build
    cd build
    cmake ..
    make -j4
    sudo make install

2. Install PyDart2

Note: If you plan to use virtual environment such as virtualenv or anaconda, which is recommended, you should setup the virtual environment first before installing pydart2 to make sure pydart2 is installed into the desired location.

    conda install swig
    conda install pyqt=5
    git clone https://github.com/sehoonha/pydart2.git
    cd pydart2

Modify setup.py: add a space before -framework Cocoa; add add CXX_FLAGS += '-stdlib=libc++ ' after the line, CXX_FLAGS += '-framework GLUT ' (this is a temporary issue and should not be needed soon)

If you are using Xcode 10 on MacOS X Mojave, run the following line:

MACOSX_DEPLOYMENT_TARGET=10.9 python setup.py build build_ext

otherwise:

python setup.py build build_ext

And then:

    python setup.py develop
    export PYTHONPATH=PATH_TO_PYDART2:$PYTHONPATH

Use python3 instead of python if you plan to use python3.

3. Install Dart Env

The installation is similar to openai gym. To install, simply do

git clone https://github.com/VincentYu68/dart-env.git
cd dart-env
pip install -e .[dart]

Use pip3 instead of pip if you plan to use python3.

Example

After installation, you can run DartEnv using the same API as openai gym. One example of running the dart version of the Hopper model is shown below:

import gym
env = gym.make('DartHopper-v1')
observation = env.reset()
for i in range(100):
    observation, reward, done, envinfo = env.step(env.action_space.sample())
    env.render()

You should be able to see a single-legged robot moving randomly for 100 steps. Now it's ready to be trained to move forward!