-
Notifications
You must be signed in to change notification settings - Fork 2
/
execute_plan.py
47 lines (39 loc) · 1.45 KB
/
execute_plan.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
import argparse
from simtools.rosutils import RosNode
parser = argparse.ArgumentParser("Parse plan.")
parser.add_argument("-p", help="plan file", type=str, required=True)
parser.add_argument("-uri", help="master uri. optional", type=str, default="http://localhost:11311")
args = parser.parse_args()
node = RosNode("execute_plan", args.uri, wait_time=2.5)
file = open(args.p, "r")
lines = file.readlines()
N = int(lines[0])
objNames = []
objLocs = []
objSizes = []
for i in range(N):
name, x, y, size = lines[i+1].split()
objNames.append(name)
objLocs.append([float(x), float(y)])
objSizes.append(float(size))
print("Plan success probability: %.2f" % float(lines[N+1].split(":")[1]))
if lines[N+1] == "not found.":
print("Cannot find a plan which satisfies the objective.")
exit()
base_level = 0.7
for p in lines[N+2:]:
node.initArmPose()
_, base, target = p.split()
base_idx = objNames.index(base)
target_idx = objNames.index(target)
base_loc = objLocs[base_idx]
target_loc = objLocs[target_idx]
node.move(target_loc+[1.0, 0., 0., 0., 1.])
node.move(target_loc+[0.7+0.85*objSizes[target_idx], 0., 0., 0., 1.])
node.handGraspPose()
base_level += objSizes[base_idx]
node.move(target_loc+[base_level+objSizes[target_idx]+0.05, 0., 0., 0., 1.])
node.move(base_loc+[base_level+objSizes[target_idx]+0.05, 0., 0., 0., 1.])
node.handOpenPose()
objLocs[target_idx] = objLocs[base_idx]
node.initArmPose()