Skip to content

Commit 60577b3

Browse files
committed
Initial attempt at 2 accel msg testing
1 parent 6cc54a5 commit 60577b3

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

tests/safety/common.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,20 @@ def setUpClass(cls):
134134
def _accel_msg(self, accel: float):
135135
pass
136136

137+
def _accel_msg_2(self, accel: float):
138+
return None
139+
140+
def _should_tx_1(self, controls_allowed: bool, stock_longitudinal: bool, accel: float, min_accel: float, max_accel: float):
141+
if stock_longitudinal:
142+
should_tx = False
143+
else:
144+
should_tx = controls_allowed and min_accel <= accel <= max_accel
145+
should_tx = should_tx or accel == self.INACTIVE_ACCEL
146+
return should_tx
147+
148+
def _should_tx_2(self, controls_allowed: bool, stock_longitudinal: bool, accel: float, min_accel: float, max_accel: float):
149+
return False
150+
137151
def test_accel_limits_correct(self):
138152
self.assertGreater(self.MAX_ACCEL, 0)
139153
self.assertLess(self.MIN_ACCEL, 0)
@@ -149,12 +163,12 @@ def test_accel_actuation_limits(self, stock_longitudinal=False):
149163
for controls_allowed in [True, False]:
150164
self.safety.set_controls_allowed(controls_allowed)
151165
self.safety.set_alternative_experience(alternative_experience)
152-
if stock_longitudinal:
153-
should_tx = False
154-
else:
155-
should_tx = controls_allowed and min_accel <= accel <= max_accel
156-
should_tx = should_tx or accel == self.INACTIVE_ACCEL
166+
should_tx = self._should_tx_1(controls_allowed, stock_longitudinal, accel, min_accel, max_accel)
157167
self.assertEqual(should_tx, self._tx(self._accel_msg(accel)))
168+
accel_msg_2 = self._accel_msg_2(accel)
169+
if accel_msg_2 is not None:
170+
should_tx_2 = self._should_tx_2(controls_allowed, stock_longitudinal, accel, min_accel, max_accel)
171+
self.assertEqual(should_tx_2, self._tx(self._accel_msg_2(accel)))
158172

159173

160174
class LongitudinalGasBrakeSafetyTest(PandaSafetyTestBase, abc.ABC):

tests/safety/test_toyota.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import unittest
55
import itertools
66

7-
from panda import Panda, ALTERNATIVE_EXPERIENCE
7+
from panda import Panda
88
from panda.tests.libpanda import libpanda_py
99
import panda.tests.safety.common as common
1010
from panda.tests.safety.common import CANPackerPanda
@@ -366,24 +366,16 @@ def _accel_2_msg(self, accel, cancel_req=0):
366366
values = {"ACCEL_CMD": accel}
367367
return self.packer.make_can_msg_panda("ACC_CONTROL_2", 0, values)
368368

369-
# FIXME: Replaces common test, refactor common tests to handle this situation better?
369+
# On a SecOC vehicle, we still transmit ACC_CONTROL but the accel value moves to ACC_CONTROL_2
370+
# Verify that all non-idle accel values in ACC_CONTROL are rejected, verify ACC_CONTROL_2 accel normally
371+
def _should_tx_1(self, controls_allowed: bool, stock_longitudinal: bool, accel: float, min_accel: float, max_accel: float):
372+
return accel == self.INACTIVE_ACCEL
373+
374+
def _should_tx_2(self, controls_allowed: bool, stock_longitudinal: bool, accel: float, min_accel: float, max_accel: float):
375+
return (controls_allowed and min_accel <= accel <= max_accel) or accel == self.INACTIVE_ACCEL
376+
370377
def test_accel_actuation_limits(self, stock_longitudinal=False):
371-
limits = ((self.MIN_ACCEL, self.MAX_ACCEL, ALTERNATIVE_EXPERIENCE.DEFAULT),
372-
(self.MIN_ACCEL, self.MAX_ACCEL, ALTERNATIVE_EXPERIENCE.RAISE_LONGITUDINAL_LIMITS_TO_ISO_MAX))
373-
374-
for min_accel, max_accel, alternative_experience in limits:
375-
# enforce we don't skip over 0 or inactive accel
376-
for accel in np.concatenate((np.arange(min_accel - 1, max_accel + 1, 0.05), [0, self.INACTIVE_ACCEL])):
377-
accel = round(accel, 2) # floats might not hit exact boundary conditions without rounding
378-
for controls_allowed in [True, False]:
379-
self.safety.set_controls_allowed(controls_allowed)
380-
self.safety.set_alternative_experience(alternative_experience)
381-
# On a SecOC vehicle, we still transmit ACC_CONTROL but the accel value moves to ACC_CONTROL_2
382-
# Verify that all non-idle accel values in ACC_CONTROL are rejected, verify ACC_CONTROL_2 accel normally
383-
should_tx_1 = accel == self.INACTIVE_ACCEL
384-
should_tx_2 = (controls_allowed and min_accel <= accel <= max_accel) or accel == self.INACTIVE_ACCEL
385-
self.assertEqual(should_tx_1, self._tx(self._accel_msg(accel)))
386-
self.assertEqual(should_tx_2, self._tx(self._accel_2_msg(accel)))
378+
super().test_accel_actuation_limits(stock_longitudinal=stock_longitudinal)
387379

388380

389381
if __name__ == "__main__":

0 commit comments

Comments
 (0)