예제 #1
0
def main():

    environment = RacecarZEDGymEnv(renders=True)

    targetVelocitySlider = environment._p.addUserDebugParameter(
        "wheelVelocity", -1, 1, 0)
    steeringSlider = environment._p.addUserDebugParameter("steering", -1, 1, 0)

    while (True):
        targetVelocity = environment._p.readUserDebugParameter(
            targetVelocitySlider)
        steeringAngle = environment._p.readUserDebugParameter(steeringSlider)
        discreteAction = 0
        if (targetVelocity < -0.33):
            discreteAction = 0
        else:
            if (targetVelocity > 0.33):
                discreteAction = 6
            else:
                discreteAction = 3
        if (steeringAngle > -0.17):
            if (steeringAngle > 0.17):
                discreteAction = discreteAction + 2
            else:
                discreteAction = discreteAction + 1
        action = discreteAction

        state, reward, done, info = environment.step(action)
        obs = environment.getExtendedObservation()
        print("obs")
        print(obs)
예제 #2
0
def main():

  environment = RacecarZEDGymEnv(renders=True, isDiscrete=isDiscrete)

  targetVelocitySlider = environment._p.addUserDebugParameter("wheelVelocity", -1, 1, 0)
  steeringSlider = environment._p.addUserDebugParameter("steering", -1, 1, 0)

  while (True):
    targetVelocity = environment._p.readUserDebugParameter(targetVelocitySlider)
    steeringAngle = environment._p.readUserDebugParameter(steeringSlider)
    if (isDiscrete):
      discreteAction = 0
      if (targetVelocity < -0.33):
        discreteAction = 0
      else:
        if (targetVelocity > 0.33):
          discreteAction = 6
        else:
          discreteAction = 3
      if (steeringAngle > -0.17):
        if (steeringAngle > 0.17):
          discreteAction = discreteAction + 2
        else:
          discreteAction = discreteAction + 1
      action = discreteAction
    else:
      action = [targetVelocity, steeringAngle]

    state, reward, done, info = environment.step(action)
    obs = environment.getExtendedObservation()
def main():

  env = RacecarZEDGymEnv(renders=True)
  act = deepq.load("racecar_zed_model.pkl")
  print(act)
  while True:
    obs, done = env.reset(), False
    print("===================================")
    print("obs")
    print(obs)
    episode_rew = 0
    while not done:
      env.render()
      obs, rew, done, _ = env.step(act(obs[None])[0])
      episode_rew += rew
    print("Episode reward", episode_rew)
예제 #4
0
def main():

    env = RacecarZEDGymEnv(renders=False, isDiscrete=True)
    model = deepq.models.cnn_to_mlp(convs=[(32, 8, 4), (64, 4, 2), (64, 3, 1)],
                                    hiddens=[256],
                                    dueling=False)
    act = deepq.learn(env,
                      q_func=model,
                      lr=1e-3,
                      max_timesteps=10000,
                      buffer_size=50000,
                      exploration_fraction=0.1,
                      exploration_final_eps=0.02,
                      print_freq=10,
                      callback=callback)
    print("Saving model to racecar_zed_model.pkl")
    act.save("racecar_zed_model.pkl")
예제 #5
0
def main():

    env = RacecarZEDGymEnv(renders=True)
    act = deepq.load("racecar_zed_model.pkl")
    print(act)
    while True:
        obs, done = env.reset(), False
        print("===================================")
        print("obs")
        print(obs)
        episode_rew = 0
        while not done:
            env.render()
            obs, rew, done, _ = env.step(act(obs[None])[0])
            episode_rew += rew
        print("Episode reward", episode_rew)
예제 #6
0
#add parent dir to find package. Only needed for source code build, pip install doesn't need it.
import os, 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)

from pybullet_envs.bullet.racecarZEDGymEnv import RacecarZEDGymEnv
print ("hello")
environment = RacecarZEDGymEnv(renders=True)

targetVelocitySlider = environment._p.addUserDebugParameter("wheelVelocity",-1,1,0)
steeringSlider = environment._p.addUserDebugParameter("steering",-1,1,0)

while (True):
  targetVelocity = environment._p.readUserDebugParameter(targetVelocitySlider)
  steeringAngle = environment._p.readUserDebugParameter(steeringSlider)
  discreteAction = 0
  if (targetVelocity<-0.33):
    discreteAction=0
  else:
    if (targetVelocity>0.33):
      discreteAction=6
    else:
      discreteAction=3
  if (steeringAngle>-0.17):
    if (steeringAngle>0.17):
      discreteAction=discreteAction+2
    else:
      discreteAction=discreteAction+1
  action=discreteAction