brake pedal release should not allow auto lane change (caught by test)

This commit is contained in:
Jason Wen
2025-03-24 20:32:51 -04:00
parent 135ff49514
commit 7ab994a71d
2 changed files with 28 additions and 3 deletions
@@ -44,7 +44,6 @@ class AutoLaneChangeController:
self.prev_brake_pressed = False
self.lane_change_delay = 0.0
self._blindspot_detected = False
self._brake_pressed = False
self.auto_lane_change_allowed = False
self.read_params()
@@ -95,10 +94,11 @@ class AutoLaneChangeController:
def update(self, blindspot_detected: bool, brake_pressed: bool) -> None:
self._blindspot_detected = blindspot_detected
self._brake_pressed = brake_pressed
if brake_pressed and not self.prev_brake_pressed:
self.prev_brake_pressed = brake_pressed
self.update_lane_change_timers()
alc_allowed = self.update_allowed()
self.auto_lane_change_allowed = alc_allowed
self.prev_brake_pressed = self._brake_pressed
@@ -94,6 +94,31 @@ class TestAutoLaneChangeController:
assert self.alc.lane_change_wait_timer > self.alc.lane_change_delay
assert self.alc.auto_lane_change_allowed
def test_brake_pressed_disables_auto_lane_change(self):
"""Test that pressing the brake disables auto lane change."""
self.alc.reset()
# Setup NUDGELESS mode (which normally allows auto lane change)
self.alc.lane_change_bsm_delay = False
self.alc.lane_change_set_timer = AutoLaneChangeState.NUDGELESS
# Update with brake pressed for 1 second
num_updates = int(1.0 / DT_MDL)
for _ in range(num_updates):
self.alc.update(blindspot_detected=False, brake_pressed=True)
# Even though NUDGELESS mode, lane change should be disallowed due to brake pressed prior initiating lane change
assert not self.alc.auto_lane_change_allowed
# Check that prev_brake_pressed is saved
assert self.alc.prev_brake_pressed
# Even releasing brake shouldn't allow auto lane change
num_updates = int(1.0 / DT_MDL)
for _ in range(num_updates):
self.alc.update(blindspot_detected=False, brake_pressed=False)
assert not self.alc.auto_lane_change_allowed
def test_blindspot_detected_with_bsm_delay(self):
"""Test behavior when blindspot is detected with BSM delay enabled."""
self.alc.reset()