This commit is contained in:
Shane Smiskol 2023-10-03 23:52:16 -07:00
parent 4c5931815d
commit c48473d9b6
2 changed files with 44 additions and 48 deletions

View File

@ -434,8 +434,7 @@ class TestFordLongitudinalSafetyBase(TestFordSafetyBase):
for brake in np.arange(self.MIN_ACCEL - 2, self.MAX_ACCEL + 2, 0.05):
brake = round(brake, 2) # floats might not hit exact boundary conditions without rounding
should_tx = (controls_allowed and self.MIN_ACCEL <= brake <= self.MAX_ACCEL) or brake == self.INACTIVE_ACCEL
tx = self._tx(self._acc_command_msg(self.INACTIVE_GAS, brake))
self.assertEqual(should_tx, tx, (controls_allowed, brake))
self.assertEqual(should_tx, self._tx(self._acc_command_msg(self.INACTIVE_GAS, brake)))
class TestFordLongitudinalSafety(TestFordLongitudinalSafetyBase):
@ -453,19 +452,19 @@ class TestFordLongitudinalSafety(TestFordLongitudinalSafetyBase):
self.safety.init_tests()
# class TestFordCANFDLongitudinalSafety(TestFordLongitudinalSafetyBase):
# STEER_MESSAGE = MSG_LateralMotionControl2
#
# TX_MSGS = [
# [MSG_Steering_Data_FD1, 0], [MSG_Steering_Data_FD1, 2], [MSG_ACCDATA, 0], [MSG_ACCDATA_3, 0], [MSG_Lane_Assist_Data1, 0],
# [MSG_LateralMotionControl2, 0], [MSG_IPMA_Data, 0],
# ]
#
# def setUp(self):
# self.packer = CANPackerPanda("ford_lincoln_base_pt")
# self.safety = libpanda_py.libpanda
# self.safety.set_safety_hooks(Panda.SAFETY_FORD, Panda.FLAG_FORD_LONG_CONTROL | Panda.FLAG_FORD_CANFD)
# self.safety.init_tests()
class TestFordCANFDLongitudinalSafety(TestFordLongitudinalSafetyBase):
STEER_MESSAGE = MSG_LateralMotionControl2
TX_MSGS = [
[MSG_Steering_Data_FD1, 0], [MSG_Steering_Data_FD1, 2], [MSG_ACCDATA, 0], [MSG_ACCDATA_3, 0], [MSG_Lane_Assist_Data1, 0],
[MSG_LateralMotionControl2, 0], [MSG_IPMA_Data, 0],
]
def setUp(self):
self.packer = CANPackerPanda("ford_lincoln_base_pt")
self.safety = libpanda_py.libpanda
self.safety.set_safety_hooks(Panda.SAFETY_FORD, Panda.FLAG_FORD_LONG_CONTROL | Panda.FLAG_FORD_CANFD)
self.safety.init_tests()
if __name__ == "__main__":

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3
import time
import unittest
import numpy as np
from panda import Panda
@ -114,24 +113,24 @@ class TestTeslaLongitudinalSafety(TestTeslaSafety):
def setUp(self):
raise unittest.SkipTest
# def test_no_aeb(self):
# for aeb_event in range(4):
# self.assertEqual(self._tx(self._long_control_msg(10, aeb_event=aeb_event)), aeb_event == 0)
def test_no_aeb(self):
for aeb_event in range(4):
self.assertEqual(self._tx(self._long_control_msg(10, aeb_event=aeb_event)), aeb_event == 0)
# def test_stock_aeb_passthrough(self):
# no_aeb_msg = self._long_control_msg(10, aeb_event=0)
# no_aeb_msg_cam = self._long_control_msg(10, aeb_event=0, bus=2)
# aeb_msg_cam = self._long_control_msg(10, aeb_event=1, bus=2)
#
# # stock system sends no AEB -> no forwarding, and OP is allowed to TX
# self.assertEqual(1, self._rx(no_aeb_msg_cam))
# self.assertEqual(-1, self.safety.safety_fwd_hook(2, no_aeb_msg_cam.addr))
# self.assertEqual(True, self._tx(no_aeb_msg))
#
# # stock system sends AEB -> forwarding, and OP is not allowed to TX
# self.assertEqual(1, self._rx(aeb_msg_cam))
# self.assertEqual(0, self.safety.safety_fwd_hook(2, aeb_msg_cam.addr))
# self.assertEqual(False, self._tx(no_aeb_msg))
def test_stock_aeb_passthrough(self):
no_aeb_msg = self._long_control_msg(10, aeb_event=0)
no_aeb_msg_cam = self._long_control_msg(10, aeb_event=0, bus=2)
aeb_msg_cam = self._long_control_msg(10, aeb_event=1, bus=2)
# stock system sends no AEB -> no forwarding, and OP is allowed to TX
self.assertEqual(1, self._rx(no_aeb_msg_cam))
self.assertEqual(-1, self.safety.safety_fwd_hook(2, no_aeb_msg_cam.addr))
self.assertEqual(True, self._tx(no_aeb_msg))
# stock system sends AEB -> forwarding, and OP is not allowed to TX
self.assertEqual(1, self._rx(aeb_msg_cam))
self.assertEqual(0, self.safety.safety_fwd_hook(2, aeb_msg_cam.addr))
self.assertEqual(False, self._tx(no_aeb_msg))
def test_acc_accel_limits(self):
for controls_allowed in [True, False]:
@ -145,9 +144,7 @@ class TestTeslaLongitudinalSafety(TestTeslaSafety):
send = (MIN_ACCEL <= min_accel <= MAX_ACCEL) and (MIN_ACCEL <= max_accel <= MAX_ACCEL)
else:
send = np.all(np.isclose([min_accel, max_accel], 0, atol=0.0001))
print([min_accel, max_accel])
self.assertEqual(send, self._tx(self._long_control_msg(10, acc_val=4, accel_limits=[min_accel, max_accel])), (min_accel, max_accel))
# time.sleep(.1)
self.assertEqual(send, self._tx(self._long_control_msg(10, acc_val=4, accel_limits=[min_accel, max_accel])))
class TestTeslaChassisLongitudinalSafety(TestTeslaLongitudinalSafety):
@ -160,18 +157,18 @@ class TestTeslaChassisLongitudinalSafety(TestTeslaLongitudinalSafety):
self.safety = libpanda_py.libpanda
self.safety.set_safety_hooks(Panda.SAFETY_TESLA, Panda.FLAG_TESLA_LONG_CONTROL)
self.safety.init_tests()
#
#
# class TestTeslaPTLongitudinalSafety(TestTeslaLongitudinalSafety):
# TX_MSGS = [[0x2BF, 0]]
# RELAY_MALFUNCTION_ADDR = 0x2BF
# FWD_BLACKLISTED_ADDRS = {2: [0x2BF]}
#
# def setUp(self):
# self.packer = CANPackerPanda("tesla_powertrain")
# self.safety = libpanda_py.libpanda
# self.safety.set_safety_hooks(Panda.SAFETY_TESLA, Panda.FLAG_TESLA_LONG_CONTROL | Panda.FLAG_TESLA_POWERTRAIN)
# self.safety.init_tests()
class TestTeslaPTLongitudinalSafety(TestTeslaLongitudinalSafety):
TX_MSGS = [[0x2BF, 0]]
RELAY_MALFUNCTION_ADDR = 0x2BF
FWD_BLACKLISTED_ADDRS = {2: [0x2BF]}
def setUp(self):
self.packer = CANPackerPanda("tesla_powertrain")
self.safety = libpanda_py.libpanda
self.safety.set_safety_hooks(Panda.SAFETY_TESLA, Panda.FLAG_TESLA_LONG_CONTROL | Panda.FLAG_TESLA_POWERTRAIN)
self.safety.init_tests()
if __name__ == "__main__":