Skip to content

Commit

Permalink
Initial upgrade to 4.6; planning collision checking still needed
Browse files Browse the repository at this point in the history
  • Loading branch information
stepjam committed Jan 28, 2024
1 parent 076ca15 commit f8ed911
Show file tree
Hide file tree
Showing 50 changed files with 920 additions and 4,174 deletions.
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.272
hooks:
- id: ruff
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

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

__Announcement!__
PyRep has undergone a __MAJOR__ update, and is now compatible with the most recent version of CoppeliaSim. Most importantly, it now has Mac and Windows support!


- [Install](#install)
- [Running Headless](#running-headless)
Expand All @@ -18,7 +21,7 @@ __PyRep is a toolkit for robot learning research, built on top of [CoppeliaSim](

## Install

PyRep requires version **4.1** of CoppeliaSim. Download:
PyRep requires version **4.6.0** of CoppeliaSim. Download:
- [Ubuntu 16.04](https://www.coppeliarobotics.com/files/V4_1_0/CoppeliaSim_Edu_V4_1_0_Ubuntu16_04.tar.xz)
- [Ubuntu 18.04](https://www.coppeliarobotics.com/files/V4_1_0/CoppeliaSim_Edu_V4_1_0_Ubuntu18_04.tar.xz)
- [Ubuntu 20.04](https://www.coppeliarobotics.com/files/V4_1_0/CoppeliaSim_Edu_V4_1_0_Ubuntu20_04.tar.xz)
Expand Down Expand Up @@ -269,8 +272,6 @@ 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
Empty file removed cffi_build/__init__.py
Empty file.
757 changes: 0 additions & 757 deletions cffi_build/cffi_build.py

This file was deleted.

712 changes: 0 additions & 712 deletions cffi_build/sim.h

This file was deleted.

5 changes: 1 addition & 4 deletions examples/example_panda_ik.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

# Try solving via linearisation
new_joint_pos = agent.solve_ik_via_jacobian([x, y, z - 0.01], quaternion=q)
new_joint_pos = agent.solve_ik_via_jacobian([x, y, z - 0.05], quaternion=q)
new_joint_pos = agent.solve_ik_via_jacobian([x, y, z - 0.1], quaternion=q)
new_joint_pos = agent.solve_ik_via_jacobian([x, y, z - 0.2], quaternion=q)

# This will fail because the distance between start and goal is too far
try:
Expand All @@ -30,7 +27,7 @@
# So let's swap to an alternative IK method...
# This returns 'max_configs' number of joint positions
input('Press key to run solve_ik_via_sampling...')
new_joint_pos = agent.solve_ik_via_sampling([x, y, z - 0.4], quaternion=q)[0]
new_joint_pos = agent.solve_ik_via_sampling([x, y, z - 0.4], quaternion=q, max_time_ms=2000)[0]

# Because the arm is in Forxe/Torque mode, we need to temporarily disable
# dynamics in order to instantaneously move joints.
Expand Down
Binary file modified examples/scene_panda_reach_target.ttt
Binary file not shown.
2 changes: 1 addition & 1 deletion pyrep/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '4.1.0.3'
__version__ = '4.6.0'

testing = False

Expand Down
54 changes: 54 additions & 0 deletions pyrep/backend/bridge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from ctypes import *

from pyrep.backend.lib import *
from pyrep.errors import CoppeliaSimError


def __f(f):
return f + '@lua'

def load():
stack = simCreateStack()
simPushStringOntoStack(stack, c_char_p('scriptClientBridge'.encode('ascii')), 0)
r = simCallScriptFunctionEx(8, c_char_p(__f('require').encode('ascii')), stack)
simReleaseStack(stack)

def call(func, args):
stack = simCreateStack()
import cbor
b = cbor.dumps({'func': func, 'args': args})
simPushStringOntoStack(stack, c_char_p(b), len(b))
r = simCallScriptFunctionEx(8, c_char_p(__f('scriptClientBridge.call').encode('ascii')), stack)
sz = c_int()
ptr = simGetStackStringValue(stack, byref(sz))
o = cbor.loads(string_at(ptr, sz.value))
simReleaseBuffer(ptr)
simReleaseStack(stack)
if o['success']:
ret = o['result']
if len(ret) == 1:
return ret[0]
if len(ret) > 1:
return tuple(ret)
else:
raise CoppeliaSimError(o['error'])

def getObject(name, _info=None):
ret = type(name, (), {})
if not _info:
_info = call('scriptClientBridge.info', [name])
for k, v in _info.items():
if not isinstance(v, dict):
raise ValueError('found nondict')
if len(v) == 1 and 'func' in v:
setattr(ret, k, lambda *a, func=f'{name}.{k}': call(func, a))
elif len(v) == 1 and 'const' in v:
setattr(ret, k, v['const'])
else:
setattr(ret, k, getObject(f'{name}.{k}', _info=v))
return ret

def require(obj):
call('scriptClientBridge.require', [obj])
o = getObject(obj)
return o
142 changes: 142 additions & 0 deletions pyrep/backend/lib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import builtins
import os
import sys

from ctypes import *

from pyrep.errors import PyRepError

if 'COPPELIASIM_ROOT' not in os.environ:
raise PyRepError(
'COPPELIASIM_ROOT not defined. See installation instructions.')
coppeliasim_root = os.environ['COPPELIASIM_ROOT']
coppeliasim_library = os.path.join(coppeliasim_root, "libcoppeliaSim.so")
if not os.path.isfile(coppeliasim_library):
raise PyRepError(
'COPPELIASIM_ROOT was not a correct path. '
'See installation instructions')

appDir = os.path.dirname(coppeliasim_library)
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = appDir

import platform
plat = platform.system()
if plat == 'Darwin':
fd = os.path.normpath(appDir + '/../Frameworks')
os.environ['DYLD_LIBRARY_PATH'] = fd + ':' + os.environ.get('DYLD_LIBRARY_PATH', '')
print(f'If next step fails, do: export DYLD_LIBRARY_PATH={fd}:$DYLD_LIBRARY_PATH and relaunch.')

coppeliaSimLib = cdll.LoadLibrary(coppeliasim_library)
coppeliaSimLib.simRunGui.argtypes = [c_int]
coppeliaSimLib.simRunGui.restype = None
coppeliaSimLib.simCreateStack.argtypes = []
coppeliaSimLib.simCreateStack.restype = c_int
coppeliaSimLib.simReleaseStack.argtypes = [c_int]
coppeliaSimLib.simReleaseStack.restype = c_int
coppeliaSimLib.simReleaseBuffer.argtypes = [c_void_p]
coppeliaSimLib.simReleaseBuffer.restype = c_int
coppeliaSimLib.simPushStringOntoStack.argtypes = [c_int, c_char_p, c_int]
coppeliaSimLib.simPushStringOntoStack.restype = c_int
coppeliaSimLib.simCallScriptFunctionEx.argtypes = [c_int, c_char_p, c_int]
coppeliaSimLib.simCallScriptFunctionEx.restype = c_int
coppeliaSimLib.simGetStackStringValue.argtypes = [c_int, POINTER(c_int)]
coppeliaSimLib.simGetStackStringValue.restype = c_void_p
coppeliaSimLib.simInitialize.argtypes = [c_char_p, c_int]
coppeliaSimLib.simInitialize.restype = c_int
coppeliaSimLib.simGetExitRequest.argtypes = []
coppeliaSimLib.simGetExitRequest.restype = c_int
coppeliaSimLib.simLoop.argtypes = [c_void_p, c_int]
coppeliaSimLib.simLoop.restype = c_int
coppeliaSimLib.simDeinitialize.argtypes = []
coppeliaSimLib.simDeinitialize.restype = c_int
coppeliaSimLib.simSetStringParam.argtypes = [c_int, c_char_p]
coppeliaSimLib.simSetStringParam.restype = c_int
coppeliaSimLib.simSetNamedStringParam.argtypes = [c_char_p, c_char_p, c_int]
coppeliaSimLib.simSetNamedStringParam.restype = c_int
coppeliaSimLib.simRegCallback.argtypes = [c_int, CFUNCTYPE(c_int, c_int)]
coppeliaSimLib.simRegCallback.restype = None
coppeliaSimLib.simCopyStack.argtypes = [c_int]
coppeliaSimLib.simCopyStack.restype = c_int
coppeliaSimLib.simPushNullOntoStack.argtypes = [c_int]
coppeliaSimLib.simPushNullOntoStack.restype = c_int
coppeliaSimLib.simPushBoolOntoStack.argtypes = [c_int, c_bool]
coppeliaSimLib.simPushBoolOntoStack.restype = c_int
coppeliaSimLib.simPushInt32OntoStack.argtypes = [c_int, c_int]
coppeliaSimLib.simPushInt32OntoStack.restype = c_int
coppeliaSimLib.simPushInt64OntoStack.argtypes = [c_int, c_longlong]
coppeliaSimLib.simPushInt64OntoStack.restype = c_int
coppeliaSimLib.simPushUInt8TableOntoStack.argtypes = [c_int, POINTER(c_ubyte), c_int]
coppeliaSimLib.simPushUInt8TableOntoStack.restype = c_int
coppeliaSimLib.simPushInt32TableOntoStack.argtypes = [c_int, POINTER(c_int), c_int]
coppeliaSimLib.simPushInt32TableOntoStack.restype = c_int
coppeliaSimLib.simPushInt64TableOntoStack.argtypes = [c_int, POINTER(c_longlong), c_int]
coppeliaSimLib.simPushInt64TableOntoStack.restype = c_int
coppeliaSimLib.simPushTableOntoStack.argtypes = [c_int]
coppeliaSimLib.simPushTableOntoStack.restype = c_int
coppeliaSimLib.simInsertDataIntoStackTable.argtypes = [c_int]
coppeliaSimLib.simInsertDataIntoStackTable.restype = c_int
coppeliaSimLib.simGetStackSize.argtypes = [c_int]
coppeliaSimLib.simGetStackSize.restype = c_int
coppeliaSimLib.simPopStackItem.argtypes = [c_int, c_int]
coppeliaSimLib.simPopStackItem.restype = c_int
coppeliaSimLib.simMoveStackItemToTop.argtypes = [c_int, c_int]
coppeliaSimLib.simMoveStackItemToTop.restype = c_int
coppeliaSimLib.simGetStackItemType.argtypes = [c_int, c_int]
coppeliaSimLib.simGetStackItemType.restype = c_int
coppeliaSimLib.simGetStackBoolValue.argtypes = [c_int, POINTER(c_bool)]
coppeliaSimLib.simGetStackBoolValue.restype = c_int
coppeliaSimLib.simGetStackInt32Value.argtypes = [c_int, POINTER(c_int)]
coppeliaSimLib.simGetStackInt32Value.restype = c_int
coppeliaSimLib.simGetStackInt64Value.argtypes = [c_int, POINTER(c_longlong)]
coppeliaSimLib.simGetStackInt64Value.restype = c_int
coppeliaSimLib.simGetStackTableInfo.argtypes = [c_int, c_int]
coppeliaSimLib.simGetStackTableInfo.restype = c_int
coppeliaSimLib.simGetStackUInt8Table.argtypes = [c_int, c_char_p, c_int]
coppeliaSimLib.simGetStackUInt8Table.restype = c_int
coppeliaSimLib.simGetStackInt32Table.argtypes = [c_int, POINTER(c_int), c_int]
coppeliaSimLib.simGetStackInt32Table.restype = c_int
coppeliaSimLib.simGetStackInt64Table.argtypes = [c_int, POINTER(c_longlong), c_int]
coppeliaSimLib.simGetStackInt64Table.restype = c_int
coppeliaSimLib.simUnfoldStackTable.argtypes = [c_int]
coppeliaSimLib.simUnfoldStackTable.restype = c_int
coppeliaSimLib.simGetStackDoubleValue.argtypes = [c_int, POINTER(c_double)]
coppeliaSimLib.simGetStackDoubleValue.restype = c_int
coppeliaSimLib.simGetStackDoubleTable.argtypes = [c_int, POINTER(c_double), c_int]
coppeliaSimLib.simGetStackDoubleTable.restype = c_int
coppeliaSimLib.simPushDoubleOntoStack.argtypes = [c_int, c_double]
coppeliaSimLib.simPushDoubleOntoStack.restype = c_int
coppeliaSimLib.simPushDoubleTableOntoStack.argtypes = [c_int, POINTER(c_double), c_int]
coppeliaSimLib.simPushDoubleTableOntoStack.restype = c_int

__all__ = []

for name in dir(coppeliaSimLib):
if name.startswith('sim'):
f = getattr(coppeliaSimLib, name)
if callable(f):
globals()[name] = f
__all__.append(name)

const = type('', (), {})

const.sim_stackitem_null = 0
const.sim_stackitem_double = 1
const.sim_stackitem_bool = 2
const.sim_stackitem_string = 3
const.sim_stackitem_table = 4
const.sim_stackitem_func = 5
const.sim_stackitem_userdat = 6
const.sim_stackitem_thread = 7
const.sim_stackitem_lightuserdat = 8
const.sim_stackitem_integer = 9

const.sim_stack_table_circular_ref = -4
const.sim_stack_table_not_table = -3
const.sim_stack_table_map = -2
const.sim_stack_table_empty = 0

for name in dir(const):
if name.startswith('sim'):
f = getattr(const, name)
globals()[name] = f
__all__.append(name)
Loading

0 comments on commit f8ed911

Please sign in to comment.