Skip to content

Commit

Permalink
Migrate from V-REP to CoppeliaSim.
Browse files Browse the repository at this point in the history
  • Loading branch information
stepjam committed Dec 14, 2019
1 parent dc255b5 commit 3defd8c
Show file tree
Hide file tree
Showing 34 changed files with 628 additions and 403 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,5 @@ ENV/
# mypy
.mypy_cache/

pyrep/backend/_v_rep_cffi*
pyrep/backend/_sim_cffi*

16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ before_install:
- sudo apt-get install qt5-default qttools5-dev-tools
install:
- cur=`pwd`
# Pull V-REP
- wget http://coppeliarobotics.com/files/V-REP_PRO_EDU_V3_6_2_Ubuntu16_04.tar.xz
- tar -xf V-REP_PRO_EDU_V3_6_2_Ubuntu16_04.tar.xz
- export VREP_ROOT="$cur/V-REP_PRO_EDU_V3_6_2_Ubuntu16_04"
- echo $VREP_ROOT
# $VREP_ROOT/platforms needed otherwise will get:
# Pull CoppeliaSim
- wget http://www.coppeliarobotics.com/files/CoppeliaSim_Edu_V4_0_0_Ubuntu16_04.tar.xz
- tar -xf CoppeliaSim_EDU_V4_0_0_Ubuntu16_04.tar.xz
- export COPPELIASIM_ROOT="$cur/CoppeliaSim_EDU_V4_0_0_Ubuntu16_04"
- echo COPPELIASIM_ROOT
# COPPELIASIM_ROOT/platforms needed otherwise will get:
# qt.qpa.plugin: Could not load the Qt platform plugin "xcb"
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$VREP_ROOT:$VREP_ROOT/platforms
- export QT_QPA_PLATFORM_PLUGIN_PATH=$VREP_ROOT
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$COPPELIASIM_ROOT:$COPPELIASIM_ROOT/platforms
- export QT_QPA_PLATFORM_PLUGIN_PATH=$COPPELIASIM_ROOT
- pip3 install -r requirements.txt
- python3 setup.py install
# command to run tests
Expand Down
40 changes: 28 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# PyRep [![Build Status](https://travis-ci.com/stepjam/PyRep.svg?token=bQxtiYV3p3bPYhzWMoLi&branch=master)](https://travis-ci.com/stepjam/PyRep) [![Documentation Status](https://readthedocs.org/projects/pyrep/badge/?version=latest)](https://pyrep.readthedocs.io/en/latest/?badge=latest)


__PyRep is a toolkit for robot learning research, built on top of the virtual
robotics experimentation platform ([V-REP](http://www.coppeliarobotics.com/)).__
__PyRep is a toolkit for robot learning research, built on top of [CoppeliaSim](http://www.coppeliarobotics.com/) (previously called V-REP).__

__NOTE:__ V-REP has recently been changed to CoppeliaSim.
If you had an old version of V-REP/PyRep installed, you should removing all
references of V-REP from your bashrc/zshrc (VREP_ROOT, LD_LIBRARY_PATH,
QT_QPA_PLATFORM_PLUGIN_PATH), and then re-run through the installation section.

- [Install](#install)
- [Getting Started](#getting-started)
Expand All @@ -12,14 +16,15 @@ robotics experimentation platform ([V-REP](http://www.coppeliarobotics.com/)).__
- [Planned Future Updates](#planned-future-updates)
- [Contributing](#contributing)
- [Projects Using PyRep](#projects-using-pyrep)
- [What Happened to V-REP?](#what-happened-to-v-rep?)
- [Citation](#citation)


## Install

In addition to the PyRep API, you will aso need to download the latest version of V-REP [from the downloads page](http://www.coppeliarobotics.com/downloads.html).
In addition to the PyRep API, you will aso need to download the latest version of CoppeliaSim [from the downloads page](http://www.coppeliarobotics.com/downloads.html).

Once you have downloaded V-REP, you can pull PyRep from git:
Once you have downloaded CoppeliaSim, you can pull PyRep from git:

```bash
git clone https://github.com/stepjam/PyRep.git
Expand All @@ -29,12 +34,13 @@ cd PyRep
Add the following to your *~/.bashrc* file: (__NOTE__: the 'EDIT ME' in the first line)

```bash
export VREP_ROOT=EDIT/ME/PATH/TO/V-REP/INSTALL/DIR
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$VREP_ROOT
export QT_QPA_PLATFORM_PLUGIN_PATH=$VREP_ROOT
export COPPELIASIM_ROOT=EDIT/ME/PATH/TO/COPPELIASIM/INSTALL/DIR
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$COPPELIASIM_ROOT
export QT_QPA_PLATFORM_PLUGIN_PATH=$COPPELIASIM_ROOT
```

__Remember to source your bashrc after this:__ ```source ~/.bashrc```.
__Remember to source your bashrc (`source ~/.bashrc`) or
zshrc (`source ~/.zshrc`) after this.

Finally install the python library:

Expand All @@ -46,7 +52,7 @@ python3 setup.py install --user
You should be good to go!
Try running one of the examples in the *examples/* folder.

_Although you can use V-REP on any platform, communication via PyRep is currently only supported on Linux._
_Although you can use CoppeliaSim on any platform, communication via PyRep is currently only supported on Linux._

#### Running Headless

Expand All @@ -69,7 +75,7 @@ Below are some problems you may encounter during installation. If none of these
## Getting Started

1. First take a look at [Usage](#usage) and the examples in the *examples/* folder to see if PyRep might be able to accelerate your research.
2. Take a look at the V-REP [tutorials](http://www.coppeliarobotics.com/helpFiles/en/tutorials.htm).
2. Take a look at the CoppeliaSim [tutorials](http://www.coppeliarobotics.com/helpFiles/en/tutorials.htm).

## Usage

Expand Down Expand Up @@ -109,7 +115,7 @@ object.set_position([x, y, z])

Robots are designed to be modular; arms are treated separately to grippers.

Use the robot ttm files defined in robots/ttms. These have been altered slightly from the original ones shipped with V-REP to allow them to be used with motional planning out of the box.
Use the robot ttm files defined in robots/ttms. These have been altered slightly from the original ones shipped with CoppeliaSim to allow them to be used with motional planning out of the box.
The 'tip' of the robot may not be where you want it, so feel free to play around with this.

```python
Expand Down Expand Up @@ -234,8 +240,9 @@ Pull requests welcome for bug fixes!
## Projects Using PyRep

If you use PyRep in your work, then get in contact and we can add you to the list!

- [RLBench: The Robot Learning Benchmark & Learning Environment, arxiv 2019](https://arxiv.org/abs/1909.12271)
- [Learning One-Shot Imitation from Humans without Humans, arxiv 2019](https://arxiv.org/abs/1911.01103)
- [Task-Embedded Control Networks for Few-Shot Imitation Learning, CoRL 2018](https://arxiv.org/abs/1810.03237)
- [Transferring End-to-End Visuomotor Control from Simulation to Real World for a Multi-Stage Task
, CoRL 2017](https://arxiv.org/abs/1707.02267)
Expand All @@ -244,6 +251,15 @@ If you use PyRep in your work, then get in contact and we can add you to the lis

- Georges Nomicos (Imperial College London) for the addition of mobile platforms.

## What Happened to V-REP?

Coppelia Robotics discontinued development of __V-REP__. Instead, they now focus
their efforts on __CoppeliaSim__. CoppeliaSim is 100% compatible with V-REP.
See more information [here](http://coppeliarobotics.com/helpFiles/en/versionInfo.htm#coppeliaSim4.0.0).

PyRep is fully compatible with both V-REP and CoppeliaSim.


## Citation

```
Expand Down
41 changes: 21 additions & 20 deletions cffi_build/cffi_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

# Get PYREP root and find the needed files to compile the cffi lib.

if 'VREP_ROOT' not in os.environ:
raise RuntimeError('VREP_ROOT not defined.')
if 'COPPELIASIM_ROOT' not in os.environ:
raise RuntimeError('COPPELIASIM_ROOT not defined.')

if not os.path.exists(os.environ['VREP_ROOT']):
raise RuntimeError('VREP_ROOT defined, but is not a valid path.')
if not os.path.exists(os.environ['COPPELIASIM_ROOT']):
raise RuntimeError('COPPELIASIM_ROOT defined, but is not a valid path.')

ffibuilder = FFI()

ffibuilder.cdef("""
// ==============
// v_repTypes.h
// simTypes.h
// ==============
// Various types used in the interface functions:
Expand Down Expand Up @@ -84,7 +84,7 @@
// ==============
// v_rep.h
// sim.h
// ==============
simInt simRunSimulator(const simChar* applicationName,simInt options,simVoid(*initCallBack)(),simVoid(*loopCallBack)(),simVoid(*deinitCallBack)());
Expand Down Expand Up @@ -233,8 +233,6 @@
simVoid* simSendModuleMessage(simInt message,simInt* auxiliaryData,simVoid* customData,simInt* replyData);
simVoid* simBroadcastMessage(simInt* auxiliaryData,simVoid* customData,simInt* replyData);
simChar* simGetModuleName(simInt index,simUChar* moduleVersion);
simChar* simGetScriptSimulationParameter(simInt scriptHandle,const simChar* parameterName,simInt* parameterLength);
simInt simSetScriptSimulationParameter(simInt scriptHandle,const simChar* parameterName,const simChar* parameterValue,simInt parameterLength);
simInt simFloatingViewAdd(simFloat posX,simFloat posY,simFloat sizeX,simFloat sizeY,simInt options);
simInt simFloatingViewRemove(simInt floatingViewHandle);
simInt simAdjustView(simInt viewHandleOrIndex,simInt associatedViewableObjectHandle,simInt options,const simChar* viewLabel);
Expand Down Expand Up @@ -501,8 +499,6 @@
simChar* simOpenTextEditor(const simChar* initText,const simChar* xml,simInt* various);
simChar* simPackTable(simInt stackHandle,simInt* bufferSize);
simInt simUnpackTable(simInt stackHandle,const simChar* buffer,simInt bufferSize);
simInt simSetVisionSensorFilter(simInt visionSensorHandle,simInt filterIndex,simInt options,const simInt* pSizes,const simUChar* bytes,const simInt* ints,const simFloat* floats,const simUChar* custom);
simInt simGetVisionSensorFilter(simInt visionSensorHandle,simInt filterIndex,simInt* options,simInt* pSizes,simUChar** bytes,simInt** ints,simFloat** floats,simUChar** custom);
simInt simSetReferencedHandles(simInt objectHandle,simInt count,const simInt* referencedHandles,const simInt* reserved1,const simInt* reserved2);
simInt simGetReferencedHandles(simInt objectHandle,simInt** referencedHandles,simInt** reserved1,simInt** reserved2);
simInt simGetShapeViz(simInt shapeHandle,simInt index,struct SShapeVizInfo* info);
Expand All @@ -518,6 +514,8 @@
simInt simSetJointDependency(simInt jointHandle,simInt masterJointHandle,simFloat offset,simFloat coeff);
simInt simSetStringNamedParam(const simChar* paramName,const simChar* stringParam,simInt paramLength);
simChar* simGetStringNamedParam(const simChar* paramName,simInt* paramLength);
simChar* simGetUserParameter(simInt objectHandle,const simChar* parameterName,simInt* parameterLength);
simInt simSetUserParameter(simInt objectHandle,const simChar* parameterName,const simChar* parameterValue,simInt parameterLength);
Expand Down Expand Up @@ -700,14 +698,16 @@
simInt simLoadUI(const simChar* filename,simInt maxCount,simInt* uiHandles);
simInt simSaveUI(simInt count,const simInt* uiHandles,const simChar* filename);
simInt simHandleGeneralCallbackScript(simInt callbackId,simInt callbackTag,simVoid* additionalData);
//simInt simRegisterCustomLuaFunction(const simChar* funcName,const simChar* callTips,const simInt* inputArgumentTypes,simVoid(*callBack)(struct SLuaCallBack* p));
simInt simRegisterCustomLuaVariable(const simChar* varName,const simChar* varValue);
simInt simRegisterContactCallback(simInt(*callBack)(simInt,simInt,simInt,simInt*,simFloat*));
simInt simRegisterJointCtrlCallback(simInt(*callBack)(simInt,simInt,simInt,const simInt*,const simFloat*,simFloat*));
simInt simGetMechanismHandle(const simChar* mechanismName);
simInt simHandleMechanism(simInt mechanismHandle);
simInt simHandleCustomizationScripts(simInt callType);
//simInt simCallScriptFunction(simInt scriptHandleOrType,const simChar* functionNameAtScriptName,SLuaCallBack* data,const simChar* reservedSetToNull);
simInt simSetVisionSensorFilter(simInt visionSensorHandle,simInt filterIndex,simInt options,const simInt* pSizes,const simUChar* bytes,const simInt* ints,const simFloat* floats,const simUChar* custom);
simInt simGetVisionSensorFilter(simInt visionSensorHandle,simInt filterIndex,simInt* options,simInt* pSizes,simUChar** bytes,simInt** ints,simFloat** floats,simUChar** custom);
simChar* simGetScriptSimulationParameter(simInt scriptHandle,const simChar* parameterName,simInt* parameterLength);
simInt simSetScriptSimulationParameter(simInt scriptHandle,const simChar* parameterName,const simChar* parameterValue,simInt parameterLength);
// Deprecated end
""")
Expand All @@ -716,26 +716,27 @@
cffi_path = os.path.join(cwd, 'cffi_build')

ffibuilder.set_source(
"pyrep.backend._v_rep_cffi",
"pyrep.backend._sim_cffi",
"""
#include "v_rep.h" // the C header of the library
#include "sim.h" // the C header of the library
""",
libraries=['v_rep'],
library_dirs=[os.environ['VREP_ROOT']],
libraries=['coppeliaSim'],
library_dirs=[os.environ['COPPELIASIM_ROOT']],
include_dirs=[cffi_path])

# For some reason, cffi makes it such that it looks for libv_rep.so.1
# rather than libv_rep.so. So we add a symlink.
path = os.path.join(os.environ['VREP_ROOT'], 'libv_rep.so')
path = os.path.join(os.environ['COPPELIASIM_ROOT'], 'libcoppeliaSim.so')
if not os.path.exists(path + '.1'):
print('creating symlink: %s -> %s' % (path + '.1', path))
os.symlink(path, path + '.1')

# Copy lua functions to the VREP_ROOT
print('copying lua file: %s -> %s' % ('pyrep/backend', os.environ['VREP_ROOT']))
lua_script_fname = 'vrepAddOnScript_PyRep.lua'
print('copying lua file: %s -> %s' % ('pyrep/backend',
os.environ['COPPELIASIM_ROOT']))
lua_script_fname = 'simAddOnScript_PyRep.lua'
copyfile(os.path.join('pyrep/backend', lua_script_fname),
os.path.join(os.environ['VREP_ROOT'], lua_script_fname))
os.path.join(os.environ['COPPELIASIM_ROOT'], lua_script_fname))

if __name__ == "__main__":
ffibuilder.compile(verbose=True)
18 changes: 9 additions & 9 deletions cffi_build/v_rep.h → cffi_build/sim.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// ==============
// v_repTypes.h
// simTypes.h
// ==============

// Various types used in the interface functions:
Expand Down Expand Up @@ -68,7 +68,7 @@ typedef int (*jointCtrlCallback)(int,int,int,const int*,const float*,float*);


// ==============
// v_rep.h
// sim.h
// ==============

simInt simRunSimulator(const simChar* applicationName,simInt options,simVoid(*initCallBack)(),simVoid(*loopCallBack)(),simVoid(*deinitCallBack)());
Expand Down Expand Up @@ -217,8 +217,6 @@ simInt simUnloadModule(simInt pluginhandle);
simVoid* simSendModuleMessage(simInt message,simInt* auxiliaryData,simVoid* customData,simInt* replyData);
simVoid* simBroadcastMessage(simInt* auxiliaryData,simVoid* customData,simInt* replyData);
simChar* simGetModuleName(simInt index,simUChar* moduleVersion);
simChar* simGetScriptSimulationParameter(simInt scriptHandle,const simChar* parameterName,simInt* parameterLength);
simInt simSetScriptSimulationParameter(simInt scriptHandle,const simChar* parameterName,const simChar* parameterValue,simInt parameterLength);
simInt simFloatingViewAdd(simFloat posX,simFloat posY,simFloat sizeX,simFloat sizeY,simInt options);
simInt simFloatingViewRemove(simInt floatingViewHandle);
simInt simAdjustView(simInt viewHandleOrIndex,simInt associatedViewableObjectHandle,simInt options,const simChar* viewLabel);
Expand Down Expand Up @@ -485,8 +483,6 @@ simInt simCheckOctreePointOccupancy(simInt octreeHandle,simInt options,const sim
simChar* simOpenTextEditor(const simChar* initText,const simChar* xml,simInt* various);
simChar* simPackTable(simInt stackHandle,simInt* bufferSize);
simInt simUnpackTable(simInt stackHandle,const simChar* buffer,simInt bufferSize);
simInt simSetVisionSensorFilter(simInt visionSensorHandle,simInt filterIndex,simInt options,const simInt* pSizes,const simUChar* bytes,const simInt* ints,const simFloat* floats,const simUChar* custom);
simInt simGetVisionSensorFilter(simInt visionSensorHandle,simInt filterIndex,simInt* options,simInt* pSizes,simUChar** bytes,simInt** ints,simFloat** floats,simUChar** custom);
simInt simSetReferencedHandles(simInt objectHandle,simInt count,const simInt* referencedHandles,const simInt* reserved1,const simInt* reserved2);
simInt simGetReferencedHandles(simInt objectHandle,simInt** referencedHandles,simInt** reserved1,simInt** reserved2);
simInt simGetShapeViz(simInt shapeHandle,simInt index,struct SShapeVizInfo* info);
Expand All @@ -502,6 +498,8 @@ simInt simApplyTexture(simInt shapeHandle,const simFloat* textureCoordinates,sim
simInt simSetJointDependency(simInt jointHandle,simInt masterJointHandle,simFloat offset,simFloat coeff);
simInt simSetStringNamedParam(const simChar* paramName,const simChar* stringParam,simInt paramLength);
simChar* simGetStringNamedParam(const simChar* paramName,simInt* paramLength);
simChar* simGetUserParameter(simInt objectHandle,const simChar* parameterName,simInt* parameterLength);
simInt simSetUserParameter(simInt objectHandle,const simChar* parameterName,const simChar* parameterValue,simInt parameterLength);



Expand Down Expand Up @@ -684,12 +682,14 @@ simInt simGetUIPosition(simInt uiHandle,simInt* position);
simInt simLoadUI(const simChar* filename,simInt maxCount,simInt* uiHandles);
simInt simSaveUI(simInt count,const simInt* uiHandles,const simChar* filename);
simInt simHandleGeneralCallbackScript(simInt callbackId,simInt callbackTag,simVoid* additionalData);
simInt simRegisterCustomLuaFunction(const simChar* funcName,const simChar* callTips,const simInt* inputArgumentTypes,simVoid(*callBack)(struct SLuaCallBack* p));
simInt simRegisterCustomLuaVariable(const simChar* varName,const simChar* varValue);
simInt simRegisterContactCallback(simInt(*callBack)(simInt,simInt,simInt,simInt*,simFloat*));
simInt simRegisterJointCtrlCallback(simInt(*callBack)(simInt,simInt,simInt,const simInt*,const simFloat*,simFloat*));
simInt simGetMechanismHandle(const simChar* mechanismName);
simInt simHandleMechanism(simInt mechanismHandle);
simInt simHandleCustomizationScripts(simInt callType);
//simInt simCallScriptFunction(simInt scriptHandleOrType,const simChar* functionNameAtScriptName,SLuaCallBack* data,const simChar* reservedSetToNull);
// Deprecated end
simInt simSetVisionSensorFilter(simInt visionSensorHandle,simInt filterIndex,simInt options,const simInt* pSizes,const simUChar* bytes,const simInt* ints,const simFloat* floats,const simUChar* custom);
simInt simGetVisionSensorFilter(simInt visionSensorHandle,simInt filterIndex,simInt* options,simInt* pSizes,simUChar** bytes,simInt** ints,simFloat** floats,simUChar** custom);
simChar* simGetScriptSimulationParameter(simInt scriptHandle,const simChar* parameterName,simInt* parameterLength);
simInt simSetScriptSimulationParameter(simInt scriptHandle,const simChar* parameterName,const simChar* parameterValue,simInt parameterLength);
// Deprecated end
4 changes: 2 additions & 2 deletions pyrep/backend/vrep.py → pyrep/backend/sim.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .vrepConst import *
from ._v_rep_cffi import ffi, lib
from .simConst import *
from ._sim_cffi import ffi, lib
import numpy as np


Expand Down
File renamed without changes.
File renamed without changes.
20 changes: 10 additions & 10 deletions pyrep/backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
from contextlib import contextmanager
from typing import List, Tuple
from pyrep.backend import vrep
from pyrep.backend import sim
from pyrep.objects.object import Object
from pyrep.objects.shape import Shape
from pyrep.objects.dummy import Dummy
Expand All @@ -20,20 +20,20 @@ def to_type(handle: int) -> Object:
:param handle: The internal handle of an object.
:return: The sub-type of this object.
"""
t = vrep.simGetObjectType(handle)
if t == vrep.sim_object_shape_type:
t = sim.simGetObjectType(handle)
if t == sim.sim_object_shape_type:
return Shape(handle)
elif t == vrep.sim_object_dummy_type:
elif t == sim.sim_object_dummy_type:
return Dummy(handle)
elif t == vrep.sim_object_path_type:
elif t == sim.sim_object_path_type:
return CartesianPath(handle)
elif t == vrep.sim_object_joint_type:
elif t == sim.sim_object_joint_type:
return Joint(handle)
elif t == vrep.sim_object_visionsensor_type:
elif t == sim.sim_object_visionsensor_type:
return VisionSensor(handle)
elif t == vrep.sim_object_forcesensor_type:
elif t == sim.sim_object_forcesensor_type:
return ForceSensor(handle)
elif t == vrep.sim_object_proximitysensor_type:
elif t == sim.sim_object_proximitysensor_type:
return ProximitySensor(handle)


Expand All @@ -56,7 +56,7 @@ def script_call(function_name_at_script_name: str,
:param bytes: The input bytes to the script (as a string).
:return: Any number of return values from the called Lua function.
"""
return vrep.simExtCallScriptFunction(
return sim.simExtCallScriptFunction(
function_name_at_script_name, script_handle_or_type, list(ints),
list(floats), list(strings), bytes)

Expand Down
Loading

0 comments on commit 3defd8c

Please sign in to comment.