2020-06-12 06:51:05 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import unittest
|
|
|
|
from panda import Panda
|
2022-12-01 09:41:24 +08:00
|
|
|
from panda.tests.libpanda import libpanda_py
|
2020-06-12 06:51:05 +08:00
|
|
|
import panda.tests.safety.common as common
|
|
|
|
from panda.tests.safety.common import CANPackerPanda
|
|
|
|
|
|
|
|
|
2023-11-07 08:19:27 +08:00
|
|
|
class TestSubaruPreglobalSafety(common.PandaCarSafetyTest, common.DriverTorqueSteeringSafetyTest):
|
2020-06-12 06:51:05 +08:00
|
|
|
TX_MSGS = [[0x161, 0], [0x164, 0]]
|
2022-09-15 09:42:16 +08:00
|
|
|
STANDSTILL_THRESHOLD = 0 # kph
|
2020-06-12 06:51:05 +08:00
|
|
|
RELAY_MALFUNCTION_ADDR = 0x164
|
|
|
|
RELAY_MALFUNCTION_BUS = 0
|
|
|
|
FWD_BLACKLISTED_ADDRS = {2: [0x161, 0x164]}
|
|
|
|
FWD_BUS_LOOKUP = {0: 2, 2: 0}
|
|
|
|
|
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 = 75
|
|
|
|
DRIVER_TORQUE_FACTOR = 10
|
|
|
|
|
2020-06-12 06:51:05 +08:00
|
|
|
def setUp(self):
|
|
|
|
self.packer = CANPackerPanda("subaru_outback_2015_generated")
|
2022-12-01 09:41:24 +08:00
|
|
|
self.safety = libpanda_py.libpanda
|
2023-05-16 08:22:40 +08:00
|
|
|
self.safety.set_safety_hooks(Panda.SAFETY_SUBARU_PREGLOBAL, 0)
|
2020-06-12 06:51:05 +08:00
|
|
|
self.safety.init_tests()
|
|
|
|
|
|
|
|
def _set_prev_torque(self, t):
|
|
|
|
self.safety.set_desired_torque_last(t)
|
|
|
|
self.safety.set_rt_torque_last(t)
|
|
|
|
|
|
|
|
def _torque_driver_msg(self, torque):
|
|
|
|
values = {"Steer_Torque_Sensor": torque}
|
|
|
|
return self.packer.make_can_msg_panda("Steering_Torque", 0, values)
|
|
|
|
|
|
|
|
def _speed_msg(self, speed):
|
|
|
|
# subaru safety doesn't use the scaled value, so undo the scaling
|
|
|
|
values = {s: speed*0.0592 for s in ["FR", "FL", "RR", "RL"]}
|
|
|
|
return self.packer.make_can_msg_panda("Wheel_Speeds", 0, values)
|
|
|
|
|
2022-03-29 04:13:27 +08:00
|
|
|
def _user_brake_msg(self, brake):
|
2020-06-12 06:51:05 +08:00
|
|
|
values = {"Brake_Pedal": brake}
|
|
|
|
return self.packer.make_can_msg_panda("Brake_Pedal", 0, values)
|
|
|
|
|
2022-05-26 13:51:33 +08:00
|
|
|
def _torque_cmd_msg(self, torque, steer_req=1):
|
2023-09-01 05:26:51 +08:00
|
|
|
values = {"LKAS_Command": torque, "LKAS_Active": steer_req}
|
2020-06-12 06:51:05 +08:00
|
|
|
return self.packer.make_can_msg_panda("ES_LKAS", 0, values)
|
|
|
|
|
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-06-12 06:51:05 +08:00
|
|
|
|
|
|
|
def _pcm_status_msg(self, enable):
|
|
|
|
values = {"Cruise_Activated": enable}
|
|
|
|
return self.packer.make_can_msg_panda("CruiseControl", 0, values)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|