Skip to content

Commit fbeeefb

Browse files
committed
code cleanup for quintic_polynomials_planner.py
1 parent 5ceb837 commit fbeeefb

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,17 @@
2424

2525
class QuinticPolynomial:
2626

27-
def __init__(self, xs, vxs, axs, xe, vxe, axe, T):
28-
27+
def __init__(self, xs, vxs, axs, xe, vxe, axe, time):
2928
# calc coefficient of quintic polynomial
3029
self.a0 = xs
3130
self.a1 = vxs
3231
self.a2 = axs / 2.0
3332

34-
A = np.array([[T**3, T**4, T**5],
35-
[3 * T ** 2, 4 * T ** 3, 5 * T ** 4],
36-
[6 * T, 12 * T ** 2, 20 * T ** 3]])
37-
b = np.array([xe - self.a0 - self.a1 * T - self.a2 * T**2,
38-
vxe - self.a1 - 2 * self.a2 * T,
33+
A = np.array([[time ** 3, time ** 4, time ** 5],
34+
[3 * time ** 2, 4 * time ** 3, 5 * time ** 4],
35+
[6 * time, 12 * time ** 2, 20 * time ** 3]])
36+
b = np.array([xe - self.a0 - self.a1 * time - self.a2 * time ** 2,
37+
vxe - self.a1 - 2 * self.a2 * time,
3938
axe - 2 * self.a2])
4039
x = np.linalg.solve(A, b)
4140

@@ -44,24 +43,24 @@ def __init__(self, xs, vxs, axs, xe, vxe, axe, T):
4443
self.a5 = x[2]
4544

4645
def calc_point(self, t):
47-
xt = self.a0 + self.a1 * t + self.a2 * t**2 + \
48-
self.a3 * t**3 + self.a4 * t**4 + self.a5 * t**5
46+
xt = self.a0 + self.a1 * t + self.a2 * t ** 2 + \
47+
self.a3 * t ** 3 + self.a4 * t ** 4 + self.a5 * t ** 5
4948

5049
return xt
5150

5251
def calc_first_derivative(self, t):
5352
xt = self.a1 + 2 * self.a2 * t + \
54-
3 * self.a3 * t**2 + 4 * self.a4 * t**3 + 5 * self.a5 * t**4
53+
3 * self.a3 * t ** 2 + 4 * self.a4 * t ** 3 + 5 * self.a5 * t ** 4
5554

5655
return xt
5756

5857
def calc_second_derivative(self, t):
59-
xt = 2 * self.a2 + 6 * self.a3 * t + 12 * self.a4 * t**2 + 20 * self.a5 * t**3
58+
xt = 2 * self.a2 + 6 * self.a3 * t + 12 * self.a4 * t ** 2 + 20 * self.a5 * t ** 3
6059

6160
return xt
6261

6362
def calc_third_derivative(self, t):
64-
xt = 6 * self.a3 + 24 * self.a4 * t + 60 * self.a5 * t**2
63+
xt = 6 * self.a3 + 24 * self.a4 * t + 60 * self.a5 * t ** 2
6564

6665
return xt
6766

@@ -146,7 +145,7 @@ def quintic_polynomials_planner(sx, sy, syaw, sv, sa, gx, gy, gyaw, gv, ga, max_
146145
plt.cla()
147146
# for stopping simulation with the esc key.
148147
plt.gcf().canvas.mpl_connect('key_release_event',
149-
lambda event: [exit(0) if event.key == 'escape' else None])
148+
lambda event: [exit(0) if event.key == 'escape' else None])
150149
plt.grid(True)
151150
plt.axis("equal")
152151
plot_arrow(sx, sy, syaw)

0 commit comments

Comments
 (0)