Skip to content

Commit c5f2c5c

Browse files
committed
keep implementing ..
1 parent f80d8d8 commit c5f2c5c

File tree

1 file changed

+84
-20
lines changed

1 file changed

+84
-20
lines changed

PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py

Lines changed: 84 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,18 @@ def mod2pi(x):
5050

5151

5252
def SLS(x, y, phi):
53-
# println(x,",", y,",", phi, ",", mod2pi(phi))
5453
phi = mod2pi(phi)
5554
if y > 0.0 and phi > 0.0 and phi < math.pi * 0.99:
5655
xd = - y / math.tan(phi) + x
5756
t = xd - math.tan(phi / 2.0)
5857
u = phi
5958
v = math.sqrt((x - xd) ** 2 + y ** 2) - math.tan(phi / 2.0)
60-
# println("1,",t,",",u,",",v)
6159
return True, t, u, v
6260
elif y < 0.0 and phi > 0.0 and phi < math.pi * 0.99:
6361
xd = - y / math.tan(phi) + x
6462
t = xd - math.tan(phi / 2.0)
6563
u = phi
66-
v = -math.sqrt((x - xd) ^ 2 + y ^ 2) - math.tan(phi / 2.0)
67-
# println("2,",t,",",u,",",v)
64+
v = -math.sqrt((x - xd) ** 2 + y ** 2) - math.tan(phi / 2.0)
6865
return True, t, u, v
6966

7067
return False, 0.0, 0.0, 0.0
@@ -80,7 +77,7 @@ def set_path(paths, lengths, ctypes):
8077
for tpath in paths:
8178
typeissame = (tpath.ctypes == path.ctypes)
8279
if typeissame:
83-
if sum(tpath.lengths - path.lengths) <= 0.01:
80+
if sum(tpath.lengths) - sum(path.lengths) <= 0.01:
8481
return paths # not insert path
8582

8683
path.L = sum([abs(i) for i in lengths])
@@ -104,6 +101,73 @@ def SCS(x, y, phi, paths):
104101
return paths
105102

106103

104+
def polar(x, y):
105+
r = math.sqrt(x ** 2 + y ** 2)
106+
theta = math.atan2(y, x)
107+
return r, theta
108+
109+
110+
def LSL(x, y, phi):
111+
u, t = polar(x - math.sin(phi), y - 1.0 + math.cos(phi))
112+
if t >= 0.0:
113+
v = mod2pi(phi - t)
114+
if v >= 0.0:
115+
return True, t, u, v
116+
117+
return False, 0.0, 0.0, 0.0
118+
119+
120+
def CSC(x, y, phi, paths):
121+
flag, t, u, v = LSL(x, y, phi)
122+
if flag:
123+
paths = set_path(paths, [t, u, v], ["L", "S", "L"])
124+
125+
flag, t, u, v = LSL(-x, y, -phi)
126+
if flag:
127+
paths = set_path(paths, [-t, -u, -v], ["L", "S", "L"])
128+
129+
flag, t, u, v = LSL(x, -y, -phi)
130+
if flag:
131+
paths = set_path(paths, [t, u, v], ["R", "S", "R"])
132+
133+
flag, t, u, v = LSL(-x, -y, phi)
134+
if flag:
135+
paths = set_path(paths, [-t, -u, -v], ["R", "S", "R"])
136+
137+
flag, t, u, v = LSR(x, y, phi)
138+
if flag:
139+
paths = set_path(paths, [t, u, v], ["L", "S", "R"])
140+
141+
flag, t, u, v = LSR(-x, y, -phi)
142+
if flag:
143+
paths = set_path(paths, [-t, -u, -v], ["L", "S", "R"])
144+
145+
flag, t, u, v = LSR(x, -y, -phi)
146+
if flag:
147+
paths = set_path(paths, [t, u, v], ["R", "S", "L"])
148+
149+
flag, t, u, v = LSR(-x, -y, phi)
150+
if flag:
151+
paths = set_path(paths, [-t, -u, -v], ["R", "S", "L"])
152+
153+
return paths
154+
155+
156+
def LSR(x, y, phi):
157+
u1, t1 = polar(x + math.sin(phi), y - 1.0 - math.cos(phi))
158+
u1 = u1 ** 2
159+
if u1 >= 4.0:
160+
u = math.sqrt(u1 - 4.0)
161+
theta = math.atan2(2.0, u)
162+
t = mod2pi(t1 + theta)
163+
v = mod2pi(t - phi)
164+
165+
if t >= 0.0 and v >= 0.0:
166+
return True, t, u, v
167+
168+
return False, 0.0, 0.0, 0.0
169+
170+
107171
def generate_path(q0, q1, maxc):
108172
dx = q1[0] - q0[0]
109173
dy = q1[1] - q0[1]
@@ -115,14 +179,13 @@ def generate_path(q0, q1, maxc):
115179

116180
paths = []
117181
paths = SCS(x, y, dth, paths)
118-
# paths = CSC(x, y, dth, paths)
182+
paths = CSC(x, y, dth, paths)
119183
# paths = CCC(x, y, dth, paths)
120184

121185
return paths
122186

123187

124188
def interpolate(ind, l, m, maxc, ox, oy, oyaw, px, py, pyaw, directions):
125-
print(ind, len(px), l)
126189

127190
if m == "S":
128191
px[ind] = ox + l / maxc * math.cos(oyaw)
@@ -154,7 +217,6 @@ def interpolate(ind, l, m, maxc, ox, oy, oyaw, px, py, pyaw, directions):
154217

155218
def generate_local_course(L, lengths, mode, maxc, step_size):
156219
npoint = math.trunc(L / step_size) + len(lengths) + 4
157-
# println(npoint, ",", L, ",", step_size, ",", L/step_size)
158220

159221
px = [0.0 for i in range(npoint)]
160222
py = [0.0 for i in range(npoint)]
@@ -251,6 +313,10 @@ def reeds_shepp_path_planning2(sx, sy, syaw,
251313

252314
paths = calc_paths(sx, sy, syaw, gx, gy, gyaw, maxc, step_size)
253315

316+
if len(paths) == 0:
317+
print("No path")
318+
return None, None, None, None, None
319+
254320
minL = float("Inf")
255321
best_path_index = -1
256322
for i in range(len(paths)):
@@ -260,12 +326,7 @@ def reeds_shepp_path_planning2(sx, sy, syaw,
260326

261327
bpath = paths[best_path_index]
262328

263-
xs = bpath.x
264-
ys = bpath.y
265-
yaw = bpath.yaw
266-
ptype = bpath.ctypes
267-
clen = bpath.lengths
268-
return xs, ys, yaw, ptype, clen
329+
return bpath.x, bpath.y, bpath.yaw, bpath.ctypes, bpath.lengths
269330

270331

271332
def reeds_shepp_path_planning(start_x, start_y, start_yaw,
@@ -301,19 +362,22 @@ def main():
301362
print("Reeds Shepp path planner sample start!!")
302363

303364
start_x = 1.0 # [m]
304-
start_y = 1.0 # [m]
305-
start_yaw = math.radians(0.0) # [rad]
365+
start_y = 14.0 # [m]
366+
start_yaw = math.radians(-20.0) # [rad]
306367

307368
end_x = 5.0 # [m]
308-
end_y = 10.0 # [m]
309-
end_yaw = math.radians(45.0) # [rad]
369+
end_y = 5.0 # [m]
370+
end_yaw = math.radians(25.0) # [rad]
310371

311372
curvature = 1.0
312373
step_size = 0.1
313374

314375
px, py, pyaw, mode, clen = reeds_shepp_path_planning2(
315376
start_x, start_y, start_yaw, end_x, end_y, end_yaw, curvature, step_size)
316377

378+
if not px:
379+
assert False, "No path"
380+
317381
# px, py, pyaw, mode, clen = reeds_shepp_path_planning(
318382
# start_x, start_y, start_yaw, end_x, end_y, end_yaw, curvature)
319383

@@ -324,8 +388,8 @@ def main():
324388
plot_arrow(start_x, start_y, start_yaw)
325389
plot_arrow(end_x, end_y, end_yaw)
326390

327-
for (ix, iy, iyaw) in zip(px, py, pyaw):
328-
plot_arrow(ix, iy, iyaw, fc="b")
391+
# for (ix, iy, iyaw) in zip(px, py, pyaw):
392+
# plot_arrow(ix, iy, iyaw, fc="b")
329393
# print(clen)
330394

331395
plt.legend()

0 commit comments

Comments
 (0)