11"""
22
3- Path Plannting with B-Spline
3+ Path Planning with B-Spline
44
55author: Atsushi Sakai (@Atsushi_twi)
66
77"""
88
99import numpy as np
1010import matplotlib .pyplot as plt
11- import scipy .interpolate as si
11+ import scipy .interpolate as scipy_interpolate
1212
13- # parameter
14- N = 3 # B Spline order
1513
16-
17- def bspline_planning (x , y , sn ):
14+ def b_spline_planning (x , y , sn , degree = 3 ):
1815 t = range (len (x ))
19- x_tup = si .splrep (t , x , k = N )
20- y_tup = si .splrep (t , y , k = N )
16+ x_tup = scipy_interpolate .splrep (t , x , k = degree )
17+ y_tup = scipy_interpolate .splrep (t , y , k = degree )
2118
2219 x_list = list (x_tup )
2320 xl = x .tolist ()
@@ -28,23 +25,23 @@ def bspline_planning(x, y, sn):
2825 y_list [1 ] = yl + [0.0 , 0.0 , 0.0 , 0.0 ]
2926
3027 ipl_t = np .linspace (0.0 , len (x ) - 1 , sn )
31- rx = si .splev (ipl_t , x_list )
32- ry = si .splev (ipl_t , y_list )
28+ rx = scipy_interpolate .splev (ipl_t , x_list )
29+ ry = scipy_interpolate .splev (ipl_t , y_list )
3330
3431 return rx , ry
3532
3633
3734def main ():
3835 print (__file__ + " start!!" )
3936 # way points
40- x = np .array ([- 1.0 , 3.0 , 4.0 , 2.0 , 1.0 ])
41- y = np .array ([0.0 , - 3.0 , 1.0 , 1.0 , 3.0 ])
37+ way_x = np .array ([- 1.0 , 3.0 , 4.0 , 2.0 , 1.0 ])
38+ way_y = np .array ([0.0 , - 3.0 , 1.0 , 1.0 , 3.0 ])
4239 sn = 100 # sampling number
4340
44- rx , ry = bspline_planning ( x , y , sn )
41+ rx , ry = b_spline_planning ( way_x , way_y , sn )
4542
4643 # show results
47- plt .plot (x , y , '-og' , label = "Waypoints " )
44+ plt .plot (way_x , way_y , '-og' , label = "way points " )
4845 plt .plot (rx , ry , '-r' , label = "B-Spline path" )
4946 plt .grid (True )
5047 plt .legend ()
0 commit comments