-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_planner.py
177 lines (151 loc) · 4.63 KB
/
run_planner.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import argparse
from pybullet_planning.pybullet_tools.utils import wait_if_gui, draw_aabb
from planners.snowplow import Snowplow
from planners.a_star_search import AStarSearch
from planners.rrt import RRT
from planners.vamp import Vamp
from planners.lamb import Lamb
from planners.namo import Namo
from planners.rotate import Rotate
from planners.do_nothing import DoNothing
from environments.empty import Empty
from environments.complex import Complex
from environments.simple_navigation import SimpleNavigation
from environments.attach_obstructed import AttObs
from environments.subgoal_obstructed import SubObs
from environments.simple_namo import SimpleNamo
from environments.simple_vision import SimpleVision
from environments.real_world import RealWorld
import pickle
from datetime import datetime
import os
import time
import random
import numpy as np
PLANNERS = {"snowplow": Snowplow,
"a_star": AStarSearch,
"namo": Namo,
"rrt": RRT,
"vamp": Vamp,
"lamb": Lamb,
"do_nothing": DoNothing,
"rotate": Rotate}
ENVIRONMENTS = {"empty": Empty,
"complex": Complex,
"simple_navigation": SimpleNavigation,
"attachment_obstructed": AttObs,
"subgoal_obstructed": SubObs,
"simple_namo": SimpleNamo,
"simple_vision": SimpleVision,
"real_world": RealWorld}
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"-a",
"--algo",
default="rrt",
type=str,
help="Planning algorithm to run",
choices=list(PLANNERS.keys())
)
parser.add_argument(
"-e",
"--env",
type=str,
default="single_movable",
help="Environment to run the planner in",
choices=list(ENVIRONMENTS.keys())
)
parser.add_argument(
"-v",
"--vis",
action="store_true"
)
parser.add_argument(
"-ov",
"--only_validate",
type=str,
default=None,
help="Filename of the plan to run validation on"
)
parser.add_argument(
"-l",
"--load",
type=str,
default=None,
help="Data file indicating saved state"
)
parser.add_argument(
"-s",
"--save_dir",
type=str,
default="./results",
help="Place to save statistics"
)
parser.add_argument(
"-d",
"--debug",
action="store_true",
help="Whether to enter in debugging mode"
)
parser.add_argument(
"-seed",
"--seed",
type=int,
default=0,
help="seed"
)
parser.add_argument(
"-f_p",
"--from_plan",
type=str,
default=None,
help="Filename of the file to restart planning from"
)
args = parser.parse_args()
return args
def write_results(args, statistics, save_dir):
fn = "algo={}_env={}_seed={}.pkl".format(args.algo, args.env, args.seed)
results_fn = os.path.join(save_dir, fn)
with open(results_fn, 'wb') as handle:
pickle.dump(statistics, handle, protocol=pickle.HIGHEST_PROTOCOL)
if __name__=="__main__":
args = get_args()
print("=================")
print(args)
random.seed(args.seed)
np.random.seed(args.seed)
env = ENVIRONMENTS[args.env](vis=args.vis, debug=args.debug, save_dir = args.save_dir)
planner = PLANNERS[args.algo](env)
start_time = time.time()
from_plan = None
if args.from_plan is not None:
with open(args.from_plan, 'rb') as handle:
data = pickle.load(handle)
from_plan = data["plan"]
print(from_plan)
if(args.only_validate is None):
plan = planner.get_plan(loadfile=args.load, debug=args.debug, from_plan=from_plan)
else:
with open(args.only_validate, 'rb') as handle:
data = pickle.load(handle)
plan = data["plan"]
plan_time = time.time()-start_time
print(plan)
# wait_if_gui()
statistics = env.validate_plan(plan)
print(statistics)
if(args.vis):
for q, att in statistics[1]:
draw_aabb(env.aabb_from_q(q))
if att is not None:
draw_aabb(env.movable_object_oobb_from_q(att[0], q, att[1]).aabb)
env.move_robot(q, env.joints, att)
# wait_if_gui()
# wait_if_gui()
results_dict = {"success": statistics[0],
"collisions":len(statistics[1]),
"plan": plan,
"plan_time":plan_time}
write_results(args, results_dict, args.save_dir)
time.sleep(5)