Skip to content

Commit

Permalink
GM: change brake pressed signal (#1089)
Browse files Browse the repository at this point in the history
* Match openpilot brake check

* comment

* simple

* Update test

* doesn't take an int

* msg varies in size by platform

* 2 extra bytes of zeros on Escalade

* label platforms

* space
  • Loading branch information
sshane authored Oct 7, 2022
1 parent c09a1cd commit 1303af2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
12 changes: 7 additions & 5 deletions board/safety/safety_gm.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ AddrCheckStruct gm_addr_checks[] = {
{.msg = {{388, 0, 8, .expected_timestep = 100000U}, { 0 }, { 0 }}},
{.msg = {{842, 0, 5, .expected_timestep = 100000U}, { 0 }, { 0 }}},
{.msg = {{481, 0, 7, .expected_timestep = 100000U}, { 0 }, { 0 }}},
{.msg = {{241, 0, 6, .expected_timestep = 100000U}, { 0 }, { 0 }}},
{.msg = {{190, 0, 6, .expected_timestep = 100000U}, // Volt, Silverado, Acadia Denali
{190, 0, 7, .expected_timestep = 100000U}, // Bolt EUV
{190, 0, 8, .expected_timestep = 100000U}}}, // Escalade
{.msg = {{452, 0, 8, .expected_timestep = 100000U}, { 0 }, { 0 }}},
};
#define GM_RX_CHECK_LEN (sizeof(gm_addr_checks) / sizeof(gm_addr_checks[0]))
Expand Down Expand Up @@ -89,10 +91,10 @@ static int gm_rx_hook(CANPacket_t *to_push) {
cruise_button_prev = button;
}

if (addr == 241) {
// Brake pedal's potentiometer returns near-zero reading
// even when pedal is not pressed
brake_pressed = GET_BYTE(to_push, 1) >= 10U;
if (addr == 190) {
// Reference for signal and threshold:
// https://github.com/commaai/openpilot/blob/master/selfdrive/car/gm/carstate.py
brake_pressed = GET_BYTE(to_push, 1) >= 8U;
}

if (addr == 452) {
Expand Down
10 changes: 5 additions & 5 deletions tests/safety/test_gm.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def _speed_msg(self, speed):
return self.packer.make_can_msg_panda("EBCMWheelSpdRear", 0, values)

def _user_brake_msg(self, brake):
# GM safety has a brake threshold of 10
values = {"BrakePedalPosition": 10 if brake else 0}
return self.packer.make_can_msg_panda("EBCMBrakePedalPosition", 0, values)
# GM safety has a brake threshold of 8
values = {"BrakePedalPos": 8 if brake else 0}
return self.packer.make_can_msg_panda("ECMAcceleratorPos", 0, values)

def _user_regen_msg(self, regen):
values = {"RegenPaddle": 2 if regen else 0}
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_tx_hook_on_pedal_pressed(self):
if pedal == 'brake':
# brake_pressed_prev and vehicle_moving
self._rx(self._speed_msg(100))
self._rx(self._user_brake_msg(MAX_BRAKE))
self._rx(self._user_brake_msg(1))
elif pedal == 'gas':
# gas_pressed_prev
self._rx(self._user_gas_msg(MAX_GAS))
Expand All @@ -135,7 +135,7 @@ def test_tx_hook_on_pedal_pressed_on_alternative_gas_experience(self):
if pedal == 'brake':
# brake_pressed_prev and vehicle_moving
self._rx(self._speed_msg(100))
self._rx(self._user_brake_msg(MAX_BRAKE))
self._rx(self._user_brake_msg(1))
allow_ctrl = False
elif pedal == 'gas':
# gas_pressed_prev
Expand Down

0 comments on commit 1303af2

Please sign in to comment.