-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay.py
35 lines (33 loc) · 1.19 KB
/
play.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
import numpy as np
import gym_carlo
import gym
import time
import argparse
from gym_carlo.envs.interactive_controllers import KeyboardController
from utils import *
if __name__ == "__main__":
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument(
"--scenario",
type=str,
help="intersection, circularroad, lanechange",
default="intersection",
)
args = parser.parse_args()
scenario_name = args.scenario.lower()
assert scenario_name in scenario_names, "--scenario argument is invalid!"
env = gym.make(scenario_name + "Scenario-v0", goal=len(goals[scenario_name]))
env.seed(int(np.random.rand() * 1e6))
o, d = env.reset(), False
env.render()
interactive_policy = KeyboardController(env.world, steering_lims[scenario_name])
while not d:
t = time.time()
a = [interactive_policy.steering, interactive_policy.throttle]
o, _, d, _ = env.step(a)
env.render()
while time.time() - t < env.dt / 2:
pass # runs 2x speed. This is not great, but time.sleep() causes problems with the interactive controller