Skip to content

Commit fb4fe86

Browse files
committed
add bsplinepath sample
1 parent c377846 commit fb4fe86

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

PathPlanning/BSplinePath/Figure_1.png

22.3 KB
Loading
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""
2+
3+
Path Plannting with B-Spline
4+
5+
author: Atsushi Sakai (@Atsushi_twi)
6+
7+
"""
8+
9+
import numpy as np
10+
import matplotlib.pyplot as plt
11+
import scipy.interpolate as si
12+
13+
# parameter
14+
N = 3 # B Spline order
15+
16+
17+
def bspline_planning(x, y, sn):
18+
t = range(len(x))
19+
x_tup = si.splrep(t, x, k=N)
20+
y_tup = si.splrep(t, y, k=N)
21+
22+
x_list = list(x_tup)
23+
xl = x.tolist()
24+
x_list[1] = xl + [0.0, 0.0, 0.0, 0.0]
25+
26+
y_list = list(y_tup)
27+
yl = y.tolist()
28+
y_list[1] = yl + [0.0, 0.0, 0.0, 0.0]
29+
30+
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)
33+
34+
return rx, ry
35+
36+
37+
def main():
38+
print(__file__ + " start!!")
39+
# 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])
42+
sn = 100 # sampling number
43+
44+
rx, ry = bspline_planning(x, y, sn)
45+
46+
# show results
47+
plt.plot(x, y, '-og', label="Waypoints")
48+
plt.plot(rx, ry, '-r', label="B-Spline path")
49+
plt.grid(True)
50+
plt.legend()
51+
plt.axis("equal")
52+
plt.show()
53+
54+
55+
if __name__ == '__main__':
56+
main()

0 commit comments

Comments
 (0)