1
1
"""
2
2
3
- Path Plannting with B-Spline
3
+ Path Planning with B-Spline
4
4
5
5
author: Atsushi Sakai (@Atsushi_twi)
6
6
7
7
"""
8
8
9
9
import numpy as np
10
10
import matplotlib .pyplot as plt
11
- import scipy .interpolate as si
11
+ import scipy .interpolate as scipy_interpolate
12
12
13
- # parameter
14
- N = 3 # B Spline order
15
13
16
-
17
- def bspline_planning (x , y , sn ):
14
+ def b_spline_planning (x , y , sn , degree = 3 ):
18
15
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 )
21
18
22
19
x_list = list (x_tup )
23
20
xl = x .tolist ()
@@ -28,23 +25,23 @@ def bspline_planning(x, y, sn):
28
25
y_list [1 ] = yl + [0.0 , 0.0 , 0.0 , 0.0 ]
29
26
30
27
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 )
33
30
34
31
return rx , ry
35
32
36
33
37
34
def main ():
38
35
print (__file__ + " start!!" )
39
36
# 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 ])
42
39
sn = 100 # sampling number
43
40
44
- rx , ry = bspline_planning ( x , y , sn )
41
+ rx , ry = b_spline_planning ( way_x , way_y , sn )
45
42
46
43
# show results
47
- plt .plot (x , y , '-og' , label = "Waypoints " )
44
+ plt .plot (way_x , way_y , '-og' , label = "way points " )
48
45
plt .plot (rx , ry , '-r' , label = "B-Spline path" )
49
46
plt .grid (True )
50
47
plt .legend ()
0 commit comments