gym env backward compatibility due to gym 0.9.6 breaking changes

This commit is contained in:
erwincoumans 2018-02-06 10:20:41 -08:00
parent ede8042c2c
commit 19231434c2
12 changed files with 78 additions and 39 deletions

View File

@ -47,7 +47,7 @@ def main():
print(obs)
episode_rew = 0
while not done:
env.render()
env.render(mode='human')
act = policy.sample_action(obs, .1)
print("Action")
print(act)

View File

@ -17,7 +17,7 @@ import time
import subprocess
import pybullet as p
import pybullet_data
from pkg_resources import parse_version
logger = logging.getLogger(__name__)
@ -100,7 +100,8 @@ class CartPoleBulletEnv(gym.Env):
def _render(self, mode='human', close=False):
return
render = _render
reset = _reset
seed = _seed
step = _step
if parse_version(gym.__version__)>=parse_version('0.9.6'):
render = _render
reset = _reset
seed = _seed
step = _step

View File

@ -14,6 +14,8 @@ import pybullet as p
from . import kuka
import random
import pybullet_data
from pkg_resources import parse_version
maxSteps = 1000
RENDER_HEIGHT = 720
@ -254,7 +256,8 @@ class KukaCamGymEnv(gym.Env):
#print(reward)
return reward
render = _render
reset = _reset
seed = _seed
step = _step
if parse_version(gym.__version__)>=parse_version('0.9.6'):
render = _render
reset = _reset
seed = _seed
step = _step

View File

@ -13,6 +13,7 @@ import pybullet as p
from . import kuka
import random
import pybullet_data
from pkg_resources import parse_version
largeValObservation = 100
@ -185,6 +186,7 @@ class KukaGymEnv(gym.Env):
def _render(self, mode="rgb_array", close=False):
if mode != "rgb_array":
return np.array([])
base_pos,orn = self._p.getBasePositionAndOrientation(self._kuka.kukaUid)
view_matrix = self._p.computeViewMatrixFromYawPitchRoll(
cameraTargetPosition=base_pos,
@ -199,7 +201,12 @@ class KukaGymEnv(gym.Env):
(_, _, px, _, _) = self._p.getCameraImage(
width=RENDER_WIDTH, height=RENDER_HEIGHT, viewMatrix=view_matrix,
projectionMatrix=proj_matrix, renderer=self._p.ER_BULLET_HARDWARE_OPENGL)
rgb_array = np.array(px)
#renderer=self._p.ER_TINY_RENDERER)
rgb_array = np.array(px, dtype=np.uint8)
rgb_array = np.reshape(rgb_array, (RENDER_WIDTH, RENDER_HEIGHT, 4))
rgb_array = rgb_array[:, :, :3]
return rgb_array
@ -276,7 +283,8 @@ class KukaGymEnv(gym.Env):
#print(reward)
return reward
render = _render
reset = _reset
seed = _seed
step = _step
if parse_version(gym.__version__)>=parse_version('0.9.6'):
render = _render
reset = _reset
seed = _seed
step = _step

View File

@ -10,7 +10,8 @@ import pybullet_data
import pdb
import distutils.dir_util
import glob
from pkg_resources import parse_version
import gym
class KukaDiverseObjectEnv(KukaGymEnv):
"""Class for Kuka environment with diverse objects.
@ -323,4 +324,10 @@ class KukaDiverseObjectEnv(KukaGymEnv):
selected_objects_filenames = []
for object_index in selected_objects:
selected_objects_filenames += [found_object_directories[object_index]]
return selected_objects_filenames
return selected_objects_filenames
if parse_version(gym.__version__)>=parse_version('0.9.6'):
reset = _reset
step = _step

View File

@ -20,6 +20,7 @@ from . import minitaur
import os
import pybullet_data
from . import minitaur_env_randomizer
from pkg_resources import parse_version
NUM_SUBSTEPS = 5
NUM_MOTORS = 8
@ -377,7 +378,8 @@ class MinitaurBulletEnv(gym.Env):
self.minitaur.GetObservationUpperBound())
return observation
render = _render
reset = _reset
seed = _seed
step = _step
if parse_version(gym.__version__)>=parse_version('0.9.6'):
render = _render
reset = _reset
seed = _seed
step = _step

View File

@ -14,6 +14,7 @@ from . import racecar
import random
from . import bullet_client
import pybullet_data
from pkg_resources import parse_version
RENDER_HEIGHT = 720
RENDER_WIDTH = 960
@ -175,7 +176,8 @@ class RacecarGymEnv(gym.Env):
#print(reward)
return reward
render = _render
reset = _reset
seed = _seed
step = _step
if parse_version(gym.__version__)>=parse_version('0.9.6'):
render = _render
reset = _reset
seed = _seed
step = _step

View File

@ -14,6 +14,7 @@ from . import bullet_client
from . import racecar
import random
import pybullet_data
from pkg_resources import parse_version
RENDER_HEIGHT = 720
RENDER_WIDTH = 960
@ -190,7 +191,8 @@ class RacecarZEDGymEnv(gym.Env):
#print(reward)
return reward
render = _render
reset = _reset
seed = _seed
step = _step
if parse_version(gym.__version__)>=parse_version('0.9.6'):
render = _render
reset = _reset
seed = _seed
step = _step

View File

@ -12,7 +12,7 @@ import time
import pybullet as p
from . import simpleHumanoid
import random
from pkg_resources import parse_version
import pybullet_data
@ -110,7 +110,8 @@ class SimpleHumanoidGymEnv(gym.Env):
print(reward)
return reward
render = _render
reset = _reset
seed = _seed
step = _step
if parse_version(gym.__version__)>=parse_version('0.9.6'):
render = _render
reset = _reset
seed = _seed
step = _step

View File

@ -1,7 +1,7 @@
import gym, gym.spaces, gym.utils, gym.utils.seeding
import numpy as np
import pybullet as p
from pkg_resources import parse_version
class MJCFBaseBulletEnv(gym.Env):
"""
@ -115,10 +115,11 @@ class MJCFBaseBulletEnv(gym.Env):
def step(self, *args, **kwargs):
return self._step(*args, **kwargs)
close = _close
render = _render
reset = _reset
seed = _seed
if parse_version(gym.__version__)>=parse_version('0.9.6'):
close = _close
render = _render
reset = _reset
seed = _seed
class Camera:

View File

@ -1,6 +1,12 @@
r"""An example to run of the minitaur gym environment with sine gaits.
"""
import os
import inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(os.path.dirname(currentdir))
os.sys.path.insert(0,parentdir)
import math
import numpy as np
from pybullet_envs.bullet import minitaur_gym_env

View File

@ -1,3 +1,9 @@
import os
import inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(os.path.dirname(currentdir))
os.sys.path.insert(0,parentdir)
import pybullet as p
import math
import time