diff --git a/opendbc_repo/opendbc/car/byd/bydcan.py b/opendbc_repo/opendbc/car/byd/bydcan.py index 47f6ea9..bb51e56 100644 --- a/opendbc_repo/opendbc/car/byd/bydcan.py +++ b/opendbc_repo/opendbc/car/byd/bydcan.py @@ -138,6 +138,47 @@ class BydCAN: values["CHECKSUM"] = byd_checksum(data) return self.packer.make_can_msg("STEERING_TORQUE", CANBUS.cam_bus, values) + # SEAL: spoofed 508 STEERING_TORQUE_ANGLE feedback towards the camera. + # Mirrors the camera's own request state back to it so the stock ADAS does + # not fault while panda intercepts its LKAS commands (same trick as the + # HAN's 792 spoofing, but on the Seal's 508 message layout). + def create_steering_torque_angle(self, eps_steering_torque_msg, mpc_lkas_output, + mpc_lkas_request_prepare, mpc_lkas_active, + mpc_lkas_angle_output): + lks_prepared = eps_steering_torque_msg["LKSPrepare"] + cruise_activated = eps_steering_torque_msg["Cruise_Activated"] + main_torque = eps_steering_torque_msg["MAIN_TORQUE"] + target_angle = eps_steering_torque_msg["TARGET_ANGLE"] + + if mpc_lkas_active: + lks_prepared = 0 + cruise_activated = 1 + main_torque = mpc_lkas_output + target_angle = mpc_lkas_angle_output + elif mpc_lkas_request_prepare: + lks_prepared = 1 + cruise_activated = 0 + main_torque = 0 + else: + lks_prepared = 0 + cruise_activated = 0 + main_torque = 0 + + values = { + "LKSPrepare": lks_prepared, + "Cruise_Activated": cruise_activated, + "TORQUE_FAILED": eps_steering_torque_msg["TORQUE_FAILED"], + "Steer_Torque_Sensor": eps_steering_torque_msg["Steer_Torque_Sensor"], + "TARGET_ANGLE": target_angle, + "MAIN_TORQUE": main_torque, + "Keep_Hands_On_Wheel": 0, + "TORQUE_TEMP_FAILED": eps_steering_torque_msg["TORQUE_TEMP_FAILED"], + "COUNTER": self._generate_eps_steering_torque_new_counter(), + } + data = self.packer.make_can_msg("STEERING_TORQUE_ANGLE", CANBUS.cam_bus, values)[1] + values["CHECKSUM"] = byd_checksum(data) + return self.packer.make_can_msg("STEERING_TORQUE_ANGLE", CANBUS.cam_bus, values) + def create_acc_cmd(self, acc_cmd_msg, accel): values = { "ACCEL_CMD": accel, diff --git a/opendbc_repo/opendbc/car/byd/carcontroller.py b/opendbc_repo/opendbc/car/byd/carcontroller.py index 5cd8bb0..4e81765 100644 --- a/opendbc_repo/opendbc/car/byd/carcontroller.py +++ b/opendbc_repo/opendbc/car/byd/carcontroller.py @@ -30,10 +30,10 @@ class CarController(CarControllerBase): self.apply_accel_last = 0 - # EPS steering feedback forwarding (792 STEERING_TORQUE) only applies to - # platforms whose EPS reports on 792 (HAN). The SEAL EPS reports on - # 508 STEERING_TORQUE_ANGLE which is forwarded stock for now. - self.send_steering_feedback = CP.carFingerprint != CAR.BYD_SEAL_PERFORMANCE_25 + # EPS steering feedback is spoofed towards the camera on both platforms so + # the stock ADAS does not fault while its LKAS commands are intercepted: + # HAN uses 792 STEERING_TORQUE, SEAL uses 508 STEERING_TORQUE_ANGLE. + self.seal_platform = CP.carFingerprint == CAR.BYD_SEAL_PERFORMANCE_25 def update(self, CC, CC_SP, CS, now_nanos): # car control running in 100Hz @@ -80,12 +80,18 @@ class CarController(CarControllerBase): lkas_request_prepare, lkas_active, lkas_mode, CS.eps_activated) can_sends.append(pack) - if self.send_steering_feedback: + if self.seal_platform: + pack = self.can.create_steering_torque_angle(CS.eps_steering_torque_msg, + CS.mpc_lkas_output, + CS.mpc_lkas_request_prepare, + CS.mpc_lkas_active, + CS.mpc_lkas_angle_output) + else: pack = self.can.create_steering_torque(CS.eps_steering_torque_msg, CS.mpc_lkas_output, CS.mpc_lkas_request_prepare, CS.mpc_lkas_active) - can_sends.append(pack) + can_sends.append(pack) self.apply_torque_last = apply_torque diff --git a/opendbc_repo/opendbc/car/byd/carstate.py b/opendbc_repo/opendbc/car/byd/carstate.py index 2f4515d..db26a61 100644 --- a/opendbc_repo/opendbc/car/byd/carstate.py +++ b/opendbc_repo/opendbc/car/byd/carstate.py @@ -35,6 +35,7 @@ class CarState(CarStateBase, MadsCarState): self.mpc_lkas_output = 0 self.mpc_lkas_active = False self.mpc_lkas_request_prepare = False + self.mpc_lkas_angle_output = 0.0 def update(self, can_parsers) -> tuple[structs.CarState, structs.CarStateSP]: cp = can_parsers[Bus.pt] @@ -106,6 +107,8 @@ class CarState(CarStateBase, MadsCarState): self.mpc_lkas_output = cp_cam.vl["MPC_LKAS_CMD"]["LKAS_Output"] self.mpc_lkas_active = cp_cam.vl["MPC_LKAS_CMD"]["LKAS_ACTIVE"] != 0 self.mpc_lkas_request_prepare = cp_cam.vl["MPC_LKAS_CMD"]["LKASPrepare"] != 0 + # camera's angle-based LKAS request (SEAL), used to spoof the 508 TARGET_ANGLE echo + self.mpc_lkas_angle_output = cp_cam.vl["MPC_LKAS_CMD_ANGLE"]["LKAS_Output"] # for generate ACC_CMD self.acc_cmd_msg = copy.copy(cp_adas.vl["ACC_CMD"]) return ret, ret_sp diff --git a/opendbc_repo/opendbc/safety/modes/byd.h b/opendbc_repo/opendbc/safety/modes/byd.h index 2a45875..2bca0eb 100644 --- a/opendbc_repo/opendbc/safety/modes/byd.h +++ b/opendbc_repo/opendbc/safety/modes/byd.h @@ -42,15 +42,22 @@ static bool byd_tx_hook(const CANPacket_t *msg) { } } - // STEERING_TORQUE: feedback message towards the camera, torque echoes the - // camera's own request. Only sanity-check the absolute limit so stock LKAS - // requests don't fault when openpilot is inactive. + // STEERING_TORQUE (792, HAN) / STEERING_TORQUE_ANGLE (508, SEAL): + // feedback message towards the camera, torque echoes the camera's own + // request. Only sanity-check the absolute limit so stock LKAS requests + // don't fault when openpilot is inactive. if (msg->addr == 792U) { int main_torque = BYD_GET_MAIN_TORQUE(msg); if (safety_max_limit_check(main_torque, BYD_STEERING_LIMITS.max_torque, -BYD_STEERING_LIMITS.max_torque)) { tx = false; } } + if (msg->addr == 508U) { + int main_torque = BYD_GET_MAIN_TORQUE_ANGLE(msg); + if (safety_max_limit_check(main_torque, BYD_STEERING_LIMITS.max_torque, -BYD_STEERING_LIMITS.max_torque)) { + tx = false; + } + } // ACC_CMD: longitudinal actuation if (msg->addr == 814U) { @@ -115,12 +122,14 @@ static void byd_rx_hook(const CANPacket_t *msg) { static safety_config byd_init(uint16_t param) { static const CanMsg BYD_TX_MSGS[] = { {790, 0, 8, .check_relay = true}, // MPC_LKAS_CMD - {792, 2, 8, .check_relay = true}, // STEERING_TORQUE + {792, 2, 8, .check_relay = true}, // STEERING_TORQUE (HAN) + {508, 2, 8, .check_relay = true}, // STEERING_TORQUE_ANGLE (SEAL) }; static const CanMsg BYD_TX_LONG_MSGS[] = { {790, 0, 8, .check_relay = true}, // MPC_LKAS_CMD - {792, 2, 8, .check_relay = true}, // STEERING_TORQUE + {792, 2, 8, .check_relay = true}, // STEERING_TORQUE (HAN) + {508, 2, 8, .check_relay = true}, // STEERING_TORQUE_ANGLE (SEAL) {814, 0, 8, .check_relay = true}, // ACC_CMD }; diff --git a/opendbc_repo/opendbc/safety/tests/test_byd.py b/opendbc_repo/opendbc/safety/tests/test_byd.py index 9548ae9..a10df63 100644 --- a/opendbc_repo/opendbc/safety/tests/test_byd.py +++ b/opendbc_repo/opendbc/safety/tests/test_byd.py @@ -7,8 +7,9 @@ import opendbc.safety.tests.common as common from opendbc.safety.tests.common import CANPackerSafety MSG_MPC_LKAS_CMD = 790 # TX by OP, lateral actuation towards EPS -MSG_STEERING_TORQUE = 792 # RX from EPS / TX by OP, torque feedback towards camera -MSG_ACC_HUD_ADAS = 813 # RX from camera, ACC state +MSG_STEERING_TORQUE = 792 # RX from EPS / TX by OP, torque feedback towards camera (HAN) +MSG_STEERING_TORQUE_ANGLE = 508 # RX from EPS / TX by OP, torque feedback towards camera (SEAL) +MSG_ACC_HUD_ADAS = 813 # RX from ADAS, ACC state MSG_ACC_CMD = 814 # TX by OP, longitudinal actuation MSG_PCM_BUTTONS = 944 # RX from PCM, steering wheel buttons @@ -36,10 +37,10 @@ def byd_checksum(msg): class TestBydSafetyBase(common.CarSafetyTest, common.MotorTorqueSteeringSafetyTest): - TX_MSGS = [[MSG_MPC_LKAS_CMD, 0], [MSG_STEERING_TORQUE, 2]] + TX_MSGS = [[MSG_MPC_LKAS_CMD, 0], [MSG_STEERING_TORQUE, 2], [MSG_STEERING_TORQUE_ANGLE, 2]] STANDSTILL_THRESHOLD = 0 - RELAY_MALFUNCTION_ADDRS = {0: (MSG_MPC_LKAS_CMD,), 2: (MSG_STEERING_TORQUE,)} - FWD_BLACKLISTED_ADDRS = {0: [MSG_STEERING_TORQUE], 2: [MSG_MPC_LKAS_CMD]} + RELAY_MALFUNCTION_ADDRS = {0: (MSG_MPC_LKAS_CMD,), 2: (MSG_STEERING_TORQUE, MSG_STEERING_TORQUE_ANGLE)} + FWD_BLACKLISTED_ADDRS = {0: [MSG_STEERING_TORQUE, MSG_STEERING_TORQUE_ANGLE], 2: [MSG_MPC_LKAS_CMD]} MAX_TORQUE_LOOKUP = ([0], [300]) MAX_RATE_UP = 6 @@ -98,9 +99,9 @@ class TestBydStockSafety(TestBydSafetyBase): class TestBydLongitudinalSafety(TestBydSafetyBase): - TX_MSGS = [[MSG_MPC_LKAS_CMD, 0], [MSG_STEERING_TORQUE, 2], [MSG_ACC_CMD, 0]] - RELAY_MALFUNCTION_ADDRS = {0: (MSG_MPC_LKAS_CMD, MSG_ACC_CMD), 2: (MSG_STEERING_TORQUE,)} - FWD_BLACKLISTED_ADDRS = {0: [MSG_STEERING_TORQUE], 2: [MSG_MPC_LKAS_CMD, MSG_ACC_CMD]} + TX_MSGS = [[MSG_MPC_LKAS_CMD, 0], [MSG_STEERING_TORQUE, 2], [MSG_STEERING_TORQUE_ANGLE, 2], [MSG_ACC_CMD, 0]] + RELAY_MALFUNCTION_ADDRS = {0: (MSG_MPC_LKAS_CMD, MSG_ACC_CMD), 2: (MSG_STEERING_TORQUE, MSG_STEERING_TORQUE_ANGLE)} + FWD_BLACKLISTED_ADDRS = {0: [MSG_STEERING_TORQUE, MSG_STEERING_TORQUE_ANGLE], 2: [MSG_MPC_LKAS_CMD, MSG_ACC_CMD]} MIN_ACCEL = 20 # -4.0 m/s^2, raw = (m/s^2 + 5) / 0.05 MAX_ACCEL = 140 # 2.0 m/s^2 diff --git a/panda/board/obj/body_h7.bin.signed b/panda/board/obj/body_h7.bin.signed index 60437f8..de6287c 100644 Binary files a/panda/board/obj/body_h7.bin.signed and b/panda/board/obj/body_h7.bin.signed differ diff --git a/panda/board/obj/body_h7/bootstub.elf b/panda/board/obj/body_h7/bootstub.elf index cb925be..5358033 100755 Binary files a/panda/board/obj/body_h7/bootstub.elf and b/panda/board/obj/body_h7/bootstub.elf differ diff --git a/panda/board/obj/body_h7/main.bin b/panda/board/obj/body_h7/main.bin index 91711cd..9685902 100755 Binary files a/panda/board/obj/body_h7/main.bin and b/panda/board/obj/body_h7/main.bin differ diff --git a/panda/board/obj/body_h7/main.elf b/panda/board/obj/body_h7/main.elf index 110e2ab..f6bd240 100755 Binary files a/panda/board/obj/body_h7/main.elf and b/panda/board/obj/body_h7/main.elf differ diff --git a/panda/board/obj/bootstub.body_h7.bin b/panda/board/obj/bootstub.body_h7.bin index 483da2c..4e81461 100755 Binary files a/panda/board/obj/bootstub.body_h7.bin and b/panda/board/obj/bootstub.body_h7.bin differ diff --git a/panda/board/obj/bootstub.panda_h7.bin b/panda/board/obj/bootstub.panda_h7.bin index aa26510..9d10111 100755 Binary files a/panda/board/obj/bootstub.panda_h7.bin and b/panda/board/obj/bootstub.panda_h7.bin differ diff --git a/panda/board/obj/bootstub.panda_jungle_h7.bin b/panda/board/obj/bootstub.panda_jungle_h7.bin index 5ffc678..b058f90 100755 Binary files a/panda/board/obj/bootstub.panda_jungle_h7.bin and b/panda/board/obj/bootstub.panda_jungle_h7.bin differ diff --git a/panda/board/obj/gitversion.h b/panda/board/obj/gitversion.h index 507c30f..085ff1e 100755 --- a/panda/board/obj/gitversion.h +++ b/panda/board/obj/gitversion.h @@ -1,2 +1,2 @@ extern const uint8_t gitversion[19]; -const uint8_t gitversion[19] = "DEV-5684dd9d-DEBUG"; +const uint8_t gitversion[19] = "DEV-63e9aa6c-DEBUG"; diff --git a/panda/board/obj/panda_h7.bin.signed b/panda/board/obj/panda_h7.bin.signed index e8c7620..f568d50 100644 Binary files a/panda/board/obj/panda_h7.bin.signed and b/panda/board/obj/panda_h7.bin.signed differ diff --git a/panda/board/obj/panda_h7/bootstub.elf b/panda/board/obj/panda_h7/bootstub.elf index 19394f6..b892a16 100755 Binary files a/panda/board/obj/panda_h7/bootstub.elf and b/panda/board/obj/panda_h7/bootstub.elf differ diff --git a/panda/board/obj/panda_h7/main.bin b/panda/board/obj/panda_h7/main.bin index a1a3adc..9419889 100755 Binary files a/panda/board/obj/panda_h7/main.bin and b/panda/board/obj/panda_h7/main.bin differ diff --git a/panda/board/obj/panda_h7/main.elf b/panda/board/obj/panda_h7/main.elf index 5802fc7..a9f63b4 100755 Binary files a/panda/board/obj/panda_h7/main.elf and b/panda/board/obj/panda_h7/main.elf differ diff --git a/panda/board/obj/panda_jungle_h7.bin.signed b/panda/board/obj/panda_jungle_h7.bin.signed index 5ed9596..380b3dc 100644 Binary files a/panda/board/obj/panda_jungle_h7.bin.signed and b/panda/board/obj/panda_jungle_h7.bin.signed differ diff --git a/panda/board/obj/panda_jungle_h7/bootstub.elf b/panda/board/obj/panda_jungle_h7/bootstub.elf index a3dab81..62b0fcd 100755 Binary files a/panda/board/obj/panda_jungle_h7/bootstub.elf and b/panda/board/obj/panda_jungle_h7/bootstub.elf differ diff --git a/panda/board/obj/panda_jungle_h7/main.bin b/panda/board/obj/panda_jungle_h7/main.bin index 37efe49..088d0be 100755 Binary files a/panda/board/obj/panda_jungle_h7/main.bin and b/panda/board/obj/panda_jungle_h7/main.bin differ diff --git a/panda/board/obj/panda_jungle_h7/main.elf b/panda/board/obj/panda_jungle_h7/main.elf index 6fdb80d..e9723dc 100755 Binary files a/panda/board/obj/panda_jungle_h7/main.elf and b/panda/board/obj/panda_jungle_h7/main.elf differ diff --git a/panda/board/obj/version b/panda/board/obj/version index 3de22dd..5950158 100755 --- a/panda/board/obj/version +++ b/panda/board/obj/version @@ -1 +1 @@ -DEV-5684dd9d-DEBUG \ No newline at end of file +DEV-63e9aa6c-DEBUG \ No newline at end of file diff --git a/panda/tests/libpanda/libpanda.so b/panda/tests/libpanda/libpanda.so index 23af64c..b94957c 100755 Binary files a/panda/tests/libpanda/libpanda.so and b/panda/tests/libpanda/libpanda.so differ