Skip to content

Commit 48c5f60

Browse files
committed
add document
1 parent ffab1f7 commit 48c5f60

File tree

3 files changed

+117
-13
lines changed

3 files changed

+117
-13
lines changed

PathPlanning/RRTstar/figure_1.png

-71.4 KB
Loading

PathPlanning/RRTstar/rrt_star.ipynb

Lines changed: 98 additions & 0 deletions
Large diffs are not rendered by default.

PathPlanning/RRTstar/rrt_star.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class RRT():
2020
"""
2121

2222
def __init__(self, start, goal, obstacleList, randArea,
23-
expandDis=0.5, goalSampleRate=20, maxIter=1000):
23+
expandDis=0.5, goalSampleRate=20, maxIter=500):
2424
"""
2525
Setting Parameter
2626
@@ -60,7 +60,7 @@ def Planning(self, animation=True):
6060
self.nodeList.append(newNode)
6161
self.rewire(newNode, nearinds)
6262

63-
if animation:
63+
if animation and i % 5 == 0:
6464
self.DrawGraph(rnd)
6565

6666
# generate coruse
@@ -103,14 +103,15 @@ def steer(self, rnd, nind):
103103
nearestNode = self.nodeList[nind]
104104
theta = math.atan2(rnd[1] - nearestNode.y, rnd[0] - nearestNode.x)
105105
newNode = Node(rnd[0], rnd[1])
106-
currentDistance = math.sqrt( (rnd[1] - nearestNode.y) ** 2 + (rnd[0] - nearestNode.x) ** 2)
106+
currentDistance = math.sqrt(
107+
(rnd[1] - nearestNode.y) ** 2 + (rnd[0] - nearestNode.x) ** 2)
107108
# Find a point within expandDis of nind, and closest to rnd
108109
if currentDistance <= self.expandDis:
109110
pass
110111
else:
111112
newNode.x = nearestNode.x + self.expandDis * math.cos(theta)
112113
newNode.y = nearestNode.y + self.expandDis * math.sin(theta)
113-
newNode.cost = float("inf")
114+
newNode.cost = float("inf")
114115
newNode.parent = None
115116
return newNode
116117

@@ -192,7 +193,7 @@ def check_collision_extend(self, nearNode, theta, d):
192193
return True
193194

194195
def DrawGraph(self, rnd=None):
195-
u"""
196+
"""
196197
Draw Graph
197198
"""
198199
plt.clf()
@@ -256,17 +257,22 @@ def main():
256257
] # [x,y,size(radius)]
257258

258259
# Set Initial parameters
259-
rrt = RRT(start=[0, 0], goal=[5, 10],
260+
rrt = RRT(start=[0, 0], goal=[10, 10],
260261
randArea=[-2, 15], obstacleList=obstacleList)
261262
path = rrt.Planning(animation=show_animation)
262263

263-
# Draw final path
264-
if show_animation:
265-
rrt.DrawGraph()
266-
plt.plot([x for (x, y) in path], [y for (x, y) in path], '-r')
267-
plt.grid(True)
268-
plt.pause(0.01) # Need for Mac
269-
plt.show()
264+
if path is None:
265+
print("Cannot find path")
266+
else:
267+
print("found path!!")
268+
269+
# Draw final path
270+
if show_animation:
271+
rrt.DrawGraph()
272+
plt.plot([x for (x, y) in path], [y for (x, y) in path], '-r')
273+
plt.grid(True)
274+
plt.pause(0.01) # Need for Mac
275+
plt.show()
270276

271277

272278
if __name__ == '__main__':

0 commit comments

Comments
 (0)