From ceadca17a33f82bd68214d1dd13c3911d510f3dc Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Fri, 24 Apr 2026 14:37:06 -0500 Subject: [PATCH] plexy --- opendbc_repo/opendbc/car/gm/carcontroller.py | 40 ++++++++++++++----- opendbc_repo/opendbc/car/gm/carstate.py | 7 +++- opendbc_repo/opendbc/car/gm/interface.py | 3 ++ opendbc_repo/opendbc/car/gm/tests/test_gm.py | 1 + .../opendbc/car/tests/test_can_fingerprint.py | 17 ++++++++ opendbc_repo/opendbc/safety/modes/gm.h | 16 +++++++- opendbc_repo/opendbc/safety/tests/test_gm.py | 10 ++++- 7 files changed, 81 insertions(+), 13 deletions(-) diff --git a/opendbc_repo/opendbc/car/gm/carcontroller.py b/opendbc_repo/opendbc/car/gm/carcontroller.py index 90b9d364a6..6ce089ffc5 100644 --- a/opendbc_repo/opendbc/car/gm/carcontroller.py +++ b/opendbc_repo/opendbc/car/gm/carcontroller.py @@ -23,13 +23,30 @@ CAMERA_CANCEL_DELAY_FRAMES = 10 MIN_STEER_MSG_INTERVAL_MS = 15 +def get_lka_steering_cmd_counter(counter, CS): + if CS.loopback_lka_steering_cmd_updated: + return (CS.loopback_lka_steering_cmd_counter + 1) % 4 + + if CS.loopback_lka_steering_cmd_ts_nanos == 0 and counter < 0: + return (CS.pt_lka_steering_cmd_counter + 1) % 4 + + return counter % 4 + + def get_stock_cc_active_for_cancel(CP, CS): + if CS.out.accFaulted: + return False + stock_cc_active = CS.out.cruiseState.enabled or CS.pcm_acc_status != AccState.OFF if CP.carFingerprint == CAR.CHEVROLET_BOLT_ACC_2022_2023_PEDAL: return CS.out.cruiseState.enabled return stock_cc_active +def should_send_stock_long_cancel(cancel_counter, CS): + return cancel_counter > CAMERA_CANCEL_DELAY_FRAMES and not CS.out.accFaulted + + def use_interceptor_sng_launch(CP, CS, maneuver_mode=False): # Restrict the fixed standstill-launch gas to actual near-zero motion # so higher accel requests can take over once the car has started moving. @@ -112,7 +129,7 @@ class CarController(CarControllerBase): self.last_button_frame = 0 self.cancel_counter = 0 - self.lka_steering_cmd_counter = 0 + self.lka_steering_cmd_counter = -1 self.lka_icon_status_last = (False, False) self.params = CarControllerParams(self.CP) @@ -396,16 +413,12 @@ class CarController(CarControllerBase): if CS.loopback_lka_steering_cmd_ts_nanos == 0 or out_of_sync: steer_step = self.params.STEER_STEP - self.lka_steering_cmd_counter += 1 if CS.loopback_lka_steering_cmd_updated else 0 + self.lka_steering_cmd_counter = get_lka_steering_cmd_counter(self.lka_steering_cmd_counter, CS) # Avoid GM EPS faults when transmitting messages too close together: skip this transmit if we # received the ASCMLKASteeringCmd loopback confirmation too recently last_lka_steer_msg_ms = (now_nanos - CS.loopback_lka_steering_cmd_ts_nanos) * 1e-6 if (self.frame - self.last_steer_frame) >= steer_step and last_lka_steer_msg_ms > MIN_STEER_MSG_INTERVAL_MS: - # Initialize ASCMLKASteeringCmd counter using the camera until we get a msg on the bus - if CS.loopback_lka_steering_cmd_ts_nanos == 0: - self.lka_steering_cmd_counter = CS.pt_lka_steering_cmd_counter + 1 - if CC.latActive: new_torque = int(round(actuators.torque * self.params.STEER_MAX)) apply_torque = apply_driver_steer_torque_limits(new_torque, self.apply_torque_last, CS.out.steeringTorque, self.params) @@ -418,8 +431,10 @@ class CarController(CarControllerBase): self.last_steer_frame = self.frame self.apply_torque_last = apply_torque - idx = self.lka_steering_cmd_counter % 4 + idx = self.lka_steering_cmd_counter can_sends.append(gmcan.create_steering_control(self.packer_pt, CanBus.POWERTRAIN, apply_torque, idx, CC.latActive)) + # Keep the counter moving even if panda stops returning loopback confirmations. + self.lka_steering_cmd_counter = (idx + 1) % 4 if should_spoof_ecm_cruise_status(self.CP) and self.frame % 4 == 0: can_sends.append(gmcan.create_ecm_cruise_control_command( @@ -551,7 +566,12 @@ class CarController(CarControllerBase): if self.CP.enableGasInterceptorDEPRECATED: can_sends.append(create_gas_interceptor_command(self.packer_pt, interceptor_gas_cmd, idx)) if self.CP.carFingerprint not in CC_ONLY_CAR: - friction_brake_bus = CanBus.CHASSIS + volt_gateway_alt_brake = ( + self.CP.carFingerprint == CAR.CHEVROLET_VOLT and + self.CP.networkLocation == NetworkLocation.gateway and + bool(self.CP.flags & GMFlags.NO_ACCELERATOR_POS_MSG.value) + ) + friction_brake_bus = CanBus.POWERTRAIN if volt_gateway_alt_brake else CanBus.CHASSIS # GM Camera exceptions # TODO: can we always check the longControlState? if self.CP.networkLocation == NetworkLocation.fwdCamera: @@ -638,10 +658,10 @@ class CarController(CarControllerBase): 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: + if self.CP.carFingerprint == CAR.CHEVROLET_MALIBU_HYBRID_CC and should_send_stock_long_cancel(self.cancel_counter, CS): malibu_cancel_requested = True elif (self.frame - self.last_button_frame) * DT_CTRL > 0.04: - if self.cancel_counter > CAMERA_CANCEL_DELAY_FRAMES: + if should_send_stock_long_cancel(self.cancel_counter, CS): self.last_button_frame = self.frame sdgm_stock_cancel_pt = ( self.CP.carFingerprint in SDGM_CAR and diff --git a/opendbc_repo/opendbc/car/gm/carstate.py b/opendbc_repo/opendbc/car/gm/carstate.py index 40a08d32a4..6d1daa14b4 100644 --- a/opendbc_repo/opendbc/car/gm/carstate.py +++ b/opendbc_repo/opendbc/car/gm/carstate.py @@ -26,6 +26,7 @@ TransmissionType = structs.CarParams.TransmissionType NetworkLocation = structs.CarParams.NetworkLocation STANDSTILL_THRESHOLD = 10 * 0.0311 +VOLT_EBCM_BRAKE_PRESSED_THRESHOLD = 6 / 0xd0 BUTTONS_DICT = {CruiseButtons.RES_ACCEL: ButtonType.accelCruise, CruiseButtons.DECEL_SET: ButtonType.decelCruise, CruiseButtons.MAIN: ButtonType.mainCruise, CruiseButtons.CANCEL: ButtonType.cancel} @@ -46,6 +47,7 @@ class CarState(CarStateBase): self.cluster_min_speed = CV.KPH_TO_MS / 2. self.loopback_lka_steering_cmd_updated = False + self.loopback_lka_steering_cmd_counter = 0 self.loopback_lka_steering_cmd_ts_nanos = 0 self.pt_lka_steering_cmd_counter = 0 self.cam_lka_steering_cmd_counter = 0 @@ -119,6 +121,7 @@ class CarState(CarStateBase): # Variables used for avoiding LKAS faults self.loopback_lka_steering_cmd_updated = len(loopback_cp.vl_all["ASCMLKASteeringCmd"]["RollingCounter"]) > 0 if self.loopback_lka_steering_cmd_updated: + self.loopback_lka_steering_cmd_counter = loopback_cp.vl["ASCMLKASteeringCmd"]["RollingCounter"] self.loopback_lka_steering_cmd_ts_nanos = loopback_cp.ts_nanos["ASCMLKASteeringCmd"]["RollingCounter"] if self.CP.networkLocation == NetworkLocation.fwdCamera and not self.CP.flags & GMFlags.NO_CAMERA.value: self.pt_lka_steering_cmd_counter = pt_cp.vl["ASCMLKASteeringCmd"]["RollingCounter"] @@ -153,7 +156,9 @@ class CarState(CarStateBase): else: ret.brake = pt_cp.vl["ECMAcceleratorPos"]["BrakePedalPos"] - if self.CP.carFingerprint in {CAR.CHEVROLET_MALIBU_CC} or (self.CP.carFingerprint == CAR.CHEVROLET_BLAZER and not no_accel_pos): + if self.CP.carFingerprint == CAR.CHEVROLET_VOLT and no_accel_pos: + ret.brakePressed = ret.brake >= VOLT_EBCM_BRAKE_PRESSED_THRESHOLD + elif self.CP.carFingerprint in {CAR.CHEVROLET_MALIBU_CC} or (self.CP.carFingerprint == CAR.CHEVROLET_BLAZER and not no_accel_pos): ret.brakePressed = ret.brake >= 8 elif (self.CP.flags & GMFlags.FORCE_BRAKE_C9.value) or ((self.CP.networkLocation == NetworkLocation.fwdCamera) and (self.CP.carFingerprint != CAR.CHEVROLET_BLAZER)): ret.brakePressed = pt_cp.vl["ECMEngineStatus"]["BrakePressed"] != 0 diff --git a/opendbc_repo/opendbc/car/gm/interface.py b/opendbc_repo/opendbc/car/gm/interface.py index 3ca01219b1..e3573b9473 100755 --- a/opendbc_repo/opendbc/car/gm/interface.py +++ b/opendbc_repo/opendbc/car/gm/interface.py @@ -620,6 +620,9 @@ class CarInterface(CarInterfaceBase): if ACCELERATOR_POS_MSG not in fingerprint[CanBus.POWERTRAIN]: ret.flags |= GMFlags.NO_ACCELERATOR_POS_MSG.value + if candidate == CAR.CHEVROLET_VOLT and ret.networkLocation == NetworkLocation.gateway: + # Reuse the no-camera safety bit as an ASCM Volt selector for the alternate EBCM brake path. + ret.safetyConfigs[0].safetyParam |= GMSafetyFlags.FLAG_GM_NO_CAMERA.value try: remote_start_boots_comma = params.get_bool("RemoteStartBootsComma") diff --git a/opendbc_repo/opendbc/car/gm/tests/test_gm.py b/opendbc_repo/opendbc/car/gm/tests/test_gm.py index a3ef1dede7..f90109ca17 100644 --- a/opendbc_repo/opendbc/car/gm/tests/test_gm.py +++ b/opendbc_repo/opendbc/car/gm/tests/test_gm.py @@ -103,6 +103,7 @@ class TestGMInterface: starpilot_toggles=_test_starpilot_toggles()) assert car_params.flags & GMFlags.NO_ACCELERATOR_POS_MSG.value + assert car_params.safetyConfigs[0].safetyParam & GMSafetyFlags.FLAG_GM_NO_CAMERA.value pt_parser = CarInterface.CarState.get_can_parsers(car_params)[Bus.pt] assert "ECMAcceleratorPos" not in pt_parser.vl diff --git a/opendbc_repo/opendbc/car/tests/test_can_fingerprint.py b/opendbc_repo/opendbc/car/tests/test_can_fingerprint.py index c3e29c1d5b..75645a3396 100644 --- a/opendbc_repo/opendbc/car/tests/test_can_fingerprint.py +++ b/opendbc_repo/opendbc/car/tests/test_can_fingerprint.py @@ -84,6 +84,23 @@ class TestCanFingerprint: assert candidate == "CHEVROLET_VOLT_CAMERA" + def test_gm_stored_candidate_fallback_demotes_volt_camera_with_only_camera_diag_msg(self): + fingerprints = {0: {190: 6, 201: 8, 209: 7, 211: 2, 241: 6}, 2: {0x24B: 8}} + + candidate = _get_gm_stored_candidate_fallback(fingerprints, "CHEVROLET_VOLT_CAMERA", None) + + assert candidate == "CHEVROLET_VOLT" + + def test_gm_stored_candidate_fallback_keeps_volt_when_bus2_only_has_forwarded_pt_core_msgs(self): + fingerprints = { + 0: {190: 6, 201: 8, 209: 7, 211: 2, 241: 6}, + 2: {201: 8, 209: 7, 211: 2, 241: 6}, + } + + candidate = _get_gm_stored_candidate_fallback(fingerprints, "CHEVROLET_VOLT", None) + + assert candidate == "CHEVROLET_VOLT" + def test_gm_stored_candidate_fallback_ignores_non_gm_fingerprint(self): fingerprints = {0: {1: 1, 2: 2, 3: 3, 4: 4}} diff --git a/opendbc_repo/opendbc/safety/modes/gm.h b/opendbc_repo/opendbc/safety/modes/gm.h index a1be98f375..9e91b2cc13 100644 --- a/opendbc_repo/opendbc/safety/modes/gm.h +++ b/opendbc_repo/opendbc/safety/modes/gm.h @@ -59,6 +59,7 @@ static bool gm_force_brake_c9 = false; static bool gm_panda_3d1_sched = false; static bool gm_panda_paddle_sched = false; static bool gm_bolt_2022_pedal = false; +static bool gm_alt_brake = false; static bool gm_cc_long = false; static bool gm_has_acc = true; @@ -246,10 +247,14 @@ static void gm_rx_hook(const CANPacket_t *msg) { brake_pressed = GET_BIT(msg, 40U); } - if ((msg->addr == 0xBEU) && ((gm_hw == GM_ASCM) || gm_sdgm || gm_ascm_int)) { + if ((msg->addr == 0xBEU) && (((gm_hw == GM_ASCM) && !gm_alt_brake) || gm_sdgm || gm_ascm_int)) { brake_pressed = msg->data[1] >= 8U; } + if ((msg->addr == 0xF1U) && gm_alt_brake) { + brake_pressed = msg->data[1] >= 6U; + } + if ((msg->addr == 0xC9U) && (gm_hw == GM_CAM) && !gm_force_brake_c9) { brake_pressed = GET_BIT(msg, 40U); } @@ -546,6 +551,12 @@ static safety_config gm_init(uint16_t param) { {0x1E1, 0, 7, .check_relay = false}, {0xBD, 0, 7, .check_relay = false}, {0x1F5, 0, 8, .check_relay = false}}; // pt bus + static const CanMsg GM_ASCM_ALT_BRAKE_TX_MSGS[] = {{0x180, 0, 4, .check_relay = true}, {0x409, 0, 7, .check_relay = false}, {0x40A, 0, 7, .check_relay = false}, {0x2CB, 0, 8, .check_relay = true}, {0x370, 0, 6, .check_relay = false}, {0x315, 0, 5, .check_relay = true}, // pt bus + {0xA1, 1, 7, .check_relay = false}, {0x306, 1, 8, .check_relay = false}, {0x308, 1, 7, .check_relay = false}, {0x310, 1, 2, .check_relay = false}, // obs bus + {0x200, 0, 6, .check_relay = false}, + {0x1E1, 0, 7, .check_relay = false}, + {0xBD, 0, 7, .check_relay = false}, + {0x1F5, 0, 8, .check_relay = false}}; // pt bus static const LongitudinalLimits GM_CAM_LONG_LIMITS = { @@ -660,6 +671,7 @@ static safety_config gm_init(uint16_t param) { gm_remote_start_boots_comma = GET_FLAG(param, GM_PARAM_REMOTE_START_BOOTS_COMMA); gm_panda_3d1_sched = GET_FLAG(param, GM_PARAM_PANDA_3D1_SCHED) && gm_pedal_long && !gm_has_acc && !gm_bolt_2022_pedal; gm_panda_paddle_sched = GET_FLAG(param, GM_PARAM_PANDA_PADDLE_SCHED) && gm_pedal_long && enable_gas_interceptor; + gm_alt_brake = GET_FLAG(param, GM_PARAM_NO_CAMERA) && (gm_hw == GM_ASCM) && !gm_sdgm && !gm_ascm_int; gm_3d1_spoof_valid = false; gm_3d1_internal_tx = false; @@ -726,6 +738,8 @@ static safety_config gm_init(uint16_t param) { ret = BUILD_SAFETY_CFG(gm_rx_checks, GM_CAM_TX_MSGS); } } + } else if (gm_alt_brake) { + ret = BUILD_SAFETY_CFG(gm_rx_checks, GM_ASCM_ALT_BRAKE_TX_MSGS); } else { ret = BUILD_SAFETY_CFG(gm_rx_checks, GM_ASCM_TX_MSGS); } diff --git a/opendbc_repo/opendbc/safety/tests/test_gm.py b/opendbc_repo/opendbc/safety/tests/test_gm.py index 55796356e7..cf0e0f6a2a 100755 --- a/opendbc_repo/opendbc/safety/tests/test_gm.py +++ b/opendbc_repo/opendbc/safety/tests/test_gm.py @@ -196,7 +196,15 @@ class TestGmAscmSafety(GmLongitudinalBase, TestGmSafetyBase): class TestGmAscmEVSafety(TestGmAscmSafety, TestGmEVSafetyBase): - pass + EXTRA_SAFETY_PARAM = GMSafetyFlags.FLAG_GM_NO_CAMERA + TX_MSGS = [[0x180, 0], [0x409, 0], [0x40A, 0], [0x2CB, 0], [0x370, 0], [0x200, 0], [0x1E1, 0], [0xBD, 0], [0x1F5, 0], [0x315, 0], + [0xA1, 1], [0x306, 1], [0x308, 1], [0x310, 1]] + RELAY_MALFUNCTION_ADDRS = {0: (0x180, 0x2CB, 0x315)} + BRAKE_BUS = 0 + + def _user_brake_msg(self, brake): + values = {"BrakePedalPosition": 6 if brake else 0} + return self.packer.make_can_msg_panda("EBCMBrakePedalPosition", 0, values) class TestGmCameraSafetyBase(TestGmSafetyBase):