1
1
"""
2
2
Batch Informed Trees based path planning:
3
- Uses a heuristic to efficiently search increasingly dense
4
- RGGs while reusing previous information. Provides faster
3
+ Uses a heuristic to efficiently search increasingly dense
4
+ RGGs while reusing previous information. Provides faster
5
5
convergence that RRT*, Informed RRT* and other sampling based
6
- methods.
6
+ methods.
7
7
8
- Uses lazy connecting by combining sampling based methods and A*
9
- like incremental graph search algorithms.
8
+ Uses lazy connecting by combining sampling based methods and A*
9
+ like incremental graph search algorithms.
10
10
11
11
author: Karan Chawla(@karanchawla)
12
12
15
15
16
16
import random
17
17
import numpy as np
18
- import copy
19
- import operator
20
18
import math
21
19
import matplotlib .pyplot as plt
22
20
@@ -101,8 +99,7 @@ def gridCoordToRealWorldCoord(self, coord):
101
99
start = self .lowerLimit [i ]
102
100
# step from the coordinate in the grid
103
101
grid_step = self .resolution * coord [i ]
104
- half_step = self .resolution / 2 # To get to middle of the grid
105
- config [i ] = start + grid_step # + half_step
102
+ config [i ] = start + grid_step
106
103
return config
107
104
108
105
def nodeIdToGridCoord (self , node_id ):
@@ -156,8 +153,7 @@ def __init__(self, start, goal,
156
153
self .tree = RTree (start = start , lowerLimit = lowerLimit ,
157
154
upperLimit = upperLimit , resolution = 0.01 )
158
155
159
- def plan (self , animation = True ):
160
-
156
+ def setup_planning (self ):
161
157
self .startId = self .tree .realWorldToNodeId (self .start )
162
158
self .goalId = self .tree .realWorldToNodeId (self .goal )
163
159
@@ -172,12 +168,8 @@ def plan(self, animation=True):
172
168
self .f_scores [self .startId ] = self .computeHeuristicCost (
173
169
self .startId , self .goalId )
174
170
175
- iterations = 0
176
171
# max length we expect to find in our 'informed' sample space, starts as infinite
177
172
cBest = self .g_scores [self .goalId ]
178
- pathLen = float ('inf' )
179
- solutionSet = set ()
180
- plan = []
181
173
182
174
# Computing the sampling space
183
175
cMin = math .sqrt (pow (self .start [0 ] - self .goal [1 ], 2 ) +
@@ -196,6 +188,15 @@ def plan(self, animation=True):
196
188
197
189
self .samples .update (self .informedSample (
198
190
200 , cBest , cMin , xCenter , C ))
191
+
192
+ return etheta , cMin , xCenter , C , cBest
193
+
194
+ def plan (self , animation = True ):
195
+
196
+ etheta , cMin , xCenter , C , cBest = self .setup_planning ()
197
+ iterations = 0
198
+ plan = []
199
+
199
200
foundGoal = False
200
201
# run until done
201
202
while (iterations < self .maxIter ):
@@ -286,20 +287,17 @@ def plan(self, animation=True):
286
287
start = firstCoord , end = secondCoord , tree = self .tree .edges )
287
288
288
289
for edge in self .edge_queue :
289
- if (edge [0 ] == bestEdge [1 ]):
290
- if self .g_scores [edge [0 ]] + self .computeDistanceCost (edge [0 ], bestEdge [1 ]) >= self .g_scores [self .goalId ]:
291
- if (edge [0 ], best_edge [1 ]) in self .edge_queue :
292
- self .edge_queue .remove (
293
- (edge [0 ], bestEdge [1 ]))
294
290
if (edge [1 ] == bestEdge [1 ]):
295
291
if self .g_scores [edge [1 ]] + self .computeDistanceCost (edge [1 ], bestEdge [1 ]) >= self .g_scores [self .goalId ]:
296
292
if (lastEdge , bestEdge [1 ]) in self .edge_queue :
297
293
self .edge_queue .remove (
298
294
(lastEdge , bestEdge [1 ]))
295
+
299
296
else :
300
297
print ("Nothing good" )
301
298
self .edge_queue = []
302
299
self .vertex_queue = []
300
+
303
301
iterations += 1
304
302
305
303
print ("Finding the path" )
@@ -449,6 +447,9 @@ def expandVertex(self, vid):
449
447
self .edge_queue .append ((vid , sid ))
450
448
451
449
# add the vertex to the edge queue
450
+ self .add_vertex_to_edge_queue (vid , currCoord )
451
+
452
+ def add_vertex_to_edge_queue (self , vid , currCoord ):
452
453
if vid not in self .old_vertices :
453
454
neigbors = []
454
455
for v , edges in self .tree .vertices .items ():
@@ -459,7 +460,6 @@ def expandVertex(self, vid):
459
460
460
461
for neighbor in neigbors :
461
462
sid = neighbor [0 ]
462
- scoord = neighbor [1 ]
463
463
estimated_f_score = self .computeDistanceCost (self .startId , vid ) + \
464
464
self .computeDistanceCost (
465
465
vid , sid ) + self .computeHeuristicCost (sid , self .goalId )
@@ -472,8 +472,6 @@ def updateGraph(self):
472
472
currId = self .startId
473
473
openSet .append (currId )
474
474
475
- foundGoal = False
476
-
477
475
while len (openSet ) != 0 :
478
476
# get the element with lowest f_score
479
477
currId = min (openSet , key = lambda x : self .f_scores [x ])
@@ -484,7 +482,6 @@ def updateGraph(self):
484
482
# Check if we're at the goal
485
483
if (currId == self .goalId ):
486
484
self .nodes [self .goalId ]
487
- foundGoal = True
488
485
break
489
486
490
487
if (currId not in closedSet ):
@@ -497,7 +494,6 @@ def updateGraph(self):
497
494
continue
498
495
else :
499
496
# claculate tentative g score
500
- succesorCoord = self .tree .nodeIdToRealWorldCoord (succesor )
501
497
g_score = self .g_scores [currId ] + \
502
498
self .computeDistanceCost (currId , succesor )
503
499
if succesor not in openSet :
@@ -570,7 +566,9 @@ def main():
570
566
bitStar = BITStar (start = [- 1 , 0 ], goal = [3 , 8 ], obstacleList = obstacleList ,
571
567
randArea = [- 2 , 15 ])
572
568
path = bitStar .plan (animation = show_animation )
573
- print (path )
569
+ # print(path)
570
+ print ("Done" )
571
+
574
572
if show_animation :
575
573
plt .plot ([x for (x , y ) in path ], [y for (x , y ) in path ], '-r' )
576
574
plt .grid (True )
0 commit comments