forked from clvrai/furniture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_manual.py
129 lines (101 loc) · 3.57 KB
/
demo_manual.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
"""
Human control for the IKEA furniture assembly environment.
The user will learn how to configure the environment and control it.
If you're coming from the demo_demonstration script:
Pass --record_demo True and press Y to save the the current scene
into demos/test.pkl.
"""
import argparse
import numpy as np
from env import make_env
from env.models import furniture_names, background_names
from util import str2bool
# available agents
agent_names = ['Baxter', 'Sawyer', 'Cursor']
# available furnitures
furniture_names
# available background scenes
background_names
def main(args):
"""
Inputs types of agent, furniture model, and background and simulates the environment.
"""
print("IKEA Furniture Assembly Environment!")
# choose an agent
print()
print("Supported robots:\n")
for i, agent in enumerate(agent_names):
print('{}: {}'.format(i, agent))
print()
try:
s = input("Choose an agent (enter a number from 0 to {}): ".format(len(agent_names) - 1))
k = int(s)
agent_name = agent_names[k]
except:
print("Input is not valid. Use 0 by default.")
agent_name = agent_names[0]
# choose a furniture model
print()
print("Supported furniture:\n")
for i, furniture_name in enumerate(furniture_names):
print('{}: {}'.format(i, furniture_name))
print()
try:
s = input("Choose a furniture model (enter a number from 0 to {}): ".format(len(furniture_names) - 1))
furniture_id = int(s)
furniture_name = furniture_names[furniture_id]
except:
print("Input is not valid. Use 0 by default.")
furniture_id = 0
furniture_name = furniture_names[0]
# choose a background scene
print()
print("Supported backgrounds:\n")
for i, background in enumerate(background_names):
print('{}: {}'.format(i, background))
print()
try:
s = input("Choose a background (enter a number from 0 to {}): ".format(len(background_names) - 1))
k = int(s)
background_name = background_names[k]
except:
print("Input is not valid. Use 0 by default.")
background_name = background_names[0]
# set parameters for the environment (env, furniture_id, background)
env_name = 'Furniture{}Env'.format(agent_name)
args.env = env_name
args.furniture_id = furniture_id
args.background = background_name
print()
print("Creating environment (robot: {}, furniture: {}, background: {})".format(
env_name, furniture_name, background_name))
# make environment following arguments
env = make_env(env_name, args)
# print brief instruction
print()
print("="*80)
print("Instruction:\n")
print("Move - WASDQE, Rotate - IJKLUO\n"
"Grasp - SPACE, Release - ENTER (RETURN), Attach - C\n"
"Switch baxter arms or cursors - 1 or 2\n"
"Screenshot - T, Video recording - R, Save Demo - Y")
print("="*80)
print()
# manual control of agent using keyboard
env.run_manual(args)
# close the environment instance
env.close()
def argsparser():
"""
Returns argument parser for furniture assembly environment.
"""
parser = argparse.ArgumentParser("Demo for IKEA Furniture Assembly Environment")
parser.add_argument('--seed', type=int, default=123)
parser.add_argument('--debug', type=str2bool, default=False)
import config.furniture as furniture_config
furniture_config.add_argument(parser)
args = parser.parse_args()
return args
if __name__ == '__main__':
args = argsparser()
main(args)