opendbc icon indicating copy to clipboard operation
opendbc copied to clipboard

[$250 bounty] Move CAN ignition hooks and add test

Open adeebshihadeh opened this issue 9 months ago • 6 comments

CAN ignition lives in board/drivers/can_common.h. This is the last car-specific code in panda and should be moved here.

It should also be possible to fully validate these signals in CI. Assert that the hook doesn't unintentionally trip on all the other cars, etc.

adeebshihadeh avatar Feb 24 '25 21:02 adeebshihadeh

with proper rx checks (counter, checksum, etc.) to reduce chances of overlap between cars

sshane avatar Feb 24 '25 23:02 sshane

with proper rx checks (counter, checksum, etc.) to reduce chances of overlap between cars

Let's do this as a separate issue once this is in.

adeebshihadeh avatar Feb 24 '25 23:02 adeebshihadeh

@ccdunder want to tackle this one?

sshane avatar Mar 03 '25 23:03 sshane

@sshane I humbly propose https://github.com/commaai/opendbc/pull/2131

Lemme know what you think!

aubsw avatar Apr 15 '25 21:04 aubsw

I've been experimenting with adding CAN ignition coverage to test_models.py

In the experiment, we check every rx to ensure that only [gm|mazda|rivian|tesla] see CAN ignition. I.e.:

diff --git a/selfdrive/car/tests/test_models.py b/selfdrive/car/tests/test_models.py
index 53f2bb586..48b33b42b 100644
--- a/selfdrive/car/tests/test_models.py
+++ b/selfdrive/car/tests/test_models.py
@@ -243,6 +243,11 @@ class TestCarModelBase(unittest.TestCase):
         if self.safety.safety_rx_hook(to_send) != 1:
           failed_addrs[hex(msg.address)] += 1

+        if self.CP.brand in ("gm", "mazda", "rivian", "tesla"):
+          self.assertTrue(self.safety.get_ignition_can())
+        else:
+          self.assertFalse(self.safety.get_ignition_can())
+
       # ensure all msgs defined in the addr checks are valid
       self.safety.safety_tick_current_safety_config()
       if t > 1e6:

But there are two problems with this:

  1. assertFalse on every rx blows up the test run time from 6 mins to 15 mins
  2. Not every single message from the [gm|mazda|rivian|tesla] logs have ignition_can == True (see CI failure)

@sshane do you have a preferred way to deal with these problems? Here are some options:

  • (a) find different logs for [gm|mazda|rivian|tesla] where every rx has CAN-ignition
  • (b) instrument opendbc with a counter or a latch that triggers whenever CAN-ignition is detected, check this after all rxs are sent instead of after each individual rx

PRs in progress:

  • https://github.com/commaai/opendbc/pull/2131
  • https://github.com/commaai/panda/pull/2195
  • https://github.com/commaai/openpilot/pull/35082 (patches in the previous PRs so that we can exercise the newly-exposed can ignition state)

aubsw avatar Apr 26 '25 18:04 aubsw

can I work on this ?

rekudyu avatar Sep 27 '25 14:09 rekudyu