Skip to content

Commit 6cb903a

Browse files
committed
add mypy setting and update bspline_path.py
1 parent 80ebc55 commit 6cb903a

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

.github/workflows/mypycheck.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- name: Mypy Check
2+
uses: jpetrucciani/[email protected]
3+

PathPlanning/BSplinePath/bspline_path.py

+44-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
3-
Path Planning with B-Spline
3+
Path Planner with B-Spline
44
55
author: Atsushi Sakai (@Atsushi_twi)
66
@@ -11,38 +11,69 @@
1111
import scipy.interpolate as scipy_interpolate
1212

1313

14-
def b_spline_planning(x, y, sn, degree=3):
14+
def approximate_b_spline_path(x: list, y: list, n_path_points: int,
15+
degree: int = 3) -> tuple:
16+
"""
17+
approximate points with a B-Spline path
18+
19+
:param x: x position list of approximated points
20+
:param y: y position list of approximated points
21+
:param n_path_points: number of path points
22+
:param degree: (Optional) B Spline curve degree
23+
:return: x and y position list of the result path
24+
"""
1525
t = range(len(x))
1626
x_tup = scipy_interpolate.splrep(t, x, k=degree)
1727
y_tup = scipy_interpolate.splrep(t, y, k=degree)
1828

1929
x_list = list(x_tup)
20-
xl = x.tolist()
21-
x_list[1] = xl + [0.0, 0.0, 0.0, 0.0]
30+
x_list[1] = x + [0.0, 0.0, 0.0, 0.0]
2231

2332
y_list = list(y_tup)
24-
yl = y.tolist()
25-
y_list[1] = yl + [0.0, 0.0, 0.0, 0.0]
33+
y_list[1] = y + [0.0, 0.0, 0.0, 0.0]
2634

27-
ipl_t = np.linspace(0.0, len(x) - 1, sn)
35+
ipl_t = np.linspace(0.0, len(x) - 1, n_path_points)
2836
rx = scipy_interpolate.splev(ipl_t, x_list)
2937
ry = scipy_interpolate.splev(ipl_t, y_list)
3038

3139
return rx, ry
3240

3341

42+
def interpolate_b_spline_path(x: list, y: list, n_path_points: int,
43+
degree: int = 3) -> tuple:
44+
"""
45+
interpolate points with a B-Spline path
46+
47+
:param x: x positions of interpolated points
48+
:param y: y positions of interpolated points
49+
:param n_path_points: number of path points
50+
:param degree: B-Spline degree
51+
:return: x and y position list of the result path
52+
"""
53+
ipl_t = np.linspace(0.0, len(x) - 1, len(x))
54+
spl_i_x = scipy_interpolate.make_interp_spline(ipl_t, x, k=degree)
55+
spl_i_y = scipy_interpolate.make_interp_spline(ipl_t, y, k=degree)
56+
57+
travel = np.linspace(0.0, len(x) - 1, n_path_points)
58+
return spl_i_x(travel), spl_i_y(travel)
59+
60+
3461
def main():
3562
print(__file__ + " start!!")
3663
# way points
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])
39-
sn = 100 # sampling number
64+
way_point_x = [-1.0, 3.0, 4.0, 2.0, 1.0]
65+
way_point_y = [0.0, -3.0, 1.0, 1.0, 3.0]
66+
n_course_point = 100 # sampling number
4067

41-
rx, ry = b_spline_planning(way_x, way_y, sn)
68+
rax, ray = approximate_b_spline_path(way_point_x, way_point_y,
69+
n_course_point)
70+
rix, riy = interpolate_b_spline_path(way_point_x, way_point_y,
71+
n_course_point)
4272

4373
# show results
44-
plt.plot(way_x, way_y, '-og', label="way points")
45-
plt.plot(rx, ry, '-r', label="B-Spline path")
74+
plt.plot(way_point_x, way_point_y, '-og', label="way points")
75+
plt.plot(rax, ray, '-r', label="Approximated B-Spline path")
76+
plt.plot(rix, riy, '-b', label="Interpolated B-Spline path")
4677
plt.grid(True)
4778
plt.legend()
4879
plt.axis("equal")

mypy.ini

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[mypy]
2+
ignore_missing_imports = True

0 commit comments

Comments
 (0)