Skip to content

Commit

Permalink
Fix controls mismatch on button enable cars + test against panda safe…
Browse files Browse the repository at this point in the history
…ty (commaai#23975)

* test models: check button enable cars against panda safety

* gm too

* cleanup
# Conflicts:
#	panda
  • Loading branch information
adeebshihadeh authored and budney committed Mar 28, 2022
1 parent d6f91df commit 594d187
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions selfdrive/car/honda/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 13 additions & 13 deletions selfdrive/car/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand All @@ -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}")

Expand Down

0 comments on commit 594d187

Please sign in to comment.