Exemple #1
0
def make_env(env_name, seed=-1, render_mode=False):
  if (env_name.startswith("RacecarBulletEnv")):
    print("bullet_racecar_started")
    env = racecarGymEnv.RacecarGymEnv(isDiscrete=False, renders=render_mode)
  elif (env_name.startswith("MinitaurBulletEnv")):
    print("bullet_minitaur_started")
    env = minitaur_gym_env.MinitaurBulletEnv(render=render_mode)
  elif (env_name.startswith("MinitaurDuckBulletEnv")):
    print("bullet_minitaur_duck_started")
    env = MinitaurDuckBulletEnv(render=render_mode)
  elif (env_name.startswith("MinitaurBallBulletEnv")):
    print("bullet_minitaur_ball_started")
    env = MinitaurBallBulletEnv(render=render_mode)
  elif (env_name.startswith("KukaBulletEnv")):
    print("bullet_kuka_grasping started")
    env = kukaGymEnv.KukaGymEnv(renders=render_mode,isDiscrete=False)
  else:
    if env_name.startswith("Roboschool"):
      import roboschool
    env = gym.make(env_name)
    if render_mode and not env_name.startswith("Roboschool"):
      env.render("human")
  if (seed >= 0):
    env.seed(seed)
  '''
  print("environment details")
  print("env.action_space", env.action_space)
  print("high, low", env.action_space.high, env.action_space.low)
  print("environment details")
  print("env.observation_space", env.observation_space)
  print("high, low", env.observation_space.high, env.observation_space.low)
  assert False
  '''
  return env
Exemple #2
0
def make_env(env_name, seed=-1, render_mode=False):
    if (env_name.startswith("RacecarBulletEnv")):
        print("bullet_racecar_started")
        env = racecarGymEnv.RacecarGymEnv(isDiscrete=False,
                                          renders=render_mode)
    elif (env_name.startswith("RocketLander")):
        from box2d.rocket import RocketLander
        env = RocketLander()
    elif (env_name.startswith("BipedalWalker")):
        if (env_name.startswith("BipedalWalkerHardcore")):
            from box2d.biped import BipedalWalkerHardcore
            env = BipedalWalkerHardcore()
        else:
            from box2d.biped import BipedalWalker
            env = BipedalWalker()
    elif (env_name.startswith("MinitaurBulletEnv")):
        print("bullet_minitaur_started")
        env = minitaur_gym_env.MinitaurBulletEnv(render=render_mode)
    elif (env_name.startswith("MinitaurDuckBulletEnv")):
        print("bullet_minitaur_duck_started")
        env = MinitaurDuckBulletEnv(render=render_mode)
    elif (env_name.startswith("MinitaurBallBulletEnv")):
        print("bullet_minitaur_ball_started")
        env = MinitaurBallBulletEnv(render=render_mode)
    elif (env_name.startswith("CartPoleSwingUp")):
        print("cartpole_swingup_started")
        from custom_envs.cartpole_swingup import CartPoleSwingUpEnv
        hardcore = env_name.startswith("CartPoleSwingUpHardcore")
        env = CartPoleSwingUpEnv(hardcore=hardcore)
    elif (env_name.startswith("KukaBulletEnv")):
        print("bullet_kuka_grasping started")
        env = kukaGymEnv.KukaGymEnv(renders=render_mode, isDiscrete=False)
    else:
        if env_name.startswith("Roboschool"):
            import roboschool
        env = gym.make(env_name)
        if render_mode and not env_name.startswith("Roboschool"):
            env.render("human")
    if (seed >= 0):
        env.seed(seed)
    '''
  print("environment details")
  print("env.action_space", env.action_space)
  print("high, low", env.action_space.high, env.action_space.low)
  print("environment details")
  print("env.observation_space", env.observation_space)
  print("high, low", env.observation_space.high, env.observation_space.low)
  assert False
  '''
    return env
Exemple #3
0
 def __init__(self):
     self.ENV = env = e.RacecarGymEnv(
         isDiscrete=False, renders=False)  #env gym.make(self.ENV_NAME)
     self.NN_TRAIN_CFG = {"epochs": 5}
     self.OPT_CFG = {
         "Random": {
             "popsize": 2000
         },
         "CEM": {
             "popsize": 400,
             "num_elites": 40,
             "max_iters": 5,
             "alpha": 0.1
         }
     }
Exemple #4
0
def make_env(env_name, seed=-1, render_mode=False):
    if (env_name.startswith("RacecarBulletEnv")):
        print("bullet_racecar_started")
        env = racecarGymEnv.RacecarGymEnv(isDiscrete=False,
                                          renders=render_mode)
    elif (env_name.startswith("MinitaurBulletEnv")):
        print("bullet_minitaur_started")
        env = minitaur_gym_env.MinitaurBulletEnv(render=render_mode)
    else:
        env = gym.make(env_name)
    if render_mode and ("BulletEnv-v0" in env_name):
        env.render("human")
    if (seed >= 0):
        env.seed(seed)

    return env
Exemple #5
0
 def __init__(self):
     self.ENV = env = e.RacecarGymEnv(isDiscrete=False ,renders=False) #gym.make(self.ENV_NAME)
     cfg = tf.ConfigProto()
     cfg.gpu_options.allow_growth = True
     self.SESS = tf.Session(config=cfg)
     self.NN_TRAIN_CFG = {"epochs": 5}
     self.OPT_CFG = {
         "Random": {
             "popsize": 2000
         },
         "CEM": {
             "popsize": 400,
             "num_elites": 40,
             "max_iters": 5,
             "alpha": 0.1
         }
     }
import time
import argparse
import multiprocessing

import gym
import numpy as np
import pybullet_envs

from pybullet_envs.stable_baselines.utils import TimeFeatureWrapper
import pybullet_envs.bullet.racecarGymEnv as e


if __name__ == '__main__':
    # env = TimeFeatureWrapper(gym.make('KukaBulletEnv-v0'))
    env = e.RacecarGymEnv(isDiscrete=False, renders=True)
    env.render(mode='human')

    try:
        # Use deterministic actions for evaluation
        episode_rewards, episode_lengths = [], []
        while True:
            env.reset()
            while True:
                action = env.action_space.sample()
                obs, reward, done, _info = env.step(action)
                env.render(mode='human')
                dt = 1. / 240.
                time.sleep(dt)
    except KeyboardInterrupt:
        pass
Exemple #7
0
def make_env(env_name, seed=-1, render_mode=False):
    if (env_name.startswith("RacecarBulletEnv")):
        import pybullet as p
        import pybullet_envs
        import pybullet_envs.bullet.racecarGymEnv as racecarGymEnv
        print("bullet_racecar_started")
        env = racecarGymEnv.RacecarGymEnv(isDiscrete=False,
                                          renders=render_mode)
    elif (env_name.startswith("RocketLander")):
        from box2d.rocket import RocketLander
        env = RocketLander()
    elif (env_name.startswith("BipedalWalker")):
        if (env_name.startswith("BipedalWalkerHardcore")):
            from box2d.biped import BipedalWalkerHardcore
            env = BipedalWalkerHardcore()
        else:
            from box2d.biped import BipedalWalker
            env = BipedalWalker()
    elif (env_name.startswith("MinitaurBulletEnv")):
        import pybullet as p
        import pybullet_envs
        import pybullet_envs.bullet.minitaur_gym_env as minitaur_gym_env
        print("bullet_minitaur_started")
        env = minitaur_gym_env.MinitaurBulletEnv(render=render_mode)
    elif (env_name.startswith("MinitaurDuckBulletEnv")):
        print("bullet_minitaur_duck_started")
        import pybullet as p
        import pybullet_envs
        from custom_envs.minitaur_duck import MinitaurDuckBulletEnv
        env = MinitaurDuckBulletEnv(render=render_mode)
    elif (env_name.startswith("MinitaurBallBulletEnv")):
        print("bullet_minitaur_ball_started")
        import pybullet as p
        import pybullet_envs
        from custom_envs.minitaur_ball import MinitaurBallBulletEnv
        env = MinitaurBallBulletEnv(render=render_mode)
    elif (env_name.startswith("SlimeVolley")):
        print("slimevolley_swingup_started")
        from custom_envs.slimevolley import SlimeVolleyEnv, SurvivalRewardEnv
        env = SlimeVolleyEnv()
        env = SurvivalRewardEnv(env)  # optional
    elif (env_name.startswith("CartPoleSwingUp")):
        print("cartpole_swingup_started")
        from custom_envs.cartpole_swingup import CartPoleSwingUpEnv
        env = CartPoleSwingUpEnv()
    elif (env_name.startswith("KukaBulletEnv")):
        import pybullet as p
        import pybullet_envs
        import pybullet_envs.bullet.kukaGymEnv as kukaGymEnv
        print("bullet_kuka_grasping started")
        env = kukaGymEnv.KukaGymEnv(renders=render_mode, isDiscrete=False)
    elif (env_name.startswith("NoDeathAntBullet")):
        print("no death bullet ant.")
        import pybullet_envs
        from custom_envs.custom_wrapper import NoDeath
        env = NoDeath(gym.make("AntBulletEnv-v0"))
        if render_mode and not env_name.startswith("Roboschool"):
            env.render("human")
    else:
        if env_name.startswith("Roboschool"):
            import roboschool
        if "Bullet" in env_name:
            import pybullet_envs
        env = gym.make(env_name)
        if render_mode and not env_name.startswith("Roboschool"):
            env.render("human")
    if (seed >= 0):
        env.seed(seed)
    '''
  print("environment details")
  print("env.action_space", env.action_space)
  print("high, low", env.action_space.high, env.action_space.low)
  print("environment details")
  print("env.observation_space", env.observation_space)
  print("high, low", env.observation_space.high, env.observation_space.low)
  assert False
  '''
    return env
Exemple #8
0
def make_env(env_name, seed=-1, render_mode=False):
    if (env_name.startswith("RacecarBulletEnv")):
        print("bullet_racecar_started")
        env = racecarGymEnv.RacecarGymEnv(isDiscrete=False,
                                          renders=render_mode)
    elif (env_name.startswith("AugmentBipedalWalker")):
        if (env_name.startswith("AugmentBipedalWalkerHardcore")):
            if (env_name.startswith("AugmentBipedalWalkerHardcoreSmallLegs")):
                from box2d.bipedal_walker import AugmentBipedalWalkerHardcoreSmallLegs
                env = AugmentBipedalWalkerHardcoreSmallLegs()
            else:
                from box2d.bipedal_walker import AugmentBipedalWalkerHardcore
                env = AugmentBipedalWalkerHardcore()
        elif (env_name.startswith("AugmentBipedalWalkerSmallLegs")):
            from box2d.bipedal_walker import AugmentBipedalWalkerSmallLegs
            env = AugmentBipedalWalkerSmallLegs()
        elif (env_name.startswith("AugmentBipedalWalkerTallLegs")):
            from box2d.bipedal_walker import AugmentBipedalWalkerTallLegs
            env = AugmentBipedalWalkerTallLegs()
        else:
            from box2d.bipedal_walker import AugmentBipedalWalker
            env = AugmentBipedalWalker()
    elif (env_name.startswith("MinitaurBulletEnv")):
        print("bullet_minitaur_started")
        env = minitaur_gym_env.MinitaurBulletEnv(render=render_mode)
    elif (env_name.startswith("MinitaurDuckBulletEnv")):
        print("bullet_minitaur_duck_started")
        env = MinitaurDuckBulletEnv(render=render_mode)
    elif (env_name.startswith("MinitaurBallBulletEnv")):
        print("bullet_minitaur_ball_started")
        env = MinitaurBallBulletEnv(render=render_mode)
    elif (env_name.startswith("KukaBulletEnv")):
        print("bullet_kuka_grasping started")
        env = kukaGymEnv.KukaGymEnv(renders=render_mode, isDiscrete=False)
    else:
        if env_name.startswith("Augment"):
            import robogym
        if env_name.startswith("AugmentAnt"):
            from robogym import AugmentAnt
            env = AugmentAnt()
        elif env_name.startswith("AugmentHopper"):
            from robogym import AugmentHopper
            env = AugmentHopper()
        elif env_name.startswith("AugmentHalfCheetah"):
            from robogym import AugmentHalfCheetah
            env = AugmentHalfCheetah()
        else:
            env = gym.make(env_name)
        if render_mode and not env_name.startswith("Augment"):
            env.render("human")
    if (seed >= 0):
        env.seed(seed)
    '''
  print("environment details")
  print("env.action_space", env.action_space)
  print("high, low", env.action_space.high, env.action_space.low)
  print("environment details")
  print("env.observation_space", env.observation_space)
  print("high, low", env.observation_space.high, env.observation_space.low)
  assert False
  '''
    return env