Skip to content

Commit ebeb3d9

Browse files
committed
code clean up
1 parent 6bd4942 commit ebeb3d9

File tree

4 files changed

+32
-103
lines changed

4 files changed

+32
-103
lines changed

PathPlanning/RRTStarReedsShepp/matplotrecorder.py

Lines changed: 0 additions & 59 deletions
This file was deleted.

PathPlanning/RRTStarReedsShepp/reeds_shepp_path_planning.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
#! /usr/bin/python
2-
# -*- coding: utf-8 -*-
31
"""
42
53
Reeds Shepp path planner sample code
64
75
author Atsushi Sakai(@Atsushi_twi)
86
9-
License MIT
10-
117
"""
128
import reeds_shepp
139
import math
10+
import matplotlib.pyplot as plt
1411

1512

1613
def plot_arrow(x, y, yaw, length=1.0, width=0.5, fc="r", ec="k"):
17-
u"""
14+
"""
1815
Plot arrow
1916
"""
20-
import matplotlib.pyplot as plt
2117

2218
if not isinstance(x, float):
2319
for (ix, iy, iyaw) in zip(x, y, yaw):
@@ -57,9 +53,8 @@ def reeds_shepp_path_planning(start_x, start_y, start_yaw,
5753
return xs, ys, yaw, ptype, clen
5854

5955

60-
if __name__ == '__main__':
56+
def main():
6157
print("Reeds Shepp path planner sample start!!")
62-
import matplotlib.pyplot as plt
6358

6459
start_x = 1.0 # [m]
6560
start_y = 1.0 # [m]
@@ -88,3 +83,7 @@ def reeds_shepp_path_planning(start_x, start_y, start_yaw,
8883
plt.grid(True)
8984
plt.axis("equal")
9085
plt.show()
86+
87+
88+
if __name__ == '__main__':
89+
main()

PathPlanning/RRTStarReedsShepp/rrt_star_car.py renamed to PathPlanning/RRTStarReedsShepp/rrt_star_reeds_shepp.py

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
#!/usr/bin/python
2-
# -*- coding: utf-8 -*-
31
"""
4-
@brief: Path Planning Sample Code with RRT for car like robot.
52
6-
@author: AtsushiSakai(@Atsushi_twi)
3+
Path Planning Sample Code with RRT for car like robot.
74
8-
@license: MIT
5+
author: AtsushiSakai(@Atsushi_twi)
96
107
"""
118

@@ -14,16 +11,19 @@
1411
import copy
1512
import numpy as np
1613
import reeds_shepp_path_planning
14+
import matplotlib.pyplot as plt
15+
16+
show_animation = True
1717

1818

1919
class RRT():
20-
u"""
20+
"""
2121
Class for RRT Planning
2222
"""
2323

2424
def __init__(self, start, goal, obstacleList, randArea,
25-
goalSampleRate=10, maxIter=1000):
26-
u"""
25+
goalSampleRate=10, maxIter=200):
26+
"""
2727
Setting Parameter
2828
2929
start:Start Position [x,y]
@@ -38,36 +38,33 @@ def __init__(self, start, goal, obstacleList, randArea,
3838
self.maxrand = randArea[1]
3939
self.goalSampleRate = goalSampleRate
4040
self.maxIter = maxIter
41+
self.obstacleList = obstacleList
4142

4243
def Planning(self, animation=True):
43-
u"""
44+
"""
4445
Pathplanning
4546
4647
animation: flag for animation on or off
4748
"""
4849

4950
self.nodeList = [self.start]
5051
for i in range(self.maxIter):
51-
print(i)
5252
rnd = self.get_random_point()
5353
nind = self.GetNearestListIndex(self.nodeList, rnd)
5454

5555
newNode = self.steer(rnd, nind)
56-
# print(newNode.cost)
5756

58-
if self.CollisionCheck(newNode, obstacleList):
57+
if self.CollisionCheck(newNode, self.obstacleList):
5958
nearinds = self.find_near_nodes(newNode)
6059
newNode = self.choose_parent(newNode, nearinds)
6160
self.nodeList.append(newNode)
6261
self.rewire(newNode, nearinds)
6362

6463
if animation and i % 5 == 0:
6564
self.DrawGraph(rnd=rnd)
66-
matplotrecorder.save_frame() # save each frame
6765

6866
# generate coruse
6967
lastIndex = self.get_best_last_index()
70-
# print(lastIndex)
7168
path = self.gen_final_course(lastIndex)
7269
return path
7370

@@ -78,7 +75,7 @@ def choose_parent(self, newNode, nearinds):
7875
dlist = []
7976
for i in nearinds:
8077
tNode = self.steer(newNode, i)
81-
if self.CollisionCheck(tNode, obstacleList):
78+
if self.CollisionCheck(tNode, self.obstacleList):
8279
dlist.append(tNode.cost)
8380
else:
8481
dlist.append(float("inf"))
@@ -104,7 +101,6 @@ def pi_2_pi(self, angle):
104101
return angle
105102

106103
def steer(self, rnd, nind):
107-
# print(rnd)
108104
curvature = 1.0
109105

110106
nearestNode = self.nodeList[nind]
@@ -149,16 +145,16 @@ def get_best_last_index(self):
149145
for (i, node) in enumerate(self.nodeList):
150146
if self.calc_dist_to_goal(node.x, node.y) <= XYTH:
151147
goalinds.append(i)
152-
print("OK XY TH num is")
153-
print(len(goalinds))
148+
# print("OK XY TH num is")
149+
# print(len(goalinds))
154150

155151
# angle check
156152
fgoalinds = []
157153
for i in goalinds:
158154
if abs(self.nodeList[i].yaw - self.end.yaw) <= YAWTH:
159155
fgoalinds.append(i)
160-
print("OK YAW TH num is")
161-
print(len(fgoalinds))
156+
# print("OK YAW TH num is")
157+
# print(len(fgoalinds))
162158

163159
mincost = min([self.nodeList[i].cost for i in fgoalinds])
164160
for i in fgoalinds:
@@ -200,18 +196,17 @@ def rewire(self, newNode, nearinds):
200196
nearNode = self.nodeList[i]
201197
tNode = self.steer(nearNode, nnode - 1)
202198

203-
obstacleOK = self.CollisionCheck(tNode, obstacleList)
199+
obstacleOK = self.CollisionCheck(tNode, self.obstacleList)
204200
imporveCost = nearNode.cost > tNode.cost
205201

206202
if obstacleOK and imporveCost:
207203
# print("rewire")
208204
self.nodeList[i] = tNode
209205

210206
def DrawGraph(self, rnd=None):
211-
u"""
207+
"""
212208
Draw Graph
213209
"""
214-
import matplotlib.pyplot as plt
215210
plt.clf()
216211
if rnd is not None:
217212
plt.plot(rnd.x, rnd.y, "^k")
@@ -221,7 +216,7 @@ def DrawGraph(self, rnd=None):
221216
# plt.plot([node.x, self.nodeList[node.parent].x], [
222217
# node.y, self.nodeList[node.parent].y], "-g")
223218

224-
for (ox, oy, size) in obstacleList:
219+
for (ox, oy, size) in self.obstacleList:
225220
plt.plot(ox, oy, "ok", ms=30 * size)
226221

227222
reeds_shepp_path_planning.plot_arrow(
@@ -258,7 +253,7 @@ def CollisionCheck(self, node, obstacleList):
258253

259254

260255
class Node():
261-
u"""
256+
"""
262257
RRT Node
263258
"""
264259

@@ -273,11 +268,8 @@ def __init__(self, x, y, yaw):
273268
self.parent = None
274269

275270

276-
if __name__ == '__main__':
271+
def main():
277272
print("Start rrt start planning")
278-
import matplotlib.pyplot as plt
279-
import matplotrecorder
280-
matplotrecorder.donothing = True
281273

282274
# ====Search Path with RRT====
283275
# obstacleList = [
@@ -305,17 +297,15 @@ def __init__(self, x, y, yaw):
305297
goal = [6.0, 7.0, math.radians(90.0)]
306298

307299
rrt = RRT(start, goal, randArea=[-2.0, 15.0], obstacleList=obstacleList)
308-
path = rrt.Planning(animation=False)
300+
path = rrt.Planning(animation=show_animation)
309301

310302
# Draw final path
311303
rrt.DrawGraph()
312304
plt.plot([x for (x, y) in path], [y for (x, y) in path], '-r')
313305
plt.grid(True)
314306
plt.pause(0.001)
315-
316-
for i in range(10):
317-
matplotrecorder.save_frame() # save each frame
318-
319307
plt.show()
320308

321-
# matplotrecorder.save_movie("animation.gif", 0.1)
309+
310+
if __name__ == '__main__':
311+
main()

PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#! /usr/bin/python
21
"""
32
43
Reeds Shepp path planner sample code

0 commit comments

Comments
 (0)