Skip to content

Commit

Permalink
h90d CAN-FD
Browse files Browse the repository at this point in the history
  • Loading branch information
sshane committed Oct 12, 2022
1 parent ffb3109 commit 7d520aa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 9 additions & 1 deletion board/safety/safety_hyundai_canfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 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[] = {
Expand Down Expand Up @@ -205,9 +212,10 @@ static int hyundai_canfd_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed
// steering
if ((addr == 0x50) || (addr == 0x12a)) {
int desired_torque = ((GET_BYTE(to_send, 6) & 0xFU) << 7U) | (GET_BYTE(to_send, 5) >> 1U);
bool steer_req = GET_BIT(to_send, 52U) != 0U;
desired_torque -= 1024;

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;
}
}
Expand Down
7 changes: 6 additions & 1 deletion tests/safety/test_hyundai_canfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand All @@ -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):
Expand Down

0 comments on commit 7d520aa

Please sign in to comment.