-
Notifications
You must be signed in to change notification settings - Fork 206
/
standalone.py
executable file
·55 lines (42 loc) · 1.14 KB
/
standalone.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python2
from __future__ import division, print_function
import gym
from gym_duckietown.envs import DuckietownEnv
import pyglet
def main():
env = gym.make('Duckietown-v0')
env.reset()
env.render()
@env.window.event
def on_key_press(symbol, modifiers):
from pyglet.window import key
action = None
if symbol == key.LEFT:
print('left')
action = (-1, 1)
elif symbol == key.RIGHT:
print('right')
action = (1, -1)
elif symbol == key.UP:
print('forward')
action = (1, 1)
elif symbol == key.DOWN:
print('back')
action = (-1, -1)
elif symbol == key.SLASH:
print('RESET')
action = (0,0)
env.reset()
else:
return
if action != (0,0):
obs, reward, done, info = env.step(action)
print(reward, done)
env.render()
if done:
print('done!')
env.reset()
# Enter main event loop
pyglet.app.run()
if __name__ == "__main__":
main()