2019-09-25 08:50:53 +08:00
|
|
|
#!/usr/bin/env python3
|
2019-03-14 02:52:50 +08:00
|
|
|
import unittest
|
2019-10-03 09:20:32 +08:00
|
|
|
from panda import Panda
|
2022-12-01 09:41:24 +08:00
|
|
|
from panda.tests.libpanda import libpanda_py
|
2020-04-16 08:00:21 +08:00
|
|
|
import panda.tests.safety.common as common
|
2023-08-05 08:16:35 +08:00
|
|
|
from panda.tests.safety.common import CANPackerPanda, MeasurementSafetyTest
|
2019-03-14 02:52:50 +08:00
|
|
|
|
|
|
|
|
2023-07-15 03:43:49 +08:00
|
|
|
MSG_SUBARU_Brake_Status = 0x13c
|
|
|
|
MSG_SUBARU_CruiseControl = 0x240
|
|
|
|
MSG_SUBARU_Throttle = 0x40
|
|
|
|
MSG_SUBARU_Steering_Torque = 0x119
|
|
|
|
MSG_SUBARU_Wheel_Speeds = 0x13a
|
|
|
|
MSG_SUBARU_ES_LKAS = 0x122
|
|
|
|
MSG_SUBARU_ES_Brake = 0x220
|
|
|
|
MSG_SUBARU_ES_Distance = 0x221
|
|
|
|
MSG_SUBARU_ES_Status = 0x222
|
|
|
|
MSG_SUBARU_ES_DashStatus = 0x321
|
|
|
|
MSG_SUBARU_ES_LKAS_State = 0x322
|
|
|
|
MSG_SUBARU_ES_Infotainment = 0x323
|
|
|
|
|
|
|
|
SUBARU_MAIN_BUS = 0
|
|
|
|
SUBARU_ALT_BUS = 1
|
|
|
|
SUBARU_CAM_BUS = 2
|
|
|
|
|
|
|
|
|
|
|
|
def lkas_tx_msgs(alt_bus):
|
2023-08-07 05:29:28 +08:00
|
|
|
return [[MSG_SUBARU_ES_LKAS, SUBARU_MAIN_BUS],
|
2023-07-15 03:43:49 +08:00
|
|
|
[MSG_SUBARU_ES_Distance, alt_bus],
|
|
|
|
[MSG_SUBARU_ES_DashStatus, SUBARU_MAIN_BUS],
|
|
|
|
[MSG_SUBARU_ES_LKAS_State, SUBARU_MAIN_BUS],
|
|
|
|
[MSG_SUBARU_ES_Infotainment, SUBARU_MAIN_BUS]]
|
|
|
|
|
|
|
|
|
2023-08-05 08:16:35 +08:00
|
|
|
class TestSubaruSafetyBase(common.PandaSafetyTest, common.DriverTorqueSteeringSafetyTest, MeasurementSafetyTest):
|
2023-07-15 03:43:49 +08:00
|
|
|
FLAGS = 0
|
|
|
|
STANDSTILL_THRESHOLD = 0 # kph
|
|
|
|
RELAY_MALFUNCTION_ADDR = MSG_SUBARU_ES_LKAS
|
|
|
|
RELAY_MALFUNCTION_BUS = SUBARU_MAIN_BUS
|
|
|
|
FWD_BUS_LOOKUP = {SUBARU_MAIN_BUS: SUBARU_CAM_BUS, SUBARU_CAM_BUS: SUBARU_MAIN_BUS}
|
|
|
|
FWD_BLACKLISTED_ADDRS = {SUBARU_CAM_BUS: [MSG_SUBARU_ES_LKAS, MSG_SUBARU_ES_DashStatus, MSG_SUBARU_ES_LKAS_State, MSG_SUBARU_ES_Infotainment]}
|
2020-04-16 08:00:21 +08:00
|
|
|
|
2022-05-26 13:51:33 +08:00
|
|
|
MAX_RATE_UP = 50
|
|
|
|
MAX_RATE_DOWN = 70
|
|
|
|
MAX_TORQUE = 2047
|
|
|
|
|
|
|
|
MAX_RT_DELTA = 940
|
|
|
|
RT_INTERVAL = 250000
|
|
|
|
|
|
|
|
DRIVER_TORQUE_ALLOWANCE = 60
|
2022-07-30 11:44:41 +08:00
|
|
|
DRIVER_TORQUE_FACTOR = 50
|
|
|
|
|
2023-07-15 03:43:49 +08:00
|
|
|
ALT_BUS = SUBARU_MAIN_BUS
|
2022-05-26 13:51:33 +08:00
|
|
|
|
2023-08-08 00:29:34 +08:00
|
|
|
DEG_TO_CAN = -100
|
2023-08-05 08:16:35 +08:00
|
|
|
|
2020-04-16 08:00:21 +08:00
|
|
|
def setUp(self):
|
2020-07-24 04:06:11 +08:00
|
|
|
self.packer = CANPackerPanda("subaru_global_2017_generated")
|
2022-12-01 09:41:24 +08:00
|
|
|
self.safety = libpanda_py.libpanda
|
2023-07-15 03:43:49 +08:00
|
|
|
self.safety.set_safety_hooks(Panda.SAFETY_SUBARU, self.FLAGS)
|
2020-04-29 01:33:20 +08:00
|
|
|
self.safety.init_tests()
|
2019-03-14 02:52:50 +08:00
|
|
|
|
|
|
|
def _set_prev_torque(self, t):
|
2020-04-29 01:33:20 +08:00
|
|
|
self.safety.set_desired_torque_last(t)
|
|
|
|
self.safety.set_rt_torque_last(t)
|
2019-03-14 02:52:50 +08:00
|
|
|
|
2022-05-26 13:51:33 +08:00
|
|
|
# TODO: this is unused
|
2019-03-14 02:52:50 +08:00
|
|
|
def _torque_driver_msg(self, torque):
|
2022-07-20 08:18:42 +08:00
|
|
|
values = {"Steer_Torque_Sensor": torque}
|
2022-07-22 09:50:42 +08:00
|
|
|
return self.packer.make_can_msg_panda("Steering_Torque", 0, values)
|
2019-03-14 02:52:50 +08:00
|
|
|
|
2020-03-07 14:29:46 +08:00
|
|
|
def _speed_msg(self, speed):
|
2023-08-05 08:16:35 +08:00
|
|
|
values = {s: speed for s in ["FR", "FL", "RR", "RL"]}
|
2022-07-30 11:44:41 +08:00
|
|
|
return self.packer.make_can_msg_panda("Wheel_Speeds", self.ALT_BUS, values)
|
2023-08-05 08:16:35 +08:00
|
|
|
|
|
|
|
def _angle_meas_msg(self, angle):
|
|
|
|
values = {"Steering_Angle": angle}
|
|
|
|
return self.packer.make_can_msg_panda("Steering_Torque", 0, values)
|
2020-03-07 14:29:46 +08:00
|
|
|
|
2022-03-29 04:13:27 +08:00
|
|
|
def _user_brake_msg(self, brake):
|
2022-07-20 08:18:42 +08:00
|
|
|
values = {"Brake": brake}
|
2022-07-30 11:44:41 +08:00
|
|
|
return self.packer.make_can_msg_panda("Brake_Status", self.ALT_BUS, values)
|
2020-03-07 14:29:46 +08:00
|
|
|
|
2022-05-26 13:51:33 +08:00
|
|
|
def _torque_cmd_msg(self, torque, steer_req=1):
|
2020-04-29 01:47:26 +08:00
|
|
|
values = {"LKAS_Output": torque}
|
2020-04-16 08:00:21 +08:00
|
|
|
return self.packer.make_can_msg_panda("ES_LKAS", 0, values)
|
2019-03-14 02:52:50 +08:00
|
|
|
|
2022-03-29 04:13:27 +08:00
|
|
|
def _user_gas_msg(self, gas):
|
2022-07-20 08:18:42 +08:00
|
|
|
values = {"Throttle_Pedal": gas}
|
2022-07-22 09:50:42 +08:00
|
|
|
return self.packer.make_can_msg_panda("Throttle", 0, values)
|
2020-04-16 08:00:21 +08:00
|
|
|
|
2020-06-03 07:27:07 +08:00
|
|
|
def _pcm_status_msg(self, enable):
|
2022-07-20 08:18:42 +08:00
|
|
|
values = {"Cruise_Activated": enable}
|
2022-07-30 11:44:41 +08:00
|
|
|
return self.packer.make_can_msg_panda("CruiseControl", self.ALT_BUS, values)
|
|
|
|
|
|
|
|
|
2023-07-15 03:43:49 +08:00
|
|
|
class TestSubaruGen2SafetyBase(TestSubaruSafetyBase):
|
|
|
|
ALT_BUS = SUBARU_ALT_BUS
|
2022-07-30 11:44:41 +08:00
|
|
|
|
|
|
|
MAX_RATE_UP = 40
|
|
|
|
MAX_RATE_DOWN = 40
|
|
|
|
MAX_TORQUE = 1000
|
|
|
|
|
2023-07-15 03:43:49 +08:00
|
|
|
class TestSubaruGen1Safety(TestSubaruSafetyBase):
|
|
|
|
FLAGS = 0
|
|
|
|
TX_MSGS = lkas_tx_msgs(SUBARU_MAIN_BUS)
|
|
|
|
|
|
|
|
|
|
|
|
class TestSubaruGen2Safety(TestSubaruGen2SafetyBase):
|
|
|
|
FLAGS = Panda.FLAG_SUBARU_GEN2
|
|
|
|
TX_MSGS = lkas_tx_msgs(SUBARU_ALT_BUS)
|
2020-02-20 11:55:05 +08:00
|
|
|
|
2019-03-14 02:52:50 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|