13
13
import math
14
14
import matplotlib .pyplot as plt
15
15
16
- show_animation = False
16
+ show_animation = True
17
17
18
18
19
19
class RTree (object ):
@@ -131,8 +131,8 @@ def __init__(self, start, goal,
131
131
self .start = start
132
132
self .goal = goal
133
133
134
- self .minrand = randArea [0 ]
135
- self .maxrand = randArea [1 ]
134
+ self .minrand = randArea [0 ]
135
+ self .maxrand = randArea [1 ]
136
136
self .expandDis = expandDis
137
137
self .goalSampleRate = goalSampleRate
138
138
self .maxIter = maxIter
@@ -158,7 +158,9 @@ def __init__(self, start, goal,
158
158
def plan (self , animation = True ):
159
159
160
160
self .startId = self .tree .realWorldToNodeId (self .start )
161
+ print ("startId: " , self .startId )
161
162
self .goalId = self .tree .realWorldToNodeId (self .goal )
163
+ print ("goalId: " , self .goalId )
162
164
163
165
# add goal to the samples
164
166
self .samples [self .goalId ] = self .goal
@@ -193,13 +195,15 @@ def plan(self, animation=True):
193
195
C = np .dot (np .dot (U , np .diag (
194
196
[1.0 , 1.0 , np .linalg .det (U ) * np .linalg .det (np .transpose (Vh ))])), Vh )
195
197
198
+ self .samples .update (self .informedSample (
199
+ 200 , cBest , cMin , xCenter , C ))
196
200
foundGoal = False
197
201
# run until done
198
202
while (iterations < self .maxIter ):
199
203
if len (self .vertex_queue ) == 0 and len (self .edge_queue ) == 0 :
200
204
# Using informed rrt star way of computing the samples
201
205
self .samples .update (self .informedSample (
202
- 200 , cBest , cMin , xCenter , C ))
206
+ 50 , cBest , cMin , xCenter , C ))
203
207
# prune the tree
204
208
self .r = 2.0
205
209
if iterations != 0 :
@@ -266,11 +270,10 @@ def plan(self, animation=True):
266
270
self .updateGraph ()
267
271
268
272
# visualize new edge
269
-
270
273
if animation :
271
- self .drawGraph (xCenter = xCenter , cBest = cBest ,
272
- cMin = cMin , etheta = etheta , samples = self .samples .values (),
273
- start = firstCoord , end = secondCoord , plan = plan )
274
+ self .drawGraph (xCenter = xCenter , cBest = cBest ,
275
+ cMin = cMin , etheta = etheta , samples = self .samples .values (),
276
+ start = firstCoord , end = secondCoord , tree = self . nodes )
274
277
275
278
for edge in self .edge_queue :
276
279
if (edge [0 ] == bestEdge [1 ]):
@@ -280,7 +283,7 @@ def plan(self, animation=True):
280
283
(edge [0 ], bestEdge [1 ]))
281
284
if (edge [1 ] == bestEdge [1 ]):
282
285
if self .g_scores [edge [1 ]] + self .computeDistanceCost (edge [1 ], bestEdge [1 ]) >= self .g_scores [self .goalId ]:
283
- if (edge [1 ], best_edge [1 ]) in self .edge_queue :
286
+ if (edge [1 ], bestEdge [1 ]) in self .edge_queue :
284
287
self .edge_queue .remove (
285
288
(edge [1 ], bestEdge [1 ]))
286
289
else :
@@ -409,7 +412,7 @@ def bestInVertexQueue(self):
409
412
v_plus_vals = [(v , self .g_scores [v ] + self .computeHeuristicCost (v , self .goalId ))
410
413
for v in self .vertex_queue ]
411
414
v_plus_vals = sorted (v_plus_vals , key = lambda x : x [1 ])
412
-
415
+ # print(v_plus_vals)
413
416
return v_plus_vals [0 ][0 ]
414
417
415
418
def bestInEdgeQueue (self ):
@@ -510,8 +513,8 @@ def updateGraph(self):
510
513
# store the parent and child
511
514
self .nodes [succesor ] = currId
512
515
513
- def drawGraph (self , xCenter = None , cBest = None , cMin = None , etheta = None ,
514
- samples = None , start = None , end = None , plan = None ):
516
+ def drawGraph (self , xCenter = None , cBest = None , cMin = None , etheta = None ,
517
+ samples = None , start = None , end = None , tree = None ):
515
518
print ("Plotting Graph" )
516
519
plt .clf ()
517
520
for rnd in samples :
@@ -521,13 +524,13 @@ def drawGraph(self, xCenter=None, cBest=None, cMin=None, etheta=None,
521
524
self .plot_ellipse (xCenter , cBest , cMin , etheta )
522
525
523
526
if start is not None and end is not None :
524
- plt .plot ([start [0 ], start [1 ]], [end [0 ], end [1 ]], "-g" )
527
+ plt .plot ([start [0 ], start [1 ]], [end [0 ], end [1 ]], "-g" )
525
528
526
- # for node in self.nodeList :
527
- # if node.parent is not None :
528
- # if node.x or node.y is not None:
529
- # plt.plot([node.x, self.nodeList[node.parent].x], [
530
- # node.y, self.nodeList[node.parent].y] , "-g ")
529
+ if tree is not None and len ( tree ) != 0 :
530
+ for key , value in tree . items () :
531
+ keyCoord = self . tree . nodeIdToRealWorldCoord ( key )
532
+ valueCoord = self .tree . nodeIdToRealWorldCoord ( value )
533
+ plt . plot ( keyCoord , valueCoord , "-r " )
531
534
532
535
for (ox , oy , size ) in self .obstacleList :
533
536
plt .plot (ox , oy , "ok" , ms = 30 * size )
@@ -570,7 +573,7 @@ def main():
570
573
]
571
574
572
575
bitStar = BITStar (start = [0 , 0 ], goal = [2 , 4 ], obstacleList = obstacleList ,
573
- randArea = [- 2 , 15 ])
576
+ randArea = [0 , 15 ])
574
577
path = bitStar .plan (animation = show_animation )
575
578
print ("Done" )
576
579
0 commit comments