panda/tests/safety/test_subaru.py

66 lines
2.1 KiB
Python
Raw Normal View History

2019-09-25 08:50:53 +08:00
#!/usr/bin/env python3
2019-03-14 02:52:50 +08:00
import unittest
from panda import Panda
2019-11-15 16:52:34 +08:00
from panda.tests.safety import libpandasafety_py
import panda.tests.safety.common as common
from panda.tests.safety.common import CANPackerPanda
2019-03-14 02:52:50 +08:00
class TestSubaruSafety(common.PandaSafetyTest, common.DriverTorqueSteeringSafetyTest):
TX_MSGS = [[0x122, 0], [0x221, 0], [0x322, 0]]
STANDSTILL_THRESHOLD = 20 # 1kph (see dbc file)
RELAY_MALFUNCTION_ADDR = 0x122
RELAY_MALFUNCTION_BUS = 0
FWD_BLACKLISTED_ADDRS = {2: [0x122, 0x221, 0x322]}
FWD_BUS_LOOKUP = {0: 2, 2: 0}
MAX_RATE_UP = 50
MAX_RATE_DOWN = 70
MAX_TORQUE = 2047
MAX_RT_DELTA = 940
RT_INTERVAL = 250000
DRIVER_TORQUE_ALLOWANCE = 60
DRIVER_TORQUE_FACTOR = 10
def setUp(self):
self.packer = CANPackerPanda("subaru_global_2017_generated")
self.safety = libpandasafety_py.libpandasafety
self.safety.set_safety_hooks(Panda.SAFETY_SUBARU, 0)
self.safety.init_tests()
2019-03-14 02:52:50 +08:00
def _set_prev_torque(self, t):
self.safety.set_desired_torque_last(t)
self.safety.set_rt_torque_last(t)
2019-03-14 02:52:50 +08:00
# TODO: this is unused
2019-03-14 02:52:50 +08:00
def _torque_driver_msg(self, torque):
values = {"Steer_Torque_Sensor": torque}
return self.packer.make_can_msg_panda("Steering_Torque", 0, values, counter=True)
2019-03-14 02:52:50 +08:00
def _speed_msg(self, speed):
# subaru safety doesn't use the scaled value, so undo the scaling
values = {s: speed * 0.057 for s in ["FR", "FL", "RR", "RL"]}
return self.packer.make_can_msg_panda("Wheel_Speeds", 0, values, counter=True)
def _user_brake_msg(self, brake):
values = {"Brake": brake}
return self.packer.make_can_msg_panda("Brake_Status", 0, values, counter=True)
def _torque_cmd_msg(self, torque, steer_req=1):
values = {"LKAS_Output": torque}
return self.packer.make_can_msg_panda("ES_LKAS", 0, values)
2019-03-14 02:52:50 +08:00
def _user_gas_msg(self, gas):
values = {"Throttle_Pedal": gas}
return self.packer.make_can_msg_panda("Throttle", 0, values, counter=True)
def _pcm_status_msg(self, enable):
values = {"Cruise_Activated": enable}
return self.packer.make_can_msg_panda("CruiseControl", 0, values, counter=True)
2019-03-14 02:52:50 +08:00
if __name__ == "__main__":
unittest.main()