Fix for 1643, allow to instantiate multiple PyBullet Gym environments (Ant, Humanoid, Hopper, Pendula etc) in the same process (same or other thread). It uses the pybullet_utils.bullet_client to achieve this.

This commit is contained in:
Erwin Coumans
2018-05-18 16:23:54 -07:00
parent d17d496f97
commit 0abe4151e5
24 changed files with 163 additions and 403 deletions

View File

@@ -6,7 +6,7 @@ import pybullet_data
from pybullet_envs.scene_abstract import Scene
import pybullet as p
import pybullet
class StadiumScene(Scene):
@@ -15,8 +15,8 @@ class StadiumScene(Scene):
stadium_halfwidth = 50*0.25 # FOOBALL_FIELD_HALFWID
stadiumLoaded=0
def episode_restart(self):
def episode_restart(self, bullet_client):
self._p = bullet_client
Scene.episode_restart(self) # contains cpp_world.clean_everything()
if (self.stadiumLoaded==0):
self.stadiumLoaded=1
@@ -26,17 +26,17 @@ class StadiumScene(Scene):
# stadium_pose.set_xyz(27, 21, 0) # see RUN_STARTLINE, RUN_RAD constants
filename = os.path.join(pybullet_data.getDataPath(),"plane_stadium.sdf")
self.ground_plane_mjcf=p.loadSDF(filename)
self.ground_plane_mjcf=self._p.loadSDF(filename)
#filename = os.path.join(pybullet_data.getDataPath(),"stadium_no_collision.sdf")
#self.ground_plane_mjcf = p.loadSDF(filename)
#self.ground_plane_mjcf = self._p.loadSDF(filename)
#
for i in self.ground_plane_mjcf:
p.changeDynamics(i,-1,lateralFriction=0.8, restitution=0.5)
p.changeVisualShape(i,-1,rgbaColor=[1,1,1,0.8])
p.configureDebugVisualizer(p.COV_ENABLE_PLANAR_REFLECTION,1)
self._p.changeDynamics(i,-1,lateralFriction=0.8, restitution=0.5)
self._p.changeVisualShape(i,-1,rgbaColor=[1,1,1,0.8])
self._p.configureDebugVisualizer(pybullet.COV_ENABLE_PLANAR_REFLECTION,1)
# for j in range(p.getNumJoints(i)):
# p.changeDynamics(i,j,lateralFriction=0)
# self._p.changeDynamics(i,j,lateralFriction=0)
#despite the name (stadium_no_collision), it DID have collision, so don't add duplicate ground
class SinglePlayerStadiumScene(StadiumScene):