From 5962bcd08ae4e7c5193535efb45cc9c39da52f54 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 14 Oct 2022 16:51:53 -0700 Subject: [PATCH] GM: different brake thresholds by platform (#1104) * Different brake pressed thresholds * Update board/safety/safety_gm.h --- board/safety/safety_gm.h | 8 ++++++-- tests/safety/test_gm.py | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/board/safety/safety_gm.h b/board/safety/safety_gm.h index c9560d5ab7..534e28362c 100644 --- a/board/safety/safety_gm.h +++ b/board/safety/safety_gm.h @@ -93,9 +93,13 @@ static int gm_rx_hook(CANPacket_t *to_push) { } if (addr == 190) { - // Reference for signal and threshold: + // Reference for signal and thresholds: // https://github.com/commaai/openpilot/blob/master/selfdrive/car/gm/carstate.py - brake_pressed = GET_BYTE(to_push, 1) >= 8U; + if (gm_hw == GM_ASCM) { + brake_pressed = GET_BYTE(to_push, 1) >= 8U; + } else { + brake_pressed = GET_BYTE(to_push, 1) >= 20U; + } } if (addr == 452) { diff --git a/tests/safety/test_gm.py b/tests/safety/test_gm.py index c5b9141584..0ac2999170 100755 --- a/tests/safety/test_gm.py +++ b/tests/safety/test_gm.py @@ -23,6 +23,7 @@ class TestGmSafetyBase(common.PandaSafetyTest, common.DriverTorqueSteeringSafety RELAY_MALFUNCTION_ADDR = 384 RELAY_MALFUNCTION_BUS = 0 BUTTONS_BUS = 0 + USER_BRAKE_THRESHOLD = 0 MAX_RATE_UP = 7 MAX_RATE_DOWN = 17 @@ -55,7 +56,7 @@ def _speed_msg(self, speed): def _user_brake_msg(self, brake): # GM safety has a brake threshold of 8 - values = {"BrakePedalPos": 8 if brake else 0} + values = {"BrakePedalPos": self.USER_BRAKE_THRESHOLD if brake else 0} return self.packer.make_can_msg_panda("ECMAcceleratorPos", 0, values) def _user_regen_msg(self, regen): @@ -163,6 +164,7 @@ class TestGmAscmSafety(TestGmSafetyBase): [0x104c006c, 3], [0x10400060, 3]] # gmlan FWD_BLACKLISTED_ADDRS: Dict[int, List[int]] = {} FWD_BUS_LOOKUP: Dict[int, int] = {} + USER_BRAKE_THRESHOLD = 8 def setUp(self): self.packer = CANPackerPanda("gm_global_a_powertrain_generated") @@ -210,6 +212,7 @@ class TestGmCameraSafety(TestGmSafetyBase): FWD_BLACKLISTED_ADDRS = {2: [384]} # LKAS message, ACC messages are (715, 880, 789) FWD_BUS_LOOKUP = {0: 2, 2: 0} BUTTONS_BUS = 2 # tx only + USER_BRAKE_THRESHOLD = 20 def setUp(self): self.packer = CANPackerPanda("gm_global_a_powertrain_generated")