Skip to content

Commit 33f4b94

Browse files
committed
keep DRY
1 parent cd65de2 commit 33f4b94

File tree

1 file changed

+13
-45
lines changed

1 file changed

+13
-45
lines changed

PathPlanning/FrenetOptimalTrajectory/frenet_optimal_trajectory.py

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717
import copy
1818
import math
1919
import cubic_spline_planner
20+
import sys
21+
import os
22+
23+
sys.path.append(os.path.dirname(os.path.abspath(__file__)) +
24+
"/../QuinticPolynomialsPlanner/")
25+
26+
try:
27+
from quintic_polynomials_planner import QuinticPolynomial
28+
except ImportError:
29+
raise
30+
2031

2132
SIM_LOOP = 500
2233

@@ -44,50 +55,6 @@
4455
show_animation = True
4556

4657

47-
class quintic_polynomial:
48-
49-
def __init__(self, xs, vxs, axs, xe, vxe, axe, T):
50-
51-
# calc coefficient of quintic polynomial
52-
self.a0 = xs
53-
self.a1 = vxs
54-
self.a2 = axs / 2.0
55-
56-
A = np.array([[T**3, T**4, T**5],
57-
[3 * T ** 2, 4 * T ** 3, 5 * T ** 4],
58-
[6 * T, 12 * T ** 2, 20 * T ** 3]])
59-
b = np.array([xe - self.a0 - self.a1 * T - self.a2 * T**2,
60-
vxe - self.a1 - 2 * self.a2 * T,
61-
axe - 2 * self.a2])
62-
x = np.linalg.solve(A, b)
63-
64-
self.a3 = x[0]
65-
self.a4 = x[1]
66-
self.a5 = x[2]
67-
68-
def calc_point(self, t):
69-
xt = self.a0 + self.a1 * t + self.a2 * t**2 + \
70-
self.a3 * t**3 + self.a4 * t**4 + self.a5 * t**5
71-
72-
return xt
73-
74-
def calc_first_derivative(self, t):
75-
xt = self.a1 + 2 * self.a2 * t + \
76-
3 * self.a3 * t**2 + 4 * self.a4 * t**3 + 5 * self.a5 * t**4
77-
78-
return xt
79-
80-
def calc_second_derivative(self, t):
81-
xt = 2 * self.a2 + 6 * self.a3 * t + 12 * self.a4 * t**2 + 20 * self.a5 * t**3
82-
83-
return xt
84-
85-
def calc_third_derivative(self, t):
86-
xt = 6 * self.a3 + 24 * self.a4 * t + 60 * self.a5 * t**2
87-
88-
return xt
89-
90-
9158
class quartic_polynomial:
9259

9360
def __init__(self, xs, vxs, axs, vxe, axe, T):
@@ -164,7 +131,8 @@ def calc_frenet_paths(c_speed, c_d, c_d_d, c_d_dd, s0):
164131
for Ti in np.arange(MINT, MAXT, DT):
165132
fp = Frenet_path()
166133

167-
lat_qp = quintic_polynomial(c_d, c_d_d, c_d_dd, di, 0.0, 0.0, Ti)
134+
# lat_qp = quintic_polynomial(c_d, c_d_d, c_d_dd, di, 0.0, 0.0, Ti)
135+
lat_qp = QuinticPolynomial(c_d, c_d_d, c_d_dd, di, 0.0, 0.0, Ti)
168136

169137
fp.t = [t for t in np.arange(0.0, Ti, DT)]
170138
fp.d = [lat_qp.calc_point(t) for t in fp.t]

0 commit comments

Comments
 (0)