Skip to content

Commit 7f40e1d

Browse files
committed
add test codes
1 parent 19e4371 commit 7f40e1d

File tree

5 files changed

+59
-36
lines changed

5 files changed

+59
-36
lines changed

PathPlanning/RRTStarReedsShepp/reeds_shepp_path_planning.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import math
1010
import matplotlib.pyplot as plt
1111

12+
show_animation = True
13+
1214

1315
def plot_arrow(x, y, yaw, length=1.0, width=0.5, fc="r", ec="k"):
1416
"""
@@ -69,20 +71,21 @@ def main():
6971
px, py, pyaw, mode, clen = reeds_shepp_path_planning(
7072
start_x, start_y, start_yaw, end_x, end_y, end_yaw, curvature)
7173

72-
plt.plot(px, py, label="final course " + str(mode))
74+
if show_animation:
75+
plt.plot(px, py, label="final course " + str(mode))
7376

74-
# plotting
75-
plot_arrow(start_x, start_y, start_yaw)
76-
plot_arrow(end_x, end_y, end_yaw)
77+
# plotting
78+
plot_arrow(start_x, start_y, start_yaw)
79+
plot_arrow(end_x, end_y, end_yaw)
7780

78-
for (ix, iy, iyaw) in zip(px, py, pyaw):
79-
plot_arrow(ix, iy, iyaw, fc="b")
80-
# print(clen)
81+
for (ix, iy, iyaw) in zip(px, py, pyaw):
82+
plot_arrow(ix, iy, iyaw, fc="b")
83+
# print(clen)
8184

82-
plt.legend()
83-
plt.grid(True)
84-
plt.axis("equal")
85-
plt.show()
85+
plt.legend()
86+
plt.grid(True)
87+
plt.axis("equal")
88+
plt.show()
8689

8790

8891
if __name__ == '__main__':

PathPlanning/RRTStarReedsShepp/rrt_star_reeds_shepp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class RRT():
2222
"""
2323

2424
def __init__(self, start, goal, obstacleList, randArea,
25-
goalSampleRate=10, maxIter=200):
25+
goalSampleRate=10, maxIter=400):
2626
"""
2727
Setting Parameter
2828

PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
55
author Atsushi Sakai(@Atsushi_twi)
66
7-
License MIT
8-
97
"""
108
import reeds_shepp
119
import math
10+
import matplotlib.pyplot as plt
11+
12+
show_animation = True
1213

1314

1415
def plot_arrow(x, y, yaw, length=1.0, width=0.5, fc="r", ec="k"):
15-
u"""
16+
"""
1617
Plot arrow
1718
"""
18-
import matplotlib.pyplot as plt
1919

2020
if not isinstance(x, float):
2121
for (ix, iy, iyaw) in zip(x, y, yaw):
@@ -28,10 +28,10 @@ def plot_arrow(x, y, yaw, length=1.0, width=0.5, fc="r", ec="k"):
2828

2929
def reeds_shepp_path_planning(start_x, start_y, start_yaw,
3030
end_x, end_y, end_yaw, curvature):
31+
step_size = 0.1
3132
q0 = [start_x, start_y, start_yaw]
3233
q1 = [end_x, end_y, end_yaw]
33-
step_size = 0.1
34-
qs = reeds_shepp.path_sample(q0, q1, curvature, step_size)
34+
qs = reeds_shepp.path_sample(q0, q1, 1.0 / curvature, step_size)
3535
xs = [q[0] for q in qs]
3636
ys = [q[1] for q in qs]
3737
yaw = [q[2] for q in qs]
@@ -40,8 +40,8 @@ def reeds_shepp_path_planning(start_x, start_y, start_yaw,
4040
ys.append(end_y)
4141
yaw.append(end_yaw)
4242

43-
clen = reeds_shepp.path_length(q0, q1, curvature)
44-
pathtypeTuple = reeds_shepp.path_type(q0, q1, curvature)
43+
clen = reeds_shepp.path_length(q0, q1, 1.0 / curvature)
44+
pathtypeTuple = reeds_shepp.path_type(q0, q1, 1.0 / curvature)
4545

4646
ptype = ""
4747
for t in pathtypeTuple:
@@ -55,13 +55,12 @@ def reeds_shepp_path_planning(start_x, start_y, start_yaw,
5555
return xs, ys, yaw, ptype, clen
5656

5757

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

62-
start_x = 10.0 # [m]
61+
start_x = 1.0 # [m]
6362
start_y = 1.0 # [m]
64-
start_yaw = math.radians(180.0) # [rad]
63+
start_yaw = math.radians(0.0) # [rad]
6564

6665
end_x = -0.0 # [m]
6766
end_y = -3.0 # [m]
@@ -72,17 +71,22 @@ def reeds_shepp_path_planning(start_x, start_y, start_yaw,
7271
px, py, pyaw, mode, clen = reeds_shepp_path_planning(
7372
start_x, start_y, start_yaw, end_x, end_y, end_yaw, curvature)
7473

75-
plt.plot(px, py, label="final course " + str(mode))
74+
if show_animation:
75+
plt.plot(px, py, label="final course " + str(mode))
76+
77+
# plotting
78+
plot_arrow(start_x, start_y, start_yaw)
79+
plot_arrow(end_x, end_y, end_yaw)
7680

77-
# plotting
78-
plot_arrow(start_x, start_y, start_yaw)
79-
plot_arrow(end_x, end_y, end_yaw)
81+
for (ix, iy, iyaw) in zip(px, py, pyaw):
82+
plot_arrow(ix, iy, iyaw, fc="b")
83+
# print(clen)
8084

81-
# for (ix, iy, iyaw) in zip(px, py, pyaw):
82-
# plot_arrow(ix, iy, iyaw, fc="b")
83-
# print(clen)
85+
plt.legend()
86+
plt.grid(True)
87+
plt.axis("equal")
88+
plt.show()
8489

85-
plt.legend()
86-
plt.grid(True)
87-
plt.axis("equal")
88-
plt.show()
90+
91+
if __name__ == '__main__':
92+
main()

tests/test_reeds_shepp_path_planning.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
class Test(TestCase):
66

77
def test1(self):
8-
pass
8+
m.show_animation = False
9+
m.main()

tests/test_rrt_star_reeds_shepp.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from unittest import TestCase
2+
3+
import sys
4+
sys.path.append("./PathPlanning/RRTStarReedsShepp/")
5+
6+
from PathPlanning.RRTStarReedsShepp import rrt_star_reeds_shepp as m
7+
8+
print(__file__)
9+
10+
11+
class Test(TestCase):
12+
13+
def test1(self):
14+
m.show_animation = False
15+
m.main()

0 commit comments

Comments
 (0)