Use pybullet_utils.bullet_client for all our BulletClient needs
This commit is contained in:
@@ -1,29 +0,0 @@
|
|||||||
import functools
|
|
||||||
import inspect
|
|
||||||
import pybullet
|
|
||||||
|
|
||||||
|
|
||||||
class BulletClient(object):
|
|
||||||
"""A wrapper for pybullet to manage different clients."""
|
|
||||||
|
|
||||||
def __init__(self, connection_mode=pybullet.DIRECT, options=""):
|
|
||||||
"""Create a simulation and connect to it."""
|
|
||||||
self._client = pybullet.connect(pybullet.SHARED_MEMORY)
|
|
||||||
if (self._client < 0):
|
|
||||||
print("options=", options)
|
|
||||||
self._client = pybullet.connect(connection_mode, options=options)
|
|
||||||
self._shapes = {}
|
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
"""Clean up connection if not already done."""
|
|
||||||
try:
|
|
||||||
pybullet.disconnect(physicsClientId=self._client)
|
|
||||||
except pybullet.error:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def __getattr__(self, name):
|
|
||||||
"""Inject the client id into Bullet functions."""
|
|
||||||
attribute = getattr(pybullet, name)
|
|
||||||
if inspect.isbuiltin(attribute):
|
|
||||||
attribute = functools.partial(attribute, physicsClientId=self._client)
|
|
||||||
return attribute
|
|
||||||
@@ -17,7 +17,7 @@ from gym import spaces
|
|||||||
from gym.utils import seeding
|
from gym.utils import seeding
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pybullet
|
import pybullet
|
||||||
from . import bullet_client
|
import pybullet_utils.bullet_client as bc
|
||||||
from . import minitaur
|
from . import minitaur
|
||||||
import pybullet_data
|
import pybullet_data
|
||||||
from . import minitaur_env_randomizer
|
from . import minitaur_env_randomizer
|
||||||
@@ -150,9 +150,9 @@ class MinitaurBulletDuckEnv(gym.Env):
|
|||||||
self._action_repeat *= NUM_SUBSTEPS
|
self._action_repeat *= NUM_SUBSTEPS
|
||||||
|
|
||||||
if self._is_render:
|
if self._is_render:
|
||||||
self._pybullet_client = bullet_client.BulletClient(connection_mode=pybullet.GUI)
|
self._pybullet_client = bc.BulletClient(connection_mode=pybullet.GUI)
|
||||||
else:
|
else:
|
||||||
self._pybullet_client = bullet_client.BulletClient()
|
self._pybullet_client = bc.BulletClient()
|
||||||
|
|
||||||
self.seed()
|
self.seed()
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from gym import spaces
|
|||||||
from gym.utils import seeding
|
from gym.utils import seeding
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pybullet
|
import pybullet
|
||||||
from . import bullet_client
|
import pybullet_utils.bullet_client as bc
|
||||||
from . import minitaur
|
from . import minitaur
|
||||||
import os
|
import os
|
||||||
import pybullet_data
|
import pybullet_data
|
||||||
@@ -145,9 +145,9 @@ class MinitaurBulletEnv(gym.Env):
|
|||||||
self._action_repeat *= NUM_SUBSTEPS
|
self._action_repeat *= NUM_SUBSTEPS
|
||||||
|
|
||||||
if self._is_render:
|
if self._is_render:
|
||||||
self._pybullet_client = bullet_client.BulletClient(connection_mode=pybullet.GUI)
|
self._pybullet_client = bc.BulletClient(connection_mode=pybullet.GUI)
|
||||||
else:
|
else:
|
||||||
self._pybullet_client = bullet_client.BulletClient()
|
self._pybullet_client = bc.BulletClient()
|
||||||
|
|
||||||
self.seed()
|
self.seed()
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import numpy as np
|
|||||||
import pybullet
|
import pybullet
|
||||||
from . import racecar
|
from . import racecar
|
||||||
import random
|
import random
|
||||||
from . import bullet_client
|
import pybullet_utils.bullet_client as bc
|
||||||
import pybullet_data
|
import pybullet_data
|
||||||
from pkg_resources import parse_version
|
from pkg_resources import parse_version
|
||||||
|
|
||||||
@@ -40,9 +40,9 @@ class RacecarGymEnv(gym.Env):
|
|||||||
self._renders = renders
|
self._renders = renders
|
||||||
self._isDiscrete = isDiscrete
|
self._isDiscrete = isDiscrete
|
||||||
if self._renders:
|
if self._renders:
|
||||||
self._p = bullet_client.BulletClient(connection_mode=pybullet.GUI)
|
self._p = bc.BulletClient(connection_mode=pybullet.GUI)
|
||||||
else:
|
else:
|
||||||
self._p = bullet_client.BulletClient()
|
self._p = bc.BulletClient()
|
||||||
|
|
||||||
self.seed()
|
self.seed()
|
||||||
#self.reset()
|
#self.reset()
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from gym.utils import seeding
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import time
|
import time
|
||||||
import pybullet
|
import pybullet
|
||||||
from . import bullet_client
|
import pybullet_utils.bullet_client as bc
|
||||||
from . import racecar
|
from . import racecar
|
||||||
import random
|
import random
|
||||||
import pybullet_data
|
import pybullet_data
|
||||||
@@ -42,9 +42,9 @@ class RacecarZEDGymEnv(gym.Env):
|
|||||||
|
|
||||||
self._isDiscrete = isDiscrete
|
self._isDiscrete = isDiscrete
|
||||||
if self._renders:
|
if self._renders:
|
||||||
self._p = bullet_client.BulletClient(connection_mode=pybullet.GUI)
|
self._p = bc.BulletClient(connection_mode=pybullet.GUI)
|
||||||
else:
|
else:
|
||||||
self._p = bullet_client.BulletClient()
|
self._p = bc.BulletClient()
|
||||||
|
|
||||||
self.seed()
|
self.seed()
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
"""A wrapper for pybullet to manage different clients."""
|
|
||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import division
|
|
||||||
import functools
|
|
||||||
import inspect
|
|
||||||
import pybullet
|
|
||||||
|
|
||||||
|
|
||||||
class BulletClient(object):
|
|
||||||
"""A wrapper for pybullet to manage different clients."""
|
|
||||||
|
|
||||||
def __init__(self, connection_mode=None):
|
|
||||||
"""Creates a Bullet client and connects to a simulation.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
connection_mode:
|
|
||||||
`None` connects to an existing simulation or, if fails, creates a
|
|
||||||
new headless simulation,
|
|
||||||
`pybullet.GUI` creates a new simulation with a GUI,
|
|
||||||
`pybullet.DIRECT` creates a headless simulation,
|
|
||||||
`pybullet.SHARED_MEMORY` connects to an existing simulation.
|
|
||||||
"""
|
|
||||||
self._shapes = {}
|
|
||||||
|
|
||||||
if connection_mode is None:
|
|
||||||
self._client = pybullet.connect(pybullet.SHARED_MEMORY)
|
|
||||||
if self._client >= 0:
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
connection_mode = pybullet.DIRECT
|
|
||||||
self._client = pybullet.connect(connection_mode)
|
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
"""Clean up connection if not already done."""
|
|
||||||
try:
|
|
||||||
pybullet.disconnect(physicsClientId=self._client)
|
|
||||||
except pybullet.error:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def __getattr__(self, name):
|
|
||||||
"""Inject the client id into Bullet functions."""
|
|
||||||
attribute = getattr(pybullet, name)
|
|
||||||
if inspect.isbuiltin(attribute):
|
|
||||||
if name not in [
|
|
||||||
"invertTransform",
|
|
||||||
"multiplyTransforms",
|
|
||||||
"getMatrixFromQuaternion",
|
|
||||||
"getEulerFromQuaternion",
|
|
||||||
"computeViewMatrixFromYawPitchRoll",
|
|
||||||
"computeProjectionMatrixFOV",
|
|
||||||
"getQuaternionFromEuler",
|
|
||||||
]: # A temporary hack for now.
|
|
||||||
attribute = functools.partial(attribute, physicsClientId=self._client)
|
|
||||||
return attribute
|
|
||||||
@@ -14,7 +14,7 @@ from gym import spaces
|
|||||||
from gym.utils import seeding
|
from gym.utils import seeding
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pybullet
|
import pybullet
|
||||||
from pybullet_envs.minitaur.envs import bullet_client
|
import pybullet_utils.bullet_client as bc
|
||||||
import pybullet_data
|
import pybullet_data
|
||||||
from pybullet_envs.minitaur.envs import minitaur
|
from pybullet_envs.minitaur.envs import minitaur
|
||||||
from pybullet_envs.minitaur.envs import minitaur_derpy
|
from pybullet_envs.minitaur.envs import minitaur_derpy
|
||||||
@@ -223,9 +223,9 @@ class MinitaurGymEnv(gym.Env):
|
|||||||
self._env_randomizers = convert_to_list(env_randomizer) if env_randomizer else []
|
self._env_randomizers = convert_to_list(env_randomizer) if env_randomizer else []
|
||||||
self._episode_proto = minitaur_logging_pb2.MinitaurEpisode()
|
self._episode_proto = minitaur_logging_pb2.MinitaurEpisode()
|
||||||
if self._is_render:
|
if self._is_render:
|
||||||
self._pybullet_client = bullet_client.BulletClient(connection_mode=pybullet.GUI)
|
self._pybullet_client = bc.BulletClient(connection_mode=pybullet.GUI)
|
||||||
else:
|
else:
|
||||||
self._pybullet_client = bullet_client.BulletClient()
|
self._pybullet_client = bc.BulletClient()
|
||||||
if self._urdf_version is None:
|
if self._urdf_version is None:
|
||||||
self._urdf_version = DEFAULT_URDF_VERSION
|
self._urdf_version = DEFAULT_URDF_VERSION
|
||||||
self._pybullet_client.setPhysicsEngineParameter(enableConeFriction=0)
|
self._pybullet_client.setPhysicsEngineParameter(enableConeFriction=0)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from gym import spaces
|
|||||||
from gym.utils import seeding
|
from gym.utils import seeding
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pybullet
|
import pybullet
|
||||||
from pybullet_envs.bullet import bullet_client
|
import pybullet_utils.bullet_client as bc
|
||||||
|
|
||||||
from pybullet_envs.prediction import boxstack_pybullet_sim
|
from pybullet_envs.prediction import boxstack_pybullet_sim
|
||||||
|
|
||||||
@@ -71,10 +71,10 @@ class PyBulletSimGymEnv(gym.Env):
|
|||||||
print("urdf_root=" + self._urdf_root)
|
print("urdf_root=" + self._urdf_root)
|
||||||
|
|
||||||
if self._is_render:
|
if self._is_render:
|
||||||
self._pybullet_client = bullet_client.BulletClient(connection_mode=pybullet.GUI,
|
self._pybullet_client = bc.BulletClient(connection_mode=pybullet.GUI,
|
||||||
options=optionstring)
|
options=optionstring)
|
||||||
else:
|
else:
|
||||||
self._pybullet_client = bullet_client.BulletClient()
|
self._pybullet_client = bc.BulletClient()
|
||||||
|
|
||||||
if (debug_visualization == False):
|
if (debug_visualization == False):
|
||||||
self._pybullet_client.configureDebugVisualizer(flag=self._pybullet_client.COV_ENABLE_GUI,
|
self._pybullet_client.configureDebugVisualizer(flag=self._pybullet_client.COV_ENABLE_GUI,
|
||||||
|
|||||||
Reference in New Issue
Block a user