-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathenv_viewer.py
40 lines (33 loc) · 1.42 KB
/
env_viewer.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
import gym, sys, argparse
import numpy as np
from .learn import make_env
# import assistive_gym
if sys.version_info < (3, 0):
print('Please use Python 3')
exit()
def sample_action(env, coop):
if coop:
return {'robot': env.action_space_robot.sample(), 'human': env.action_space_human.sample()}
return env.action_space.sample()
def viewer(env_name):
coop = 'Human' in env_name
env = make_env(env_name, coop=True) if coop else gym.make(env_name)
while True:
done = False
env.render()
observation = env.reset()
action = sample_action(env, coop)
if coop:
print('Robot observation size:', np.shape(observation['robot']), 'Human observation size:', np.shape(observation['human']), 'Robot action size:', np.shape(action['robot']), 'Human action size:', np.shape(action['human']))
else:
print('Observation size:', np.shape(observation), 'Action size:', np.shape(action))
while not done:
observation, reward, done, info = env.step(sample_action(env, coop))
if coop:
done = done['__all__']
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Assistive Gym Environment Viewer')
parser.add_argument('--env', default='ScratchItchJaco-v1',
help='Environment to test (default: ScratchItchJaco-v1)')
args = parser.parse_args()
viewer(args.env)