Skip to content

Commit 6438de5

Browse files
authored
Merge pull request AtsushiSakai#53 from jwdinius/feature/fop_analytic_jerk
analytic jerk calculation in frenet_optimal_planner.py
2 parents 0d53101 + ad25d69 commit 6438de5

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

PathPlanning/FrenetOptimalTrajectory/frenet_optimal_trajectory.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ def calc_second_derivative(self, t):
8686
xt = 2 * self.a2 + 6 * self.a3 * t + 12 * self.a4 * t**2 + 20 * self.a5 * t**3
8787

8888
return xt
89+
90+
def calc_third_derivative(self, t):
91+
xt = 6 * self.a3 + 24 * self.a4 * t + 60 * self.a5 * t**2
8992

93+
return xt
9094

9195
class quartic_polynomial:
9296

@@ -128,6 +132,11 @@ def calc_second_derivative(self, t):
128132
xt = 2 * self.a2 + 6 * self.a3 * t + 12 * self.a4 * t**2
129133

130134
return xt
135+
136+
def calc_third_derivative(self, t):
137+
xt = 6 * self.a3 + 24 * self.a4 * t
138+
139+
return xt
131140

132141

133142
class Frenet_path:
@@ -137,9 +146,11 @@ def __init__(self):
137146
self.d = []
138147
self.d_d = []
139148
self.d_dd = []
149+
self.d_ddd = []
140150
self.s = []
141151
self.s_d = []
142152
self.s_dd = []
153+
self.s_ddd = []
143154
self.cd = 0.0
144155
self.cv = 0.0
145156
self.cf = 0.0
@@ -168,6 +179,7 @@ def calc_frenet_paths(c_speed, c_d, c_d_d, c_d_dd, s0):
168179
fp.d = [lat_qp.calc_point(t) for t in fp.t]
169180
fp.d_d = [lat_qp.calc_first_derivative(t) for t in fp.t]
170181
fp.d_dd = [lat_qp.calc_second_derivative(t) for t in fp.t]
182+
fp.d_ddd = [lat_qp.calc_third_derivative(t) for t in fp.t]
171183

172184
# Loongitudinal motion planning (Velocity keeping)
173185
for tv in np.arange(TARGET_SPEED - D_T_S * N_S_SAMPLE, TARGET_SPEED + D_T_S * N_S_SAMPLE, D_T_S):
@@ -177,9 +189,10 @@ def calc_frenet_paths(c_speed, c_d, c_d_d, c_d_dd, s0):
177189
tfp.s = [lon_qp.calc_point(t) for t in fp.t]
178190
tfp.s_d = [lon_qp.calc_first_derivative(t) for t in fp.t]
179191
tfp.s_dd = [lon_qp.calc_second_derivative(t) for t in fp.t]
192+
tfp.s_ddd = [lon_qp.calc_third_derivative(t) for t in fp.t]
180193

181-
Jp = sum(np.diff(tfp.d_dd)**2) # square of jerk
182-
Js = sum(np.diff(tfp.s_dd)**2) # square of jerk
194+
Jp = sum(np.power(tfp.d_ddd, 2)) # square of jerk
195+
Js = sum(np.power(tfp.s_ddd, 2)) # square of jerk
183196

184197
# square of diff from target speed
185198
ds = (TARGET_SPEED - tfp.s_d[-1])**2

0 commit comments

Comments
 (0)