-
Notifications
You must be signed in to change notification settings - Fork 207
/
standalone.py
executable file
·57 lines (44 loc) · 1.27 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
56
57
#!/usr/bin/env python2
from __future__ import division, print_function
import numpy
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 = numpy.array([-1, 1])
elif symbol == key.RIGHT:
print('right')
action = numpy.array([1, -1])
elif symbol == key.UP:
print('forward')
action = numpy.array([1, 1])
elif symbol == key.DOWN:
print('back')
action = numpy.array([-1, -1])
elif symbol == key.SLASH:
print('RESET')
action = None
env.reset()
else:
return
if action is not None:
obs, reward, done, info = env.step(action)
print('stepCount = %s, reward=%.3f' % (env.stepCount, reward))
env.render()
if done:
print('done!')
env.reset()
env.render()
# Enter main event loop
pyglet.app.run()
if __name__ == "__main__":
main()