-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPRMGenerator.py
executable file
·79 lines (53 loc) · 2.19 KB
/
PRMGenerator.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
import Franka
import numpy as np
import random
import pickle
import RobotUtil as rt
import time
random.seed(13)
#Initialize robot object
mybot=Franka.FrankArm()
#Create environment obstacles - # these are blocks in the environment/scene (not part of robot)
pointsObs=[]
axesObs=[]
envpoints, envaxes = rt.BlockDesc2Points(rt.rpyxyz2H([0,0.,0.],[0.1,0,1.0]),[1.3,1.4,0.1])
pointsObs.append(envpoints), axesObs.append(envaxes)
envpoints, envaxes = rt.BlockDesc2Points(rt.rpyxyz2H([0,0.,0.],[0.1,-0.65,0.475]),[1.3,0.1,0.95])
pointsObs.append(envpoints), axesObs.append(envaxes)
envpoints, envaxes = rt.BlockDesc2Points(rt.rpyxyz2H([0,0.,0.],[0.1, 0.65,0.475]),[1.3,0.1,0.95])
pointsObs.append(envpoints), axesObs.append(envaxes)
envpoints, envaxes = rt.BlockDesc2Points(rt.rpyxyz2H([0,0.,0.],[-0.5, 0, 0.475]),[0.1,1.2,0.95])
pointsObs.append(envpoints), axesObs.append(envaxes)
# Central block ahead of the robot
envpoints, envaxes = rt.BlockDesc2Points(rt.rpyxyz2H([0,0.,0.],[0.45, 0, 0.25]),[0.5,0.4,0.5])
pointsObs.append(envpoints), axesObs.append(envaxes)
#TODO: Create PRM - generate collision-free vertices
prmVertices=[]
prmEdges=[]
start = time.time()
#TODO: Fill in the following function using prmVertices and prmEdges to store
# the graph. The code at the end saves the graph into a python pickle file.
def PRMGenerator():
while len(prmVertices)<1000:
# sample random poses
q = mybot.SampleRobotConfig()
if not mybot.DetectCollision(q, pointsObs, axesObs):
prmVertices.append(q)
prmEdges.append([])
for j in range(len(prmVertices)-1):
if np.linalg.norm(np.array(prmVertices[-1]) - np.array(prmVertices[j])) < 2.:
if not mybot.DetectCollisionEdge(prmVertices[-1], prmVertices[j], pointsObs, axesObs):
prmEdges[-1].append(j)
prmEdges[j].append(len(prmVertices)-1)
print(len(prmVertices))
#Save the PRM such that it can be run by PRMQuery.py
f = open("myPRM.p", 'wb')
pickle.dump(prmVertices, f)
pickle.dump(prmEdges, f)
pickle.dump(pointsObs, f)
pickle.dump(axesObs, f)
f.close
if __name__ == "__main__":
# Call the PRM Generator function and generate a graph
PRMGenerator()
print("\n", "Vertices: ", len(prmVertices),", Time Taken: ", time.time()-start)