Skip to content

Commit

Permalink
Hyundai: match openpilot standstill check (#1586)
Browse files Browse the repository at this point in the history
* checks that we can replicate in openpilot

* clean up

* fix test

* can simplify this

* can also simplify this
  • Loading branch information
sshane authored Aug 17, 2023
1 parent cfff338 commit 1f475a8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions board/safety/safety_hyundai.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ static int hyundai_rx_hook(CANPacket_t *to_push) {

// sample wheel speed, averaging opposite corners
if (addr == 902) {
uint32_t hyundai_speed = (GET_BYTES(to_push, 0, 4) & 0x3FFFU) + ((GET_BYTES(to_push, 4, 4) >> 16) & 0x3FFFU); // FL + RR
hyundai_speed /= 2;
vehicle_moving = hyundai_speed > HYUNDAI_STANDSTILL_THRSLD;
uint32_t front_left_speed = GET_BYTES(to_push, 0, 2) & 0x3FFFU;
uint32_t rear_right_speed = GET_BYTES(to_push, 6, 2) & 0x3FFFU;
vehicle_moving = (front_left_speed > HYUNDAI_STANDSTILL_THRSLD) || (rear_right_speed > HYUNDAI_STANDSTILL_THRSLD);
}

if (addr == 916) {
Expand Down
8 changes: 3 additions & 5 deletions board/safety/safety_hyundai_canfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,9 @@ static int hyundai_canfd_rx_hook(CANPacket_t *to_push) {

// vehicle moving
if (addr == 0xa0) {
uint32_t speed = 0;
for (int i = 8; i < 15; i+=2) {
speed += GET_BYTE(to_push, i) | (GET_BYTE(to_push, i + 1) << 8U);
}
vehicle_moving = (speed / 4U) > HYUNDAI_STANDSTILL_THRSLD;
uint32_t front_left_speed = GET_BYTES(to_push, 8, 2);
uint32_t rear_right_speed = GET_BYTES(to_push, 14, 2);
vehicle_moving = (front_left_speed > HYUNDAI_STANDSTILL_THRSLD) || (rear_right_speed > HYUNDAI_STANDSTILL_THRSLD);
}
}

Expand Down
2 changes: 1 addition & 1 deletion board/safety/safety_hyundai_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const int HYUNDAI_PARAM_CAMERA_SCC = 8;
const int HYUNDAI_PARAM_ALT_LIMITS = 64; // TODO: shift this down with the rest of the common flags

const uint8_t HYUNDAI_PREV_BUTTON_SAMPLES = 8; // roughly 160 ms
const uint32_t HYUNDAI_STANDSTILL_THRSLD = 30; // ~1kph
const uint32_t HYUNDAI_STANDSTILL_THRSLD = 12; // 0.375 kph

enum {
HYUNDAI_BTN_NONE = 0,
Expand Down
2 changes: 1 addition & 1 deletion tests/safety/test_hyundai.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def checksum(msg):

class TestHyundaiSafety(HyundaiButtonBase, common.PandaSafetyTest, common.DriverTorqueSteeringSafetyTest):
TX_MSGS = [[832, 0], [1265, 0], [1157, 0]]
STANDSTILL_THRESHOLD = 30 # ~1kph
STANDSTILL_THRESHOLD = 12 # 0.375 kph
RELAY_MALFUNCTION_ADDR = 832
RELAY_MALFUNCTION_BUS = 0
FWD_BLACKLISTED_ADDRS = {2: [832, 1157]}
Expand Down
2 changes: 1 addition & 1 deletion tests/safety/test_hyundai_canfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class TestHyundaiCanfdBase(HyundaiButtonBase, common.PandaSafetyTest, common.DriverTorqueSteeringSafetyTest):

TX_MSGS = [[0x50, 0], [0x1CF, 1], [0x2A4, 0]]
STANDSTILL_THRESHOLD = 30 # ~1kph
STANDSTILL_THRESHOLD = 12 # 0.375 kph
RELAY_MALFUNCTION_ADDR = 0x50
RELAY_MALFUNCTION_BUS = 0
FWD_BLACKLISTED_ADDRS = {2: [0x50, 0x2a4]}
Expand Down

0 comments on commit 1f475a8

Please sign in to comment.