diff --git a/board/safety/safety_hyundai_canfd.h b/board/safety/safety_hyundai_canfd.h index b704becbb3..f590391d09 100644 --- a/board/safety/safety_hyundai_canfd.h +++ b/board/safety/safety_hyundai_canfd.h @@ -9,6 +9,13 @@ const SteeringLimits HYUNDAI_CANFD_STEERING_LIMITS = { .driver_torque_allowance = 250, .driver_torque_factor = 2, .type = TorqueDriverLimited, + + // the EPS faults when the steering angle is above a certain threshold for too long. to prevent this, + // we allow setting torque actuation bit to 0 while maintaining the requested torque value for two consecutive frames + .min_valid_request_frames = 89, + .max_invalid_request_frames = 2, + .min_valid_request_rt_interval = 810000, // 810ms; a ~10% buffer on cutting every 90 frames + .has_steer_req_tolerance = true, }; const CanMsg HYUNDAI_CANFD_HDA2_TX_MSGS[] = { @@ -205,10 +212,10 @@ static int hyundai_canfd_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed // steering const int steer_addr = (hyundai_canfd_hda2 && !hyundai_longitudinal) ? 0x50 : 0x12a; if (addr == steer_addr) { - int desired_torque = ((GET_BYTE(to_send, 6) & 0xFU) << 7U) | (GET_BYTE(to_send, 5) >> 1U); - desired_torque -= 1024; + int desired_torque = (((GET_BYTE(to_send, 6) & 0xFU) << 7U) | (GET_BYTE(to_send, 5) >> 1U)) - 1024; + bool steer_req = GET_BIT(to_send, 52U) != 0U; - if (steer_torque_cmd_checks(desired_torque, -1, HYUNDAI_CANFD_STEERING_LIMITS)) { + if (steer_torque_cmd_checks(desired_torque, steer_req, HYUNDAI_CANFD_STEERING_LIMITS)) { tx = 0; } } diff --git a/tests/safety/test_hyundai_canfd.py b/tests/safety/test_hyundai_canfd.py index ee1ee341b1..fa058efb0c 100755 --- a/tests/safety/test_hyundai_canfd.py +++ b/tests/safety/test_hyundai_canfd.py @@ -25,6 +25,11 @@ class TestHyundaiCanfdBase(HyundaiButtonBase, common.PandaSafetyTest, common.Dri DRIVER_TORQUE_ALLOWANCE = 250 DRIVER_TORQUE_FACTOR = 2 + # Safety around steering req bit + MIN_VALID_STEERING_FRAMES = 89 + MAX_INVALID_STEERING_FRAMES = 2 + MIN_VALID_STEERING_RT_INTERVAL = 810000 # a ~10% buffer, can send steer up to 110Hz + PT_BUS = 0 STEER_BUS = 0 STEER_MSG = "" @@ -41,7 +46,7 @@ def _torque_driver_msg(self, torque): return self.packer.make_can_msg_panda("MDPS", self.PT_BUS, values) def _torque_cmd_msg(self, torque, steer_req=1): - values = {"TORQUE_REQUEST": torque} + values = {"TORQUE_REQUEST": torque, "STEER_REQ": steer_req} return self.packer.make_can_msg_panda(self.STEER_MSG, self.STEER_BUS, values) def _speed_msg(self, speed):