Skip to content

Commit b2e4904

Browse files
committed
Pr suggestions
1 parent 8521e18 commit b2e4904

File tree

3 files changed

+31
-35
lines changed

3 files changed

+31
-35
lines changed

opendbc/safety/modes/toyota.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static bool toyota_tx_hook(const CANPacket_t *msg) {
216216
if (toyota_secoc) {
217217
// SecOC cars move accel to 0x183. Only allow inactive accel on 0x343 to match stock behavior
218218
violation = desired_accel != TOYOTA_LONG_LIMITS.inactive_accel;
219-
}
219+
}
220220
violation |= longitudinal_accel_checks(desired_accel, TOYOTA_LONG_LIMITS);
221221

222222
// only ACC messages that cancel are allowed when openpilot is not controlling longitudinal

opendbc/safety/tests/common.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,6 @@ def setUpClass(cls):
150150
def _accel_msg(self, accel: float):
151151
pass
152152

153-
def _accel_msg_2(self, accel: float):
154-
return None
155-
156-
def _should_tx_1(self, controls_allowed: bool, accel: float, min_accel: float, max_accel: float):
157-
if self.LONGITUDINAL:
158-
should_tx = controls_allowed and min_accel <= accel <= max_accel
159-
should_tx = should_tx or accel == self.INACTIVE_ACCEL
160-
else:
161-
should_tx = False
162-
return should_tx
163-
164-
def _should_tx_2(self, controls_allowed: bool, accel: float, min_accel: float, max_accel: float):
165-
return False
166-
167153
def test_accel_limits_correct(self):
168154
self.assertGreater(self.MAX_ACCEL, 0)
169155
self.assertLess(self.MIN_ACCEL, 0)
@@ -179,12 +165,12 @@ def test_accel_actuation_limits(self):
179165
for controls_allowed in [True, False]:
180166
self.safety.set_controls_allowed(controls_allowed)
181167
self.safety.set_alternative_experience(alternative_experience)
182-
should_tx = self._should_tx_1(controls_allowed, accel, min_accel, max_accel)
168+
if self.LONGITUDINAL:
169+
should_tx = controls_allowed and min_accel <= accel <= max_accel
170+
should_tx = should_tx or accel == self.INACTIVE_ACCEL
171+
else:
172+
should_tx = False
183173
self.assertEqual(should_tx, self._tx(self._accel_msg(accel)))
184-
accel_msg_2 = self._accel_msg_2(accel)
185-
if accel_msg_2 is not None:
186-
should_tx_2 = self._should_tx_2(controls_allowed, accel, min_accel, max_accel)
187-
self.assertEqual(should_tx_2, self._tx(self._accel_msg_2(accel)))
188174

189175

190176
class LongitudinalGasBrakeSafetyTest(PandaSafetyTestBase, abc.ABC):

opendbc/safety/tests/test_toyota.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,17 @@ def _lta_msg(self, req, req2, angle_cmd, torque_wind_down=100):
5252
values = {"STEER_REQUEST": req, "STEER_REQUEST_2": req2, "STEER_ANGLE_CMD": angle_cmd, "TORQUE_WIND_DOWN": torque_wind_down}
5353
return self.packer.make_can_msg_panda("STEERING_LTA", 0, values)
5454

55-
def _accel_msg(self, accel, cancel_req=0):
55+
def _accel_msg_343(self, accel, cancel_req=0):
5656
values = {"ACCEL_CMD": accel, "CANCEL_REQ": cancel_req}
5757
return self.packer.make_can_msg_panda("ACC_CONTROL", 0, values)
5858

59+
def _accel_msg_183(self, accel):
60+
values = {"ACCEL_CMD": accel}
61+
return self.packer.make_can_msg_panda("ACC_CONTROL_2", 0, values)
62+
63+
def _accel_msg(self, accel, cancel_req=0):
64+
return self._accel_msg_343(accel, cancel_req)
65+
5966
def _speed_msg(self, speed):
6067
values = {("WHEEL_SPEED_%s" % n): speed * 3.6 for n in ["FR", "FL", "RR", "RL"]}
6168
return self.packer.make_can_msg_panda("WHEEL_SPEEDS", 0, values)
@@ -285,9 +292,9 @@ def test_acc_cancel(self):
285292
for controls_allowed in [True, False]:
286293
self.safety.set_controls_allowed(controls_allowed)
287294
for accel in np.arange(self.MIN_ACCEL - 1, self.MAX_ACCEL + 1, 0.1):
288-
self.assertFalse(self._tx(self._accel_msg(accel)))
289-
should_tx = np.isclose(accel, 0, atol=0.0001)
290-
self.assertEqual(should_tx, self._tx(self._accel_msg(accel, cancel_req=1)))
295+
self.assertFalse(self._tx(self._accel_msg_343(accel)))
296+
should_tx = np.isclose(accel, self.INACTIVE_ACCEL, atol=0.0001)
297+
self.assertEqual(should_tx, self._tx(self._accel_msg_343(accel, cancel_req=1)))
291298

292299

293300
class TestToyotaStockLongitudinalTorque(TestToyotaStockLongitudinalBase, TestToyotaSafetyTorque):
@@ -345,6 +352,9 @@ def test_lta_2_steer_cmd(self):
345352
should_tx = not req and not req2 and angle == 0
346353
self.assertEqual(should_tx, self._tx(self._lta_2_msg(req, req2, angle)), f"{req=} {req2=} {angle=}")
347354

355+
def _accel_msg(self, accel, cancel_req=0):
356+
return self._accel_msg_183(accel)
357+
348358

349359
class TestToyotaSecOcSafetyStockLongitudinal(TestToyotaSecOcSafetyBase, TestToyotaStockLongitudinalBase):
350360

@@ -371,17 +381,17 @@ def setUp(self):
371381
def test_block_aeb(self, stock_longitudinal: bool = False):
372382
pass
373383

374-
def _accel_msg_2(self, accel):
375-
values = {"ACCEL_CMD": accel}
376-
return self.packer.make_can_msg_panda("ACC_CONTROL_2", 0, values)
377-
378-
# On a SecOC vehicle, we still transmit ACC_CONTROL but the accel value moves to ACC_CONTROL_2
379-
# Verify that all non-idle accel values in ACC_CONTROL are rejected, verify ACC_CONTROL_2 accel normally
380-
def _should_tx_1(self, controls_allowed: bool, accel: float, min_accel: float, max_accel: float):
381-
return accel == self.INACTIVE_ACCEL
382-
383-
def _should_tx_2(self, controls_allowed: bool, accel: float, min_accel: float, max_accel: float):
384-
return (controls_allowed and min_accel <= accel <= max_accel) or accel == self.INACTIVE_ACCEL
384+
def test_343_actuation_blocked(self):
385+
"""
386+
For SecOC cars, longitudinal acceleration must be sent in ACC_CONTROL_2, but all other ACC
387+
data remains in ACC_CONTROL. Verify no actuation is sent via ACC_CONTROL.
388+
"""
389+
for controls_allowed in [True, False]:
390+
self.safety.set_controls_allowed(controls_allowed)
391+
for accel in np.arange(self.MIN_ACCEL - 1, self.MAX_ACCEL + 1, 0.1):
392+
should_tx = np.isclose(accel, self.INACTIVE_ACCEL, atol=0.0001)
393+
self.assertEqual(should_tx, self._tx(self._accel_msg_343(accel)), f"accel: {accel=}, {controls_allowed=}, {should_tx=}")
394+
self.assertEqual(should_tx, self._tx(self._accel_msg_343(accel, cancel_req=1)))
385395

386396

387397
if __name__ == "__main__":

0 commit comments

Comments
 (0)