From 20db4525a21de0d29adb8938f2a26fc38971451b Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Wed, 16 Mar 2022 14:54:22 -0700 Subject: [PATCH] Fix controls mismatch on button enable cars + test against panda safety (#23975) * test models: check button enable cars against panda safety * gm too * cleanup --- panda | 2 +- selfdrive/car/honda/interface.py | 6 +++--- selfdrive/car/tests/test_models.py | 26 +++++++++++++------------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/panda b/panda index e6722c7f99b8f7..ba10911dbc0a6f 160000 --- a/panda +++ b/panda @@ -1 +1 @@ -Subproject commit e6722c7f99b8f7b9f81bb0216edb88cc2e5ad7c0 +Subproject commit ba10911dbc0a6f2c5c04886ca793f6ac38400cd3 diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index 040587be6f09bf..f7c1be72e8af25 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -403,9 +403,9 @@ def update(self, c, can_strings): for b in ret.buttonEvents: # do enable on both accel and decel buttons - if b.type in (ButtonType.accelCruise, ButtonType.decelCruise) and not b.pressed: - if not self.CP.pcmCruise: - events.add(EventName.buttonEnable) + if not self.CP.pcmCruise: + if b.type in (ButtonType.accelCruise, ButtonType.decelCruise) and not b.pressed: + events.add(EventName.buttonEnable) # do disable on button down if b.type == ButtonType.cancel and b.pressed: diff --git a/selfdrive/car/tests/test_models.py b/selfdrive/car/tests/test_models.py index 0b0a83e98b198c..71c9ac90d85702 100755 --- a/selfdrive/car/tests/test_models.py +++ b/selfdrive/car/tests/test_models.py @@ -50,9 +50,6 @@ class TestCarModel(unittest.TestCase): @classmethod def setUpClass(cls): - #if cls.car_model != "HONDA RIDGELINE 2017": - # raise unittest.SkipTest - if cls.route is None: if cls.car_model in non_tested_cars: print(f"Skipping tests for {cls.car_model}: missing route") @@ -63,11 +60,6 @@ def setUpClass(cls): params.clear_all() for seg in (2, 1, 0): - #from tools.lib.route import Route - #from tools.lib.logreader import MultiLogIterator - #r = Route("97bbe58ea225ad1d|2022-03-08--12-54-42") - #lr = MultiLogIterator(r.log_paths()[3:4]) - try: lr = LogReader(get_url(cls.route, seg)) except Exception: @@ -104,7 +96,7 @@ def setUp(self): # TODO: check safetyModel is in release panda build self.safety = libpandasafety_py.libpandasafety set_status = self.safety.set_safety_hooks(self.CP.safetyConfigs[0].safetyModel.raw, self.CP.safetyConfigs[0].safetyParam) - self.assertEqual(0, set_status, f"failed to set safetyModel {self.CP.safetyConfigs[0].safetyModel}") + self.assertEqual(0, set_status, f"failed to set safetyModel {self.CP.safetyConfigs}") self.safety.init_tests() def test_car_params(self): @@ -197,6 +189,10 @@ def test_panda_safety_carstate(self): self.safety.safety_rx_hook(to_send) self.CI.update(CC, (can_list_to_can_capnp([msg, ]), )) + if not self.CP.pcmCruise: + self.safety.set_controls_allowed(0) + + controls_allowed_prev = False CS_prev = car.CarState.new_message() checks = defaultdict(lambda: 0) for can in self.can_msgs: @@ -235,6 +231,14 @@ def test_panda_safety_carstate(self): checks['controlsAllowed'] += not self.safety.get_controls_allowed() else: checks['controlsAllowed'] += not CS.cruiseState.enabled and self.safety.get_controls_allowed() + else: + # Check for enable events on rising edge of controls allowed + button_enable = any(evt.enable for evt in CS.events) + mismatch = button_enable != (self.safety.get_controls_allowed() and not controls_allowed_prev) + checks['controlsAllowed'] += mismatch + controls_allowed_prev = self.safety.get_controls_allowed() + if button_enable and not mismatch: + self.safety.set_controls_allowed(False) if self.CP.carName == "honda": checks['mainOn'] += CS.cruiseState.available != self.safety.get_acc_main_on() @@ -245,10 +249,6 @@ def test_panda_safety_carstate(self): if self.CP.carFingerprint == TOYOTA.SIENNA and checks['brakePressed'] < 25: checks['brakePressed'] = 0 - # Honda Nidec uses button enable in panda, but pcm enable in openpilot - if self.CP.carName == "honda" and self.CP.carFingerprint not in HONDA_BOSCH and checks['controlsAllowed'] < 25: - checks['controlsAllowed'] = 0 - failed_checks = {k: v for k, v in checks.items() if v > 0} self.assertFalse(len(failed_checks), f"panda safety doesn't agree with openpilot: {failed_checks}")