diff --git a/opendbc_repo/opendbc/car/gm/carcontroller.py b/opendbc_repo/opendbc/car/gm/carcontroller.py index f179512cd..d6470132e 100644 --- a/opendbc_repo/opendbc/car/gm/carcontroller.py +++ b/opendbc_repo/opendbc/car/gm/carcontroller.py @@ -218,7 +218,7 @@ def get_volt_one_pedal_target_decel(v_ego: float) -> float: def should_activate_volt_one_pedal(one_pedal_ready: bool, cruise_main: bool, long_active: bool, gas_pressed: bool, brake_pressed: bool, regen_braking: bool, single_pedal_mode: bool, gear_shifter, drive_time_s: float) -> bool: - # Volt rear wheel direction bits can falsely report reverse while stopping in L. + return ( one_pedal_ready and cruise_main and @@ -227,8 +227,22 @@ def should_activate_volt_one_pedal(one_pedal_ready: bool, cruise_main: bool, lon drive_time_s >= AUTO_HOLD_MIN_DRIVE_TIME_S and not long_active and not gas_pressed and - not brake_pressed and - not regen_braking + not brake_pressed + ) + + +def should_suppress_volt_stock_long_pre_drive(CP, gear_shifter, enabled: bool) -> bool: + return ( + CP.carFingerprint in AUTO_HOLD_VOLT_CARS and + gear_shifter not in AUTO_HOLD_DRIVE_GEARS and + not enabled + ) + + +def should_suppress_volt_stock_cancel_in_park(CP, gear_shifter) -> bool: + return ( + CP.carFingerprint in AUTO_HOLD_VOLT_CARS and + gear_shifter not in AUTO_HOLD_DRIVE_GEARS ) @@ -870,7 +884,13 @@ class CarController(CarControllerBase): else: acc_engaged = CC.enabled - if auto_hold_active: + skip_volt_stock_long_pre_drive = should_suppress_volt_stock_long_pre_drive( + self.CP, CS.out.gearShifter, CC.enabled + ) + + if skip_volt_stock_long_pre_drive: + CS.auto_hold_engaged = False + elif auto_hold_active: hold_brake = max(self.volt_one_pedal_brake, self.auto_hold_brake or estimate_auto_hold_brake(CS.out.brake, self.apply_brake)) hold_standstill = CS.pcm_acc_status == AccState.STANDSTILL hold_near_stop = CS.out.vEgo < self.params.NEAR_STOP_BRAKE_PHASE @@ -991,7 +1011,10 @@ class CarController(CarControllerBase): # While car is braking, cancel button causes ECM to enter a soft disable state with a fault status. # A delayed cancellation allows camera to cancel and avoids a fault when user depresses brake quickly - self.cancel_counter = self.cancel_counter + 1 if CC.cruiseControl.cancel else 0 + if should_suppress_volt_stock_cancel_in_park(self.CP, CS.out.gearShifter): + self.cancel_counter = 0 + else: + self.cancel_counter = self.cancel_counter + 1 if CC.cruiseControl.cancel else 0 # Stock longitudinal, integrated at camera if self.CP.carFingerprint == CAR.CHEVROLET_MALIBU_HYBRID_CC and self.cancel_counter > CAMERA_CANCEL_DELAY_FRAMES: diff --git a/opendbc_repo/opendbc/car/gm/tests/test_carcontroller.py b/opendbc_repo/opendbc/car/gm/tests/test_carcontroller.py index 0460ebb62..f83b8fd62 100644 --- a/opendbc_repo/opendbc/car/gm/tests/test_carcontroller.py +++ b/opendbc_repo/opendbc/car/gm/tests/test_carcontroller.py @@ -48,6 +48,8 @@ from opendbc.car.gm.carcontroller import ( should_activate_volt_one_pedal, should_neutralize_volt_long_on_driver_override, should_send_stock_long_cancel, + should_suppress_volt_stock_cancel_in_park, + should_suppress_volt_stock_long_pre_drive, should_spoof_dash_speed, should_spoof_ecm_cruise_status, supports_volt_auto_hold, @@ -408,7 +410,7 @@ def test_volt_one_pedal_activation_requires_main_l_mode_and_no_driver_input(): structs.CarState.GearShifter.low, 3.0, ) - assert not should_activate_volt_one_pedal( + assert should_activate_volt_one_pedal( True, True, False, @@ -452,6 +454,20 @@ def test_volt_one_pedal_regression_ignores_noisy_wheel_direction_bits(): ) +def test_volt_one_pedal_regression_stays_active_through_l_mode_regen_state(): + assert should_activate_volt_one_pedal( + True, + True, + False, + False, + False, + True, + True, + structs.CarState.GearShifter.manumatic, + 3.0, + ) + + def test_volt_one_pedal_requires_time_in_drive_before_arming(): assert not should_activate_volt_one_pedal( True, @@ -504,6 +520,21 @@ def test_volt_driver_override_neutralization_skips_pedal_and_non_volt_paths(): ) +def test_volt_stock_long_pre_drive_is_suppressed_outside_drive_gears(): + CP = SimpleNamespace(carFingerprint=CAR.CHEVROLET_VOLT_2019) + + assert should_suppress_volt_stock_long_pre_drive(CP, structs.CarState.GearShifter.park, False) + assert not should_suppress_volt_stock_long_pre_drive(CP, structs.CarState.GearShifter.drive, False) + assert not should_suppress_volt_stock_long_pre_drive(CP, structs.CarState.GearShifter.park, True) + + +def test_volt_stock_cancel_is_suppressed_outside_drive_gears(): + CP = SimpleNamespace(carFingerprint=CAR.CHEVROLET_VOLT_2019) + + assert should_suppress_volt_stock_cancel_in_park(CP, structs.CarState.GearShifter.park) + assert not should_suppress_volt_stock_cancel_in_park(CP, structs.CarState.GearShifter.low) + + def test_friction_brake_mode_keeps_near_stop_disabled_for_regular_long_braking(): CP = SimpleNamespace(carFingerprint=CAR.CHEVROLET_VOLT_ASCM)