From 3891602784a28d14fce716aa162b2a582ba86e09 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Mon, 11 Sep 2017 17:34:06 -0700 Subject: [PATCH] enable continuous action space for racecarZEDGymEnv disable SHARED_MEMORY connection (it was just some debug test) --- .../gym/pybullet_envs/bullet/bullet_client.py | 2 +- .../gym/pybullet_envs/bullet/kukaGymEnv.py | 2 +- .../pybullet_envs/bullet/racecarZEDGymEnv.py | 23 +++++++++++++------ .../pybullet/gym/pybullet_envs/env_bases.py | 2 +- .../examples/racecarZEDGymEnvTest.py | 4 ++-- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/examples/pybullet/gym/pybullet_envs/bullet/bullet_client.py b/examples/pybullet/gym/pybullet_envs/bullet/bullet_client.py index 0eda1fb2e..fcdedf10c 100644 --- a/examples/pybullet/gym/pybullet_envs/bullet/bullet_client.py +++ b/examples/pybullet/gym/pybullet_envs/bullet/bullet_client.py @@ -8,7 +8,7 @@ class BulletClient(object): def __init__(self, connection_mode=pybullet.DIRECT): """Create a simulation and connect to it.""" - self._client = pybullet.connect(pybullet.SHARED_MEMORY) + self._client = -1 #pybullet.connect(pybullet.SHARED_MEMORY) if(self._client<0): self._client = pybullet.connect(connection_mode) self._shapes = {} diff --git a/examples/pybullet/gym/pybullet_envs/bullet/kukaGymEnv.py b/examples/pybullet/gym/pybullet_envs/bullet/kukaGymEnv.py index 5928a7232..903727b07 100644 --- a/examples/pybullet/gym/pybullet_envs/bullet/kukaGymEnv.py +++ b/examples/pybullet/gym/pybullet_envs/bullet/kukaGymEnv.py @@ -37,7 +37,7 @@ class KukaGymEnv(gym.Env): self.terminated = 0 self._p = p if self._renders: - cid = p.connect(p.SHARED_MEMORY) + cid = -1 #p.connect(p.SHARED_MEMORY) if (cid<0): cid = p.connect(p.GUI) p.resetDebugVisualizerCamera(1.3,180,-41,[0.52,-0.2,-0.33]) diff --git a/examples/pybullet/gym/pybullet_envs/bullet/racecarZEDGymEnv.py b/examples/pybullet/gym/pybullet_envs/bullet/racecarZEDGymEnv.py index 5fcbd75f7..507f6cb1a 100644 --- a/examples/pybullet/gym/pybullet_envs/bullet/racecarZEDGymEnv.py +++ b/examples/pybullet/gym/pybullet_envs/bullet/racecarZEDGymEnv.py @@ -25,7 +25,7 @@ class RacecarZEDGymEnv(gym.Env): urdfRoot=pybullet_data.getDataPath(), actionRepeat=10, isEnableSelfCollision=True, - isDiscrete=True, + isDiscrete=False, renders=True): print("init") self._timeStep = 0.01 @@ -52,7 +52,13 @@ class RacecarZEDGymEnv(gym.Env): #print(observationDim) observation_high = np.array([np.finfo(np.float32).max] * observationDim) - self.action_space = spaces.Discrete(9) + if (isDiscrete): + self.action_space = spaces.Discrete(9) + else: + action_dim = 2 + self._action_bound = 1 + action_high = np.array([self._action_bound] * action_dim) + self.action_space = spaces.Box(-action_high, action_high) self.observation_space = spaces.Box(low=0, high=255, shape=(self._height, self._width, 4)) self.viewer = None @@ -119,11 +125,14 @@ class RacecarZEDGymEnv(gym.Env): basePos,orn = self._p.getBasePositionAndOrientation(self._racecar.racecarUniqueId) #self._p.resetDebugVisualizerCamera(1, 30, -40, basePos) - fwd = [-1,-1,-1,0,0,0,1,1,1] - steerings = [-0.6,0,0.6,-0.6,0,0.6,-0.6,0,0.6] - forward = fwd[action] - steer = steerings[action] - realaction = [forward,steer] + if (self._isDiscrete): + fwd = [-1,-1,-1,0,0,0,1,1,1] + steerings = [-0.6,0,0.6,-0.6,0,0.6,-0.6,0,0.6] + forward = fwd[action] + steer = steerings[action] + realaction = [forward,steer] + else: + realaction = action self._racecar.applyAction(realaction) for i in range(self._actionRepeat): diff --git a/examples/pybullet/gym/pybullet_envs/env_bases.py b/examples/pybullet/gym/pybullet_envs/env_bases.py index 5e2017e42..3379ae4b4 100644 --- a/examples/pybullet/gym/pybullet_envs/env_bases.py +++ b/examples/pybullet/gym/pybullet_envs/env_bases.py @@ -39,7 +39,7 @@ class MJCFBaseBulletEnv(gym.Env): def _reset(self): if (self.physicsClientId<0): - self.physicsClientId = p.connect(p.SHARED_MEMORY) + self.physicsClientId = -1 #p.connect(p.SHARED_MEMORY) if (self.physicsClientId<0): if (self.isRender): self.physicsClientId = p.connect(p.GUI) diff --git a/examples/pybullet/gym/pybullet_envs/examples/racecarZEDGymEnvTest.py b/examples/pybullet/gym/pybullet_envs/examples/racecarZEDGymEnvTest.py index 176846651..64521b121 100644 --- a/examples/pybullet/gym/pybullet_envs/examples/racecarZEDGymEnvTest.py +++ b/examples/pybullet/gym/pybullet_envs/examples/racecarZEDGymEnvTest.py @@ -8,7 +8,7 @@ from pybullet_envs.bullet.racecarZEDGymEnv import RacecarZEDGymEnv def main(): - environment = RacecarZEDGymEnv(renders=True) + environment = RacecarZEDGymEnv(renders=True, isDiscrete=True) targetVelocitySlider = environment._p.addUserDebugParameter("wheelVelocity",-1,1,0) steeringSlider = environment._p.addUserDebugParameter("steering",-1,1,0) @@ -37,4 +37,4 @@ def main(): print(obs) if __name__=="__main__": - main() \ No newline at end of file + main()