55author Atsushi Sakai(@Atsushi_twi)
66
77"""
8- import reeds_shepp
98import numpy as np
109import math
1110import matplotlib .pyplot as plt
@@ -117,6 +116,62 @@ def LSL(x, y, phi):
117116 return False , 0.0 , 0.0 , 0.0
118117
119118
119+ def LRL (x , y , phi ):
120+ u1 , t1 = polar (x - math .sin (phi ), y - 1.0 + math .cos (phi ))
121+
122+ if u1 <= 4.0 :
123+ u = - 2.0 * math .asin (0.25 * u1 )
124+ t = mod2pi (t1 + 0.5 * u + math .pi )
125+ v = mod2pi (phi - t + u )
126+
127+ if t >= 0.0 and u <= 0.0 :
128+ return True , t , u , v
129+
130+ return False , 0.0 , 0.0 , 0.0
131+
132+
133+ def CCC (x , y , phi , paths ):
134+
135+ flag , t , u , v = LRL (x , y , phi )
136+ if flag :
137+ paths = set_path (paths , [t , u , v ], ["L" , "R" , "L" ])
138+
139+ flag , t , u , v = LRL (- x , y , - phi )
140+ if flag :
141+ paths = set_path (paths , [- t , - u , - v ], ["L" , "R" , "L" ])
142+
143+ flag , t , u , v = LRL (x , - y , - phi )
144+ if flag :
145+ paths = set_path (paths , [t , u , v ], ["R" , "L" , "R" ])
146+
147+ flag , t , u , v = LRL (- x , - y , phi )
148+ if flag :
149+ paths = set_path (paths , [- t , - u , - v ], ["R" , "L" , "R" ])
150+
151+ # backwards
152+ xb = x * math .cos (phi ) + y * math .sin (phi )
153+ yb = x * math .sin (phi ) - y * math .cos (phi )
154+ # println(xb, ",", yb,",",x,",",y)
155+
156+ flag , t , u , v = LRL (xb , yb , phi )
157+ if flag :
158+ paths = set_path (paths , [v , u , t ], ["L" , "R" , "L" ])
159+
160+ flag , t , u , v = LRL (- xb , yb , - phi )
161+ if flag :
162+ paths = set_path (paths , [- v , - u , - t ], ["L" , "R" , "L" ])
163+
164+ flag , t , u , v = LRL (xb , - yb , - phi )
165+ if flag :
166+ paths = set_path (paths , [v , u , t ], ["R" , "L" , "R" ])
167+
168+ flag , t , u , v = LRL (- xb , - yb , phi )
169+ if flag :
170+ paths = set_path (paths , [- v , - u , - t ], ["R" , "L" , "R" ])
171+
172+ return paths
173+
174+
120175def CSC (x , y , phi , paths ):
121176 flag , t , u , v = LSL (x , y , phi )
122177 if flag :
@@ -180,7 +235,7 @@ def generate_path(q0, q1, maxc):
180235 paths = []
181236 paths = SCS (x , y , dth , paths )
182237 paths = CSC (x , y , dth , paths )
183- # paths = CCC(x, y, dth, paths)
238+ paths = CCC (x , y , dth , paths )
184239
185240 return paths
186241
@@ -308,8 +363,8 @@ def calc_paths(sx, sy, syaw, gx, gy, gyaw, maxc, step_size):
308363 return paths
309364
310365
311- def reeds_shepp_path_planning2 (sx , sy , syaw ,
312- gx , gy , gyaw , maxc , step_size ):
366+ def reeds_shepp_path_planning (sx , sy , syaw ,
367+ gx , gy , gyaw , maxc , step_size ):
313368
314369 paths = calc_paths (sx , sy , syaw , gx , gy , gyaw , maxc , step_size )
315370
@@ -329,40 +384,52 @@ def reeds_shepp_path_planning2(sx, sy, syaw,
329384 return bpath .x , bpath .y , bpath .yaw , bpath .ctypes , bpath .lengths
330385
331386
332- def reeds_shepp_path_planning (start_x , start_y , start_yaw ,
333- end_x , end_y , end_yaw , curvature ):
334- step_size = 0.1
335- q0 = [start_x , start_y , start_yaw ]
336- q1 = [end_x , end_y , end_yaw ]
337- qs = reeds_shepp .path_sample (q0 , q1 , 1.0 / curvature , step_size )
338- xs = [q [0 ] for q in qs ]
339- ys = [q [1 ] for q in qs ]
340- yaw = [q [2 ] for q in qs ]
387+ def test ():
388+
389+ NTEST = 100
390+
391+ for i in range (NTEST ):
392+ start_x = (np .random .rand () - 0.5 ) * 100.0 # [m]
393+ start_y = (np .random .rand () - 0.5 ) * 100.0 # [m]
394+ start_yaw = math .radians ((np .random .rand () - 0.5 ) * 180.0 ) # [rad]
395+
396+ end_x = (np .random .rand () - 0.5 ) * 100.0 # [m]
397+ end_y = (np .random .rand () - 0.5 ) * 100.0 # [m]
398+ end_yaw = math .radians ((np .random .rand () - 0.5 ) * 180.0 ) # [rad]
399+
400+ curvature = 1.0 / (np .random .rand () * 20.0 )
401+ # print(curvature)
402+ step_size = 0.1
403+
404+ # print(start_x, start_y, start_yaw)
405+ # print(end_x, end_y, end_yaw)
341406
342- xs .append (end_x )
343- ys .append (end_y )
344- yaw .append (end_yaw )
407+ px , py , pyaw , mode , clen = reeds_shepp_path_planning (
408+ start_x , start_y , start_yaw , end_x , end_y , end_yaw , curvature , step_size )
345409
346- clen = reeds_shepp . path_length ( q0 , q1 , 1.0 / curvature )
347- pathtypeTuple = reeds_shepp . path_type ( q0 , q1 , 1.0 / curvature )
410+ # print(len(px) )
411+ # plt.plot(px, py, label="final course " + str(mode) )
348412
349- ptype = ""
350- for t in pathtypeTuple :
351- if t == 1 :
352- ptype += "L"
353- elif t == 2 :
354- ptype += "S"
355- elif t == 3 :
356- ptype += "R"
413+ # plotting
414+ # plot_arrow(start_x, start_y, start_yaw)
415+ # plot_arrow(end_x, end_y, end_yaw)
416+
417+ # plt.legend()
418+ # plt.grid(True)
419+ # plt.axis("equal")
420+ # plt.show()
421+
422+ if not px :
423+ assert False , "No path"
357424
358- return xs , ys , yaw , ptype , clen
425+ print ( "Test done" )
359426
360427
361428def main ():
362429 print ("Reeds Shepp path planner sample start!!" )
363430
364- start_x = 1.0 # [m]
365- start_y = 14 .0 # [m]
431+ start_x = - 1.0 # [m]
432+ start_y = - 4 .0 # [m]
366433 start_yaw = math .radians (- 20.0 ) # [rad]
367434
368435 end_x = 5.0 # [m]
@@ -372,31 +439,25 @@ def main():
372439 curvature = 1.0
373440 step_size = 0.1
374441
375- px , py , pyaw , mode , clen = reeds_shepp_path_planning2 (
442+ px , py , pyaw , mode , clen = reeds_shepp_path_planning (
376443 start_x , start_y , start_yaw , end_x , end_y , end_yaw , curvature , step_size )
377444
378- if not px :
379- assert False , "No path"
380-
381- # px, py, pyaw, mode, clen = reeds_shepp_path_planning(
382- # start_x, start_y, start_yaw, end_x, end_y, end_yaw, curvature)
383-
384445 if show_animation :
385446 plt .plot (px , py , label = "final course " + str (mode ))
386447
387448 # plotting
388449 plot_arrow (start_x , start_y , start_yaw )
389450 plot_arrow (end_x , end_y , end_yaw )
390451
391- # for (ix, iy, iyaw) in zip(px, py, pyaw):
392- # plot_arrow(ix, iy, iyaw, fc="b")
393- # print(clen)
394-
395452 plt .legend ()
396453 plt .grid (True )
397454 plt .axis ("equal" )
398455 plt .show ()
399456
457+ if not px :
458+ assert False , "No path"
459+
400460
401461if __name__ == '__main__' :
462+ test ()
402463 main ()
0 commit comments