Skip to content

Commit 1ff5347

Browse files
authored
Brake sooner if approaching a car fast
1 parent feb3114 commit 1ff5347

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

selfdrive/controls/lib/planner.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,18 @@ def update(self, CS, lead, v_cruise_setpoint):
251251
self.lead_car_gap_shrinking = 1
252252
else:
253253
self.lead_car_gap_shrinking = 0
254+
255+
# Is the gap from the lead car shrinking FAST?
256+
if self.v_rel < -7.5:
257+
self.lead_car_gap_shrinking_fast = 1
258+
else:
259+
self.lead_car_gap_shrinking_fast = 0
260+
254261

255262
# Adjust distance from lead car when distance button pressed
256263
if CS.readdistancelines == 1:
257264
# If one bar distance, auto set to 2 bar distance under current conditions to prevent rear ending lead car
258-
if self.street_speed and (self.lead_car_gap_shrinking or self.tailgating):
265+
if self.lead_car_gap_shrinking_fast or (self.street_speed and (self.lead_car_gap_shrinking or self.tailgating)):
259266
TR=2.1
260267
if self.lastTR != -1:
261268
self.libmpc.init(MPC_COST_LONG.TTC, 0.0825, MPC_COST_LONG.ACCELERATION, MPC_COST_LONG.JERK)
@@ -268,7 +275,7 @@ def update(self, CS, lead, v_cruise_setpoint):
268275

269276
elif CS.readdistancelines == 2:
270277
# More conservative braking than comma default
271-
if self.street_speed and (self.lead_car_gap_shrinking or self.tailgating):
278+
if self.lead_car_gap_shrinking_fast or (self.street_speed and (self.lead_car_gap_shrinking or self.tailgating)):
272279
TR=2.0
273280
if self.lastTR != -2:
274281
self.libmpc.init(MPC_COST_LONG.TTC, 0.0875, MPC_COST_LONG.ACCELERATION, MPC_COST_LONG.JERK)

0 commit comments

Comments
 (0)