Skip to content

Commit

Permalink
Brake sooner if approaching a car fast
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonGalaxy75 authored Dec 17, 2018
1 parent feb3114 commit 1ff5347
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions selfdrive/controls/lib/planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,18 @@ def update(self, CS, lead, v_cruise_setpoint):
self.lead_car_gap_shrinking = 1
else:
self.lead_car_gap_shrinking = 0

# Is the gap from the lead car shrinking FAST?
if self.v_rel < -7.5:
self.lead_car_gap_shrinking_fast = 1
else:
self.lead_car_gap_shrinking_fast = 0


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

elif CS.readdistancelines == 2:
# More conservative braking than comma default
if self.street_speed and (self.lead_car_gap_shrinking or self.tailgating):
if self.lead_car_gap_shrinking_fast or (self.street_speed and (self.lead_car_gap_shrinking or self.tailgating)):
TR=2.0
if self.lastTR != -2:
self.libmpc.init(MPC_COST_LONG.TTC, 0.0875, MPC_COST_LONG.ACCELERATION, MPC_COST_LONG.JERK)
Expand Down

0 comments on commit 1ff5347

Please sign in to comment.