Skip to content

Commit

Permalink
Honda: add latching AEB test (commaai#1704)
Browse files Browse the repository at this point in the history
* use get bit

* simplify parsing

* add get_honda_fwd_brake for latching test

rm print

* can also test with txing brake

* Revert "can also test with txing brake"

This reverts commit f75eb6e.

* rm this
  • Loading branch information
sshane authored Nov 1, 2023
1 parent bc69d25 commit d2f9e14
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
4 changes: 2 additions & 2 deletions board/safety/safety_honda.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ static int honda_rx_hook(CANPacket_t *to_push) {
// disable stock Honda AEB in alternative experience
if (!(alternative_experience & ALT_EXP_DISABLE_STOCK_AEB)) {
if ((bus == 2) && (addr == 0x1FA)) {
bool honda_stock_aeb = GET_BYTE(to_push, 3) & 0x20U;
int honda_stock_brake = (GET_BYTE(to_push, 0) << 2) + ((GET_BYTE(to_push, 1) >> 6) & 0x3U);
bool honda_stock_aeb = GET_BIT(to_push, 29U) != 0U;
int honda_stock_brake = (GET_BYTE(to_push, 0) << 2) | (GET_BYTE(to_push, 1) >> 6);

// Forward AEB when stock braking is higher than openpilot braking
// only stop forwarding when AEB event is over
Expand Down
4 changes: 4 additions & 0 deletions tests/libpanda/safety_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ void set_honda_fwd_brake(bool c){
honda_fwd_brake = c;
}

bool get_honda_fwd_brake(void){
return honda_fwd_brake;
}

void init_tests(void){
// get HW_TYPE from env variable set in test.sh
if (getenv("HW_TYPE")) {
Expand Down
2 changes: 2 additions & 0 deletions tests/libpanda/safety_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def setup_safety_helpers(ffi):
void init_tests(void);
void set_honda_fwd_brake(bool c);
bool get_honda_fwd_brake(void);
void set_honda_alt_brake_msg(bool c);
void set_honda_bosch_long(bool c);
int get_honda_hw(void);
Expand Down Expand Up @@ -97,6 +98,7 @@ def addr_checks_valid(self) -> bool: ...
def init_tests(self) -> None: ...

def set_honda_fwd_brake(self, c: bool) -> None: ...
def get_honda_fwd_brake(self) -> bool: ...
def set_honda_alt_brake_msg(self, c: bool) -> None: ...
def set_honda_bosch_long(self, c: bool) -> None: ...
def get_honda_hw(self) -> int: ...
Expand Down
37 changes: 31 additions & 6 deletions tests/safety/test_honda.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def test_buttons(self):


class HondaBase(common.PandaSafetyTest):
MAX_BRAKE: float = 255
MAX_BRAKE = 255
PT_BUS: Optional[int] = None # must be set when inherited
STEER_BUS: Optional[int] = None # must be set when inherited
BUTTONS_BUS: Optional[int] = None # must be set when inherited, tx on this bus, rx on PT_BUS
Expand Down Expand Up @@ -288,9 +288,12 @@ def _interceptor_gas_cmd(self, gas):
def _interceptor_user_gas(self, gas):
return interceptor_msg(gas, 0x201)

def _send_brake_msg(self, brake):
values = {"COMPUTER_BRAKE": brake}
return self.packer.make_can_msg_panda("BRAKE_COMMAND", 0, values)
def _send_brake_msg(self, brake, aeb_req=0, bus=0):
values = {"COMPUTER_BRAKE": brake, "AEB_REQ_1": aeb_req}
return self.packer.make_can_msg_panda("BRAKE_COMMAND", bus, values)

def _rx_brake_msg(self, brake, aeb_req=0):
return self._send_brake_msg(brake, aeb_req, bus=2)

def _send_acc_hud_msg(self, pcm_gas, pcm_speed):
# Used to control ACC on Nidec without pedal
Expand All @@ -311,12 +314,35 @@ def test_fwd_hook(self):
self.safety.set_honda_fwd_brake(False)
super().test_fwd_hook()

# TODO: test latching until AEB event is over?
# forwarding AEB brake signal
self.FWD_BLACKLISTED_ADDRS = {2: [0xE4, 0x194, 0x33D, 0x30C]}
self.safety.set_honda_fwd_brake(True)
super().test_fwd_hook()

def test_honda_fwd_brake_latching(self):
# Shouldn't fwd stock Honda requesting brake without AEB
self.assertTrue(self._rx(self._rx_brake_msg(self.MAX_BRAKE, aeb_req=0)))
self.assertFalse(self.safety.get_honda_fwd_brake())

# Now allow controls and request some brake
openpilot_brake = round(self.MAX_BRAKE / 2.0)
self.safety.set_controls_allowed(True)
self.assertTrue(self._tx(self._send_brake_msg(openpilot_brake)))

# Still shouldn't fwd stock Honda brake until it's more than openpilot's
for stock_honda_brake in range(self.MAX_BRAKE + 1):
self.assertTrue(self._rx(self._rx_brake_msg(stock_honda_brake, aeb_req=1)))
should_fwd_brake = stock_honda_brake >= openpilot_brake
self.assertEqual(should_fwd_brake, self.safety.get_honda_fwd_brake())

# Shouldn't stop fwding until AEB event is over
for stock_honda_brake in range(self.MAX_BRAKE + 1)[::-1]:
self.assertTrue(self._rx(self._rx_brake_msg(stock_honda_brake, aeb_req=1)))
self.assertTrue(self.safety.get_honda_fwd_brake())

self.assertTrue(self._rx(self._rx_brake_msg(0, aeb_req=0)))
self.assertFalse(self.safety.get_honda_fwd_brake())

def test_brake_safety_check(self):
for fwd_brake in [False, True]:
self.safety.set_honda_fwd_brake(fwd_brake)
Expand All @@ -330,7 +356,6 @@ def test_brake_safety_check(self):
else:
send = brake == 0
self.assertEqual(send, self._tx(self._send_brake_msg(brake)))
self.safety.set_honda_fwd_brake(False)


class TestHondaNidecSafety(HondaPcmEnableBase, TestHondaNidecSafetyBase):
Expand Down

0 comments on commit d2f9e14

Please sign in to comment.