Skip to content

Commit eac8676

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

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

tests/safety/common.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ 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+
return (controls_allowed and min_accel <= accel <= max_accel) or accel == self.INACTIVE_ACCEL
142+
143+
def _should_tx_2(self, controls_allowed: bool, stock_longitudinal: bool, accel: float, min_accel: float, max_accel: float):
144+
return None
145+
137146
def test_accel_limits_correct(self):
138147
self.assertGreater(self.MAX_ACCEL, 0)
139148
self.assertLess(self.MIN_ACCEL, 0)
@@ -149,12 +158,12 @@ def test_accel_actuation_limits(self, stock_longitudinal=False):
149158
for controls_allowed in [True, False]:
150159
self.safety.set_controls_allowed(controls_allowed)
151160
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
161+
should_tx = self._should_tx_1(controls_allowed, stock_longitudinal, accel, min_accel, max_accel)
157162
self.assertEqual(should_tx, self._tx(self._accel_msg(accel)))
163+
accel_msg_2 = self._accel_msg_2(accel)
164+
if accel_msg_2 is not None:
165+
should_tx_2 = self._should_tx_2(controls_allowed, stock_longitudinal, accel, min_accel, max_accel)
166+
self.assertEqual(should_tx_2, self._tx(self._accel_msg_2(accel)))
158167

159168

160169
class LongitudinalGasBrakeSafetyTest(PandaSafetyTestBase, abc.ABC):

tests/safety/test_toyota.py

Lines changed: 15 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,21 @@ 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+
if stock_longitudinal:
376+
should_tx = False
377+
else:
378+
should_tx = controls_allowed and min_accel <= accel <= max_accel
379+
should_tx = should_tx or accel == self.INACTIVE_ACCEL
380+
return should_tx
381+
370382
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)))
383+
super().test_accel_actuation_limits(stock_longitudinal=stock_longitudinal)
387384

388385

389386
if __name__ == "__main__":

0 commit comments

Comments
 (0)