panda/tests/safety/test_subaru.py

229 lines
7.7 KiB
Python
Raw Permalink Normal View History

2019-09-25 08:50:53 +08:00
#!/usr/bin/env python3
import enum
2019-03-14 02:52:50 +08:00
import unittest
from panda import Panda
from panda.tests.libpanda import libpanda_py
import panda.tests.safety.common as common
from panda.tests.safety.common import CANPackerPanda
from functools import partial
2019-03-14 02:52:50 +08:00
class SubaruMsg(enum.IntEnum):
Brake_Status = 0x13c
CruiseControl = 0x240
Throttle = 0x40
Steering_Torque = 0x119
Wheel_Speeds = 0x13a
ES_LKAS = 0x122
ES_LKAS_ANGLE = 0x124
ES_Brake = 0x220
ES_Distance = 0x221
ES_Status = 0x222
ES_DashStatus = 0x321
ES_LKAS_State = 0x322
ES_Infotainment = 0x323
ES_UDS_Request = 0x787
ES_HighBeamAssist = 0x121
ES_STATIC_1 = 0x22a
ES_STATIC_2 = 0x325
2019-03-14 02:52:50 +08:00
SUBARU_MAIN_BUS = 0
SUBARU_ALT_BUS = 1
SUBARU_CAM_BUS = 2
def lkas_tx_msgs(alt_bus, lkas_msg=SubaruMsg.ES_LKAS):
return [[lkas_msg, SUBARU_MAIN_BUS],
[SubaruMsg.ES_Distance, alt_bus],
[SubaruMsg.ES_DashStatus, SUBARU_MAIN_BUS],
[SubaruMsg.ES_LKAS_State, SUBARU_MAIN_BUS],
[SubaruMsg.ES_Infotainment, SUBARU_MAIN_BUS]]
def long_tx_msgs(alt_bus):
return [[SubaruMsg.ES_Brake, alt_bus],
[SubaruMsg.ES_Status, alt_bus]]
def gen2_long_additional_tx_msgs():
return [[SubaruMsg.ES_UDS_Request, SUBARU_CAM_BUS],
[SubaruMsg.ES_HighBeamAssist, SUBARU_MAIN_BUS],
[SubaruMsg.ES_STATIC_1, SUBARU_MAIN_BUS],
[SubaruMsg.ES_STATIC_2, SUBARU_MAIN_BUS]]
def fwd_blacklisted_addr(lkas_msg=SubaruMsg.ES_LKAS):
return {SUBARU_CAM_BUS: [lkas_msg, SubaruMsg.ES_DashStatus, SubaruMsg.ES_LKAS_State, SubaruMsg.ES_Infotainment]}
class TestSubaruSafetyBase(common.PandaCarSafetyTest):
FLAGS = 0
STANDSTILL_THRESHOLD = 0 # kph
RELAY_MALFUNCTION_ADDRS = {SUBARU_MAIN_BUS: (SubaruMsg.ES_LKAS,)}
FWD_BUS_LOOKUP = {SUBARU_MAIN_BUS: SUBARU_CAM_BUS, SUBARU_CAM_BUS: SUBARU_MAIN_BUS}
FWD_BLACKLISTED_ADDRS = fwd_blacklisted_addr()
MAX_RT_DELTA = 940
RT_INTERVAL = 250000
DRIVER_TORQUE_ALLOWANCE = 60
DRIVER_TORQUE_FACTOR = 50
ALT_MAIN_BUS = SUBARU_MAIN_BUS
ALT_CAM_BUS = SUBARU_CAM_BUS
DEG_TO_CAN = 100
INACTIVE_GAS = 1818
def setUp(self):
self.packer = CANPackerPanda("subaru_global_2017_generated")
self.safety = libpanda_py.libpanda
self.safety.set_safety_hooks(Panda.SAFETY_SUBARU, self.FLAGS)
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
def _torque_driver_msg(self, torque):
values = {"Steer_Torque_Sensor": torque}
return self.packer.make_can_msg_panda("Steering_Torque", 0, values)
2019-03-14 02:52:50 +08:00
def _speed_msg(self, speed):
values = {s: speed for s in ["FR", "FL", "RR", "RL"]}
return self.packer.make_can_msg_panda("Wheel_Speeds", self.ALT_MAIN_BUS, values)
def _angle_meas_msg(self, angle):
values = {"Steering_Angle": angle}
return self.packer.make_can_msg_panda("Steering_Torque", 0, values)
def _user_brake_msg(self, brake):
values = {"Brake": brake}
return self.packer.make_can_msg_panda("Brake_Status", self.ALT_MAIN_BUS, values)
def _user_gas_msg(self, gas):
values = {"Throttle_Pedal": gas}
return self.packer.make_can_msg_panda("Throttle", 0, values)
def _pcm_status_msg(self, enable):
values = {"Cruise_Activated": enable}
return self.packer.make_can_msg_panda("CruiseControl", self.ALT_MAIN_BUS, values)
class TestSubaruStockLongitudinalSafetyBase(TestSubaruSafetyBase):
def _cancel_msg(self, cancel, cruise_throttle=0):
values = {"Cruise_Cancel": cancel, "Cruise_Throttle": cruise_throttle}
return self.packer.make_can_msg_panda("ES_Distance", self.ALT_MAIN_BUS, values)
def test_cancel_message(self):
# test that we can only send the cancel message (ES_Distance) with inactive throttle (1818) and Cruise_Cancel=1
for cancel in [True, False]:
self._generic_limit_safety_check(partial(self._cancel_msg, cancel), self.INACTIVE_GAS, self.INACTIVE_GAS, 0, 2**12, 1, self.INACTIVE_GAS, cancel)
Subaru: Global gen1 longitudinal safety (#1500) * Add subaru long TX and RX messages * misra c2012 fix * fix tests * Reorder signals * increase max steering torque * merge fix * merge fix, remove cnt from test * Move subaru logitudinal behind flag, add safety test * update subaru_longitudinal checks * cleanup * Add subaru longitudinal checks * misra fix * Add subaru rpm and throttle rate limit checks * temporary disable cruise throttle and cruise rpm checks * update subaru long test * update longitudinal safety and add tests * fix tests * fix misra * subaru long signals limits checks * Add controls_allowed to long tests * remove unused variables * Add AEB passthru and tests * Add bus * Update AEB logic * Add GEN2 AEB support * syntax fix * Update AEB tests * Add comment for subaru_aeb * Do not check cruise_throttle and cruise_rpm limits when gas pressed * use long limits struct * Subaru: longitudinal checks only when controls_allowed, use ES_LKAS_State LKAS_Alert for AEB * fix misra, set controls_allowed for es_brake test * fix misra * Fix es_brake violation check * Add 0x323 to longitudinal test * Remove stock fcw from aeb signals * Use GET_BYTES * Revert "export FW_PATH" This reverts commit 2a5058d858b36ff7dc5477119a54f0aab137b266. * Revert "cleanup fw filename conventions (#1434)" This reverts commit 4dd2735e38b63940ca1e1f42b4522ca4c1a0a1cc. * Revert "Revert "export FW_PATH"" This reverts commit 86e8d321d055c5f89cde7ee26a0014df1bcd5b39. * Revert "Revert "cleanup fw filename conventions (#1434)"" This reverts commit 5aae6716fa5506aac49dadd287229a45f0a3b94e. * cleaned up safety * cleanup subaru long safety * subaru_aeb -> stock_aeb for other platforms * fix unittests * pretty * need to upload this route * remove AEB stuff for now * remove unrequired rpm checks * add comment * added comment about acceleration and use throttle limit for rpm too * inactive_throttle_fix * Update board/safety/safety_subaru.h Co-authored-by: Shane Smiskol <shane@smiskol.com> * added comments about long limits * increase max brake * revert that * cleanup * rename throttle to gas * add safety replay * remove todo * rename throttle to gas * move subaru stuff out of common test * PR cleanup * added min gas * reduce initial complexity by not intercepting cruisecontrol or brake_status * create common gas brake safety test * remove unrelated subaru reference * also test below min_value * fix fwd hook test * better name and hardcoded * use same as acceleration limits * revert gm * remove callable * also limit rpm * remove safety replay for now * revert unrelated changes * pr cleanup * remove unused gasbrake safety test * fix ruff linter * PR cleanup * pr cleanup? * added common brake test and moved generic test to base safety class * remove duplicate test * wip * wip * rename longitudinalaccelsafety * revert limits correct test * fix controls allowed test * move gm over to long gas brake test * assert that limits are reasonable * fix typing * fix linter again * fix linter again * fix linter again * like to make it clear * typo * fix from merge * clearer names * dont need thesemore * subaru: use common test * fix merge issue * inactive gas from long limits * fix tests * linter * fix gen2 * fix linter * also test torque when doing long control * renamre transmision rpm * consistent whitespace * rename declarations too * rename transmission rpm * same line * actually is transmission rpm --------- Co-authored-by: Martin Lillepuu <martin@mlp.ee> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Shane Smiskol <shane@smiskol.com>
2023-08-16 09:51:13 +08:00
class TestSubaruLongitudinalSafetyBase(TestSubaruSafetyBase, common.LongitudinalGasBrakeSafetyTest):
MIN_GAS = 808
MAX_GAS = 3400
INACTIVE_GAS = 1818
MAX_POSSIBLE_GAS = 2**13
Subaru: Global gen1 longitudinal safety (#1500) * Add subaru long TX and RX messages * misra c2012 fix * fix tests * Reorder signals * increase max steering torque * merge fix * merge fix, remove cnt from test * Move subaru logitudinal behind flag, add safety test * update subaru_longitudinal checks * cleanup * Add subaru longitudinal checks * misra fix * Add subaru rpm and throttle rate limit checks * temporary disable cruise throttle and cruise rpm checks * update subaru long test * update longitudinal safety and add tests * fix tests * fix misra * subaru long signals limits checks * Add controls_allowed to long tests * remove unused variables * Add AEB passthru and tests * Add bus * Update AEB logic * Add GEN2 AEB support * syntax fix * Update AEB tests * Add comment for subaru_aeb * Do not check cruise_throttle and cruise_rpm limits when gas pressed * use long limits struct * Subaru: longitudinal checks only when controls_allowed, use ES_LKAS_State LKAS_Alert for AEB * fix misra, set controls_allowed for es_brake test * fix misra * Fix es_brake violation check * Add 0x323 to longitudinal test * Remove stock fcw from aeb signals * Use GET_BYTES * Revert "export FW_PATH" This reverts commit 2a5058d858b36ff7dc5477119a54f0aab137b266. * Revert "cleanup fw filename conventions (#1434)" This reverts commit 4dd2735e38b63940ca1e1f42b4522ca4c1a0a1cc. * Revert "Revert "export FW_PATH"" This reverts commit 86e8d321d055c5f89cde7ee26a0014df1bcd5b39. * Revert "Revert "cleanup fw filename conventions (#1434)"" This reverts commit 5aae6716fa5506aac49dadd287229a45f0a3b94e. * cleaned up safety * cleanup subaru long safety * subaru_aeb -> stock_aeb for other platforms * fix unittests * pretty * need to upload this route * remove AEB stuff for now * remove unrequired rpm checks * add comment * added comment about acceleration and use throttle limit for rpm too * inactive_throttle_fix * Update board/safety/safety_subaru.h Co-authored-by: Shane Smiskol <shane@smiskol.com> * added comments about long limits * increase max brake * revert that * cleanup * rename throttle to gas * add safety replay * remove todo * rename throttle to gas * move subaru stuff out of common test * PR cleanup * added min gas * reduce initial complexity by not intercepting cruisecontrol or brake_status * create common gas brake safety test * remove unrelated subaru reference * also test below min_value * fix fwd hook test * better name and hardcoded * use same as acceleration limits * revert gm * remove callable * also limit rpm * remove safety replay for now * revert unrelated changes * pr cleanup * remove unused gasbrake safety test * fix ruff linter * PR cleanup * pr cleanup? * added common brake test and moved generic test to base safety class * remove duplicate test * wip * wip * rename longitudinalaccelsafety * revert limits correct test * fix controls allowed test * move gm over to long gas brake test * assert that limits are reasonable * fix typing * fix linter again * fix linter again * fix linter again * like to make it clear * typo * fix from merge * clearer names * dont need thesemore * subaru: use common test * fix merge issue * inactive gas from long limits * fix tests * linter * fix gen2 * fix linter * also test torque when doing long control * renamre transmision rpm * consistent whitespace * rename declarations too * rename transmission rpm * same line * actually is transmission rpm --------- Co-authored-by: Martin Lillepuu <martin@mlp.ee> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Shane Smiskol <shane@smiskol.com>
2023-08-16 09:51:13 +08:00
MIN_BRAKE = 0
MAX_BRAKE = 600
MAX_POSSIBLE_BRAKE = 2**16
MIN_RPM = 0
MAX_RPM = 3600
MAX_POSSIBLE_RPM = 2**13
Subaru: Global gen1 longitudinal safety (#1500) * Add subaru long TX and RX messages * misra c2012 fix * fix tests * Reorder signals * increase max steering torque * merge fix * merge fix, remove cnt from test * Move subaru logitudinal behind flag, add safety test * update subaru_longitudinal checks * cleanup * Add subaru longitudinal checks * misra fix * Add subaru rpm and throttle rate limit checks * temporary disable cruise throttle and cruise rpm checks * update subaru long test * update longitudinal safety and add tests * fix tests * fix misra * subaru long signals limits checks * Add controls_allowed to long tests * remove unused variables * Add AEB passthru and tests * Add bus * Update AEB logic * Add GEN2 AEB support * syntax fix * Update AEB tests * Add comment for subaru_aeb * Do not check cruise_throttle and cruise_rpm limits when gas pressed * use long limits struct * Subaru: longitudinal checks only when controls_allowed, use ES_LKAS_State LKAS_Alert for AEB * fix misra, set controls_allowed for es_brake test * fix misra * Fix es_brake violation check * Add 0x323 to longitudinal test * Remove stock fcw from aeb signals * Use GET_BYTES * Revert "export FW_PATH" This reverts commit 2a5058d858b36ff7dc5477119a54f0aab137b266. * Revert "cleanup fw filename conventions (#1434)" This reverts commit 4dd2735e38b63940ca1e1f42b4522ca4c1a0a1cc. * Revert "Revert "export FW_PATH"" This reverts commit 86e8d321d055c5f89cde7ee26a0014df1bcd5b39. * Revert "Revert "cleanup fw filename conventions (#1434)"" This reverts commit 5aae6716fa5506aac49dadd287229a45f0a3b94e. * cleaned up safety * cleanup subaru long safety * subaru_aeb -> stock_aeb for other platforms * fix unittests * pretty * need to upload this route * remove AEB stuff for now * remove unrequired rpm checks * add comment * added comment about acceleration and use throttle limit for rpm too * inactive_throttle_fix * Update board/safety/safety_subaru.h Co-authored-by: Shane Smiskol <shane@smiskol.com> * added comments about long limits * increase max brake * revert that * cleanup * rename throttle to gas * add safety replay * remove todo * rename throttle to gas * move subaru stuff out of common test * PR cleanup * added min gas * reduce initial complexity by not intercepting cruisecontrol or brake_status * create common gas brake safety test * remove unrelated subaru reference * also test below min_value * fix fwd hook test * better name and hardcoded * use same as acceleration limits * revert gm * remove callable * also limit rpm * remove safety replay for now * revert unrelated changes * pr cleanup * remove unused gasbrake safety test * fix ruff linter * PR cleanup * pr cleanup? * added common brake test and moved generic test to base safety class * remove duplicate test * wip * wip * rename longitudinalaccelsafety * revert limits correct test * fix controls allowed test * move gm over to long gas brake test * assert that limits are reasonable * fix typing * fix linter again * fix linter again * fix linter again * like to make it clear * typo * fix from merge * clearer names * dont need thesemore * subaru: use common test * fix merge issue * inactive gas from long limits * fix tests * linter * fix gen2 * fix linter * also test torque when doing long control * renamre transmision rpm * consistent whitespace * rename declarations too * rename transmission rpm * same line * actually is transmission rpm --------- Co-authored-by: Martin Lillepuu <martin@mlp.ee> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Shane Smiskol <shane@smiskol.com>
2023-08-16 09:51:13 +08:00
FWD_BLACKLISTED_ADDRS = {2: [SubaruMsg.ES_LKAS, SubaruMsg.ES_Brake, SubaruMsg.ES_Distance,
SubaruMsg.ES_Status, SubaruMsg.ES_DashStatus,
SubaruMsg.ES_LKAS_State, SubaruMsg.ES_Infotainment]}
Subaru: Global gen1 longitudinal safety (#1500) * Add subaru long TX and RX messages * misra c2012 fix * fix tests * Reorder signals * increase max steering torque * merge fix * merge fix, remove cnt from test * Move subaru logitudinal behind flag, add safety test * update subaru_longitudinal checks * cleanup * Add subaru longitudinal checks * misra fix * Add subaru rpm and throttle rate limit checks * temporary disable cruise throttle and cruise rpm checks * update subaru long test * update longitudinal safety and add tests * fix tests * fix misra * subaru long signals limits checks * Add controls_allowed to long tests * remove unused variables * Add AEB passthru and tests * Add bus * Update AEB logic * Add GEN2 AEB support * syntax fix * Update AEB tests * Add comment for subaru_aeb * Do not check cruise_throttle and cruise_rpm limits when gas pressed * use long limits struct * Subaru: longitudinal checks only when controls_allowed, use ES_LKAS_State LKAS_Alert for AEB * fix misra, set controls_allowed for es_brake test * fix misra * Fix es_brake violation check * Add 0x323 to longitudinal test * Remove stock fcw from aeb signals * Use GET_BYTES * Revert "export FW_PATH" This reverts commit 2a5058d858b36ff7dc5477119a54f0aab137b266. * Revert "cleanup fw filename conventions (#1434)" This reverts commit 4dd2735e38b63940ca1e1f42b4522ca4c1a0a1cc. * Revert "Revert "export FW_PATH"" This reverts commit 86e8d321d055c5f89cde7ee26a0014df1bcd5b39. * Revert "Revert "cleanup fw filename conventions (#1434)"" This reverts commit 5aae6716fa5506aac49dadd287229a45f0a3b94e. * cleaned up safety * cleanup subaru long safety * subaru_aeb -> stock_aeb for other platforms * fix unittests * pretty * need to upload this route * remove AEB stuff for now * remove unrequired rpm checks * add comment * added comment about acceleration and use throttle limit for rpm too * inactive_throttle_fix * Update board/safety/safety_subaru.h Co-authored-by: Shane Smiskol <shane@smiskol.com> * added comments about long limits * increase max brake * revert that * cleanup * rename throttle to gas * add safety replay * remove todo * rename throttle to gas * move subaru stuff out of common test * PR cleanup * added min gas * reduce initial complexity by not intercepting cruisecontrol or brake_status * create common gas brake safety test * remove unrelated subaru reference * also test below min_value * fix fwd hook test * better name and hardcoded * use same as acceleration limits * revert gm * remove callable * also limit rpm * remove safety replay for now * revert unrelated changes * pr cleanup * remove unused gasbrake safety test * fix ruff linter * PR cleanup * pr cleanup? * added common brake test and moved generic test to base safety class * remove duplicate test * wip * wip * rename longitudinalaccelsafety * revert limits correct test * fix controls allowed test * move gm over to long gas brake test * assert that limits are reasonable * fix typing * fix linter again * fix linter again * fix linter again * like to make it clear * typo * fix from merge * clearer names * dont need thesemore * subaru: use common test * fix merge issue * inactive gas from long limits * fix tests * linter * fix gen2 * fix linter * also test torque when doing long control * renamre transmision rpm * consistent whitespace * rename declarations too * rename transmission rpm * same line * actually is transmission rpm --------- Co-authored-by: Martin Lillepuu <martin@mlp.ee> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Shane Smiskol <shane@smiskol.com>
2023-08-16 09:51:13 +08:00
def test_rpm_safety_check(self):
self._generic_limit_safety_check(self._send_rpm_msg, self.MIN_RPM, self.MAX_RPM, 0, self.MAX_POSSIBLE_RPM, 1)
def _send_brake_msg(self, brake):
values = {"Brake_Pressure": brake}
return self.packer.make_can_msg_panda("ES_Brake", self.ALT_MAIN_BUS, values)
Subaru: Global gen1 longitudinal safety (#1500) * Add subaru long TX and RX messages * misra c2012 fix * fix tests * Reorder signals * increase max steering torque * merge fix * merge fix, remove cnt from test * Move subaru logitudinal behind flag, add safety test * update subaru_longitudinal checks * cleanup * Add subaru longitudinal checks * misra fix * Add subaru rpm and throttle rate limit checks * temporary disable cruise throttle and cruise rpm checks * update subaru long test * update longitudinal safety and add tests * fix tests * fix misra * subaru long signals limits checks * Add controls_allowed to long tests * remove unused variables * Add AEB passthru and tests * Add bus * Update AEB logic * Add GEN2 AEB support * syntax fix * Update AEB tests * Add comment for subaru_aeb * Do not check cruise_throttle and cruise_rpm limits when gas pressed * use long limits struct * Subaru: longitudinal checks only when controls_allowed, use ES_LKAS_State LKAS_Alert for AEB * fix misra, set controls_allowed for es_brake test * fix misra * Fix es_brake violation check * Add 0x323 to longitudinal test * Remove stock fcw from aeb signals * Use GET_BYTES * Revert "export FW_PATH" This reverts commit 2a5058d858b36ff7dc5477119a54f0aab137b266. * Revert "cleanup fw filename conventions (#1434)" This reverts commit 4dd2735e38b63940ca1e1f42b4522ca4c1a0a1cc. * Revert "Revert "export FW_PATH"" This reverts commit 86e8d321d055c5f89cde7ee26a0014df1bcd5b39. * Revert "Revert "cleanup fw filename conventions (#1434)"" This reverts commit 5aae6716fa5506aac49dadd287229a45f0a3b94e. * cleaned up safety * cleanup subaru long safety * subaru_aeb -> stock_aeb for other platforms * fix unittests * pretty * need to upload this route * remove AEB stuff for now * remove unrequired rpm checks * add comment * added comment about acceleration and use throttle limit for rpm too * inactive_throttle_fix * Update board/safety/safety_subaru.h Co-authored-by: Shane Smiskol <shane@smiskol.com> * added comments about long limits * increase max brake * revert that * cleanup * rename throttle to gas * add safety replay * remove todo * rename throttle to gas * move subaru stuff out of common test * PR cleanup * added min gas * reduce initial complexity by not intercepting cruisecontrol or brake_status * create common gas brake safety test * remove unrelated subaru reference * also test below min_value * fix fwd hook test * better name and hardcoded * use same as acceleration limits * revert gm * remove callable * also limit rpm * remove safety replay for now * revert unrelated changes * pr cleanup * remove unused gasbrake safety test * fix ruff linter * PR cleanup * pr cleanup? * added common brake test and moved generic test to base safety class * remove duplicate test * wip * wip * rename longitudinalaccelsafety * revert limits correct test * fix controls allowed test * move gm over to long gas brake test * assert that limits are reasonable * fix typing * fix linter again * fix linter again * fix linter again * like to make it clear * typo * fix from merge * clearer names * dont need thesemore * subaru: use common test * fix merge issue * inactive gas from long limits * fix tests * linter * fix gen2 * fix linter * also test torque when doing long control * renamre transmision rpm * consistent whitespace * rename declarations too * rename transmission rpm * same line * actually is transmission rpm --------- Co-authored-by: Martin Lillepuu <martin@mlp.ee> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Shane Smiskol <shane@smiskol.com>
2023-08-16 09:51:13 +08:00
def _send_gas_msg(self, gas):
values = {"Cruise_Throttle": gas}
return self.packer.make_can_msg_panda("ES_Distance", self.ALT_MAIN_BUS, values)
Subaru: Global gen1 longitudinal safety (#1500) * Add subaru long TX and RX messages * misra c2012 fix * fix tests * Reorder signals * increase max steering torque * merge fix * merge fix, remove cnt from test * Move subaru logitudinal behind flag, add safety test * update subaru_longitudinal checks * cleanup * Add subaru longitudinal checks * misra fix * Add subaru rpm and throttle rate limit checks * temporary disable cruise throttle and cruise rpm checks * update subaru long test * update longitudinal safety and add tests * fix tests * fix misra * subaru long signals limits checks * Add controls_allowed to long tests * remove unused variables * Add AEB passthru and tests * Add bus * Update AEB logic * Add GEN2 AEB support * syntax fix * Update AEB tests * Add comment for subaru_aeb * Do not check cruise_throttle and cruise_rpm limits when gas pressed * use long limits struct * Subaru: longitudinal checks only when controls_allowed, use ES_LKAS_State LKAS_Alert for AEB * fix misra, set controls_allowed for es_brake test * fix misra * Fix es_brake violation check * Add 0x323 to longitudinal test * Remove stock fcw from aeb signals * Use GET_BYTES * Revert "export FW_PATH" This reverts commit 2a5058d858b36ff7dc5477119a54f0aab137b266. * Revert "cleanup fw filename conventions (#1434)" This reverts commit 4dd2735e38b63940ca1e1f42b4522ca4c1a0a1cc. * Revert "Revert "export FW_PATH"" This reverts commit 86e8d321d055c5f89cde7ee26a0014df1bcd5b39. * Revert "Revert "cleanup fw filename conventions (#1434)"" This reverts commit 5aae6716fa5506aac49dadd287229a45f0a3b94e. * cleaned up safety * cleanup subaru long safety * subaru_aeb -> stock_aeb for other platforms * fix unittests * pretty * need to upload this route * remove AEB stuff for now * remove unrequired rpm checks * add comment * added comment about acceleration and use throttle limit for rpm too * inactive_throttle_fix * Update board/safety/safety_subaru.h Co-authored-by: Shane Smiskol <shane@smiskol.com> * added comments about long limits * increase max brake * revert that * cleanup * rename throttle to gas * add safety replay * remove todo * rename throttle to gas * move subaru stuff out of common test * PR cleanup * added min gas * reduce initial complexity by not intercepting cruisecontrol or brake_status * create common gas brake safety test * remove unrelated subaru reference * also test below min_value * fix fwd hook test * better name and hardcoded * use same as acceleration limits * revert gm * remove callable * also limit rpm * remove safety replay for now * revert unrelated changes * pr cleanup * remove unused gasbrake safety test * fix ruff linter * PR cleanup * pr cleanup? * added common brake test and moved generic test to base safety class * remove duplicate test * wip * wip * rename longitudinalaccelsafety * revert limits correct test * fix controls allowed test * move gm over to long gas brake test * assert that limits are reasonable * fix typing * fix linter again * fix linter again * fix linter again * like to make it clear * typo * fix from merge * clearer names * dont need thesemore * subaru: use common test * fix merge issue * inactive gas from long limits * fix tests * linter * fix gen2 * fix linter * also test torque when doing long control * renamre transmision rpm * consistent whitespace * rename declarations too * rename transmission rpm * same line * actually is transmission rpm --------- Co-authored-by: Martin Lillepuu <martin@mlp.ee> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Shane Smiskol <shane@smiskol.com>
2023-08-16 09:51:13 +08:00
def _send_rpm_msg(self, rpm):
values = {"Cruise_RPM": rpm}
return self.packer.make_can_msg_panda("ES_Status", self.ALT_MAIN_BUS, values)
Subaru: Global gen1 longitudinal safety (#1500) * Add subaru long TX and RX messages * misra c2012 fix * fix tests * Reorder signals * increase max steering torque * merge fix * merge fix, remove cnt from test * Move subaru logitudinal behind flag, add safety test * update subaru_longitudinal checks * cleanup * Add subaru longitudinal checks * misra fix * Add subaru rpm and throttle rate limit checks * temporary disable cruise throttle and cruise rpm checks * update subaru long test * update longitudinal safety and add tests * fix tests * fix misra * subaru long signals limits checks * Add controls_allowed to long tests * remove unused variables * Add AEB passthru and tests * Add bus * Update AEB logic * Add GEN2 AEB support * syntax fix * Update AEB tests * Add comment for subaru_aeb * Do not check cruise_throttle and cruise_rpm limits when gas pressed * use long limits struct * Subaru: longitudinal checks only when controls_allowed, use ES_LKAS_State LKAS_Alert for AEB * fix misra, set controls_allowed for es_brake test * fix misra * Fix es_brake violation check * Add 0x323 to longitudinal test * Remove stock fcw from aeb signals * Use GET_BYTES * Revert "export FW_PATH" This reverts commit 2a5058d858b36ff7dc5477119a54f0aab137b266. * Revert "cleanup fw filename conventions (#1434)" This reverts commit 4dd2735e38b63940ca1e1f42b4522ca4c1a0a1cc. * Revert "Revert "export FW_PATH"" This reverts commit 86e8d321d055c5f89cde7ee26a0014df1bcd5b39. * Revert "Revert "cleanup fw filename conventions (#1434)"" This reverts commit 5aae6716fa5506aac49dadd287229a45f0a3b94e. * cleaned up safety * cleanup subaru long safety * subaru_aeb -> stock_aeb for other platforms * fix unittests * pretty * need to upload this route * remove AEB stuff for now * remove unrequired rpm checks * add comment * added comment about acceleration and use throttle limit for rpm too * inactive_throttle_fix * Update board/safety/safety_subaru.h Co-authored-by: Shane Smiskol <shane@smiskol.com> * added comments about long limits * increase max brake * revert that * cleanup * rename throttle to gas * add safety replay * remove todo * rename throttle to gas * move subaru stuff out of common test * PR cleanup * added min gas * reduce initial complexity by not intercepting cruisecontrol or brake_status * create common gas brake safety test * remove unrelated subaru reference * also test below min_value * fix fwd hook test * better name and hardcoded * use same as acceleration limits * revert gm * remove callable * also limit rpm * remove safety replay for now * revert unrelated changes * pr cleanup * remove unused gasbrake safety test * fix ruff linter * PR cleanup * pr cleanup? * added common brake test and moved generic test to base safety class * remove duplicate test * wip * wip * rename longitudinalaccelsafety * revert limits correct test * fix controls allowed test * move gm over to long gas brake test * assert that limits are reasonable * fix typing * fix linter again * fix linter again * fix linter again * like to make it clear * typo * fix from merge * clearer names * dont need thesemore * subaru: use common test * fix merge issue * inactive gas from long limits * fix tests * linter * fix gen2 * fix linter * also test torque when doing long control * renamre transmision rpm * consistent whitespace * rename declarations too * rename transmission rpm * same line * actually is transmission rpm --------- Co-authored-by: Martin Lillepuu <martin@mlp.ee> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Shane Smiskol <shane@smiskol.com>
2023-08-16 09:51:13 +08:00
class TestSubaruTorqueSafetyBase(TestSubaruSafetyBase, common.DriverTorqueSteeringSafetyTest, common.SteerRequestCutSafetyTest):
MAX_RATE_UP = 50
MAX_RATE_DOWN = 70
MAX_TORQUE = 2047
# Safety around steering req bit
MIN_VALID_STEERING_FRAMES = 7
MAX_INVALID_STEERING_FRAMES = 1
MIN_VALID_STEERING_RT_INTERVAL = 144000
def _torque_cmd_msg(self, torque, steer_req=1):
values = {"LKAS_Output": torque, "LKAS_Request": steer_req}
return self.packer.make_can_msg_panda("ES_LKAS", SUBARU_MAIN_BUS, values)
class TestSubaruGen1TorqueStockLongitudinalSafety(TestSubaruStockLongitudinalSafetyBase, TestSubaruTorqueSafetyBase):
FLAGS = 0
TX_MSGS = lkas_tx_msgs(SUBARU_MAIN_BUS)
class TestSubaruGen2TorqueSafetyBase(TestSubaruTorqueSafetyBase):
ALT_MAIN_BUS = SUBARU_ALT_BUS
ALT_CAM_BUS = SUBARU_ALT_BUS
MAX_RATE_UP = 40
MAX_RATE_DOWN = 40
MAX_TORQUE = 1000
class TestSubaruGen2TorqueStockLongitudinalSafety(TestSubaruStockLongitudinalSafetyBase, TestSubaruGen2TorqueSafetyBase):
FLAGS = Panda.FLAG_SUBARU_GEN2
TX_MSGS = lkas_tx_msgs(SUBARU_ALT_BUS)
2019-03-14 02:52:50 +08:00
Subaru: Global gen1 longitudinal safety (#1500) * Add subaru long TX and RX messages * misra c2012 fix * fix tests * Reorder signals * increase max steering torque * merge fix * merge fix, remove cnt from test * Move subaru logitudinal behind flag, add safety test * update subaru_longitudinal checks * cleanup * Add subaru longitudinal checks * misra fix * Add subaru rpm and throttle rate limit checks * temporary disable cruise throttle and cruise rpm checks * update subaru long test * update longitudinal safety and add tests * fix tests * fix misra * subaru long signals limits checks * Add controls_allowed to long tests * remove unused variables * Add AEB passthru and tests * Add bus * Update AEB logic * Add GEN2 AEB support * syntax fix * Update AEB tests * Add comment for subaru_aeb * Do not check cruise_throttle and cruise_rpm limits when gas pressed * use long limits struct * Subaru: longitudinal checks only when controls_allowed, use ES_LKAS_State LKAS_Alert for AEB * fix misra, set controls_allowed for es_brake test * fix misra * Fix es_brake violation check * Add 0x323 to longitudinal test * Remove stock fcw from aeb signals * Use GET_BYTES * Revert "export FW_PATH" This reverts commit 2a5058d858b36ff7dc5477119a54f0aab137b266. * Revert "cleanup fw filename conventions (#1434)" This reverts commit 4dd2735e38b63940ca1e1f42b4522ca4c1a0a1cc. * Revert "Revert "export FW_PATH"" This reverts commit 86e8d321d055c5f89cde7ee26a0014df1bcd5b39. * Revert "Revert "cleanup fw filename conventions (#1434)"" This reverts commit 5aae6716fa5506aac49dadd287229a45f0a3b94e. * cleaned up safety * cleanup subaru long safety * subaru_aeb -> stock_aeb for other platforms * fix unittests * pretty * need to upload this route * remove AEB stuff for now * remove unrequired rpm checks * add comment * added comment about acceleration and use throttle limit for rpm too * inactive_throttle_fix * Update board/safety/safety_subaru.h Co-authored-by: Shane Smiskol <shane@smiskol.com> * added comments about long limits * increase max brake * revert that * cleanup * rename throttle to gas * add safety replay * remove todo * rename throttle to gas * move subaru stuff out of common test * PR cleanup * added min gas * reduce initial complexity by not intercepting cruisecontrol or brake_status * create common gas brake safety test * remove unrelated subaru reference * also test below min_value * fix fwd hook test * better name and hardcoded * use same as acceleration limits * revert gm * remove callable * also limit rpm * remove safety replay for now * revert unrelated changes * pr cleanup * remove unused gasbrake safety test * fix ruff linter * PR cleanup * pr cleanup? * added common brake test and moved generic test to base safety class * remove duplicate test * wip * wip * rename longitudinalaccelsafety * revert limits correct test * fix controls allowed test * move gm over to long gas brake test * assert that limits are reasonable * fix typing * fix linter again * fix linter again * fix linter again * like to make it clear * typo * fix from merge * clearer names * dont need thesemore * subaru: use common test * fix merge issue * inactive gas from long limits * fix tests * linter * fix gen2 * fix linter * also test torque when doing long control * renamre transmision rpm * consistent whitespace * rename declarations too * rename transmission rpm * same line * actually is transmission rpm --------- Co-authored-by: Martin Lillepuu <martin@mlp.ee> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Shane Smiskol <shane@smiskol.com>
2023-08-16 09:51:13 +08:00
class TestSubaruGen1LongitudinalSafety(TestSubaruLongitudinalSafetyBase, TestSubaruTorqueSafetyBase):
FLAGS = Panda.FLAG_SUBARU_LONG
TX_MSGS = lkas_tx_msgs(SUBARU_MAIN_BUS) + long_tx_msgs(SUBARU_MAIN_BUS)
class TestSubaruGen2LongitudinalSafety(TestSubaruLongitudinalSafetyBase, TestSubaruGen2TorqueSafetyBase):
FLAGS = Panda.FLAG_SUBARU_LONG | Panda.FLAG_SUBARU_GEN2
TX_MSGS = lkas_tx_msgs(SUBARU_ALT_BUS) + long_tx_msgs(SUBARU_ALT_BUS) + gen2_long_additional_tx_msgs()
def _rdbi_msg(self, did: int):
return b'\x03\x22' + did.to_bytes(2) + b'\x00\x00\x00\x00'
def _es_uds_msg(self, msg: bytes):
return libpanda_py.make_CANPacket(SubaruMsg.ES_UDS_Request, 2, msg)
def test_es_uds_message(self):
tester_present = b'\x02\x3E\x80\x00\x00\x00\x00\x00'
not_tester_present = b"\x03\xAA\xAA\x00\x00\x00\x00\x00"
button_did = 0x1130
# Tester present is allowed for gen2 long to keep eyesight disabled
self.assertTrue(self._tx(self._es_uds_msg(tester_present)))
# Non-Tester present is not allowed
self.assertFalse(self._tx(self._es_uds_msg(not_tester_present)))
# Only button_did is allowed to be read via UDS
for did in range(0xFFFF):
should_tx = (did == button_did)
self.assertEqual(self._tx(self._es_uds_msg(self._rdbi_msg(did))), should_tx)
# any other msg is not allowed
for sid in range(0xFF):
msg = b'\x03' + sid.to_bytes(1) + b'\x00' * 6
self.assertFalse(self._tx(self._es_uds_msg(msg)))
Subaru: Global gen1 longitudinal safety (#1500) * Add subaru long TX and RX messages * misra c2012 fix * fix tests * Reorder signals * increase max steering torque * merge fix * merge fix, remove cnt from test * Move subaru logitudinal behind flag, add safety test * update subaru_longitudinal checks * cleanup * Add subaru longitudinal checks * misra fix * Add subaru rpm and throttle rate limit checks * temporary disable cruise throttle and cruise rpm checks * update subaru long test * update longitudinal safety and add tests * fix tests * fix misra * subaru long signals limits checks * Add controls_allowed to long tests * remove unused variables * Add AEB passthru and tests * Add bus * Update AEB logic * Add GEN2 AEB support * syntax fix * Update AEB tests * Add comment for subaru_aeb * Do not check cruise_throttle and cruise_rpm limits when gas pressed * use long limits struct * Subaru: longitudinal checks only when controls_allowed, use ES_LKAS_State LKAS_Alert for AEB * fix misra, set controls_allowed for es_brake test * fix misra * Fix es_brake violation check * Add 0x323 to longitudinal test * Remove stock fcw from aeb signals * Use GET_BYTES * Revert "export FW_PATH" This reverts commit 2a5058d858b36ff7dc5477119a54f0aab137b266. * Revert "cleanup fw filename conventions (#1434)" This reverts commit 4dd2735e38b63940ca1e1f42b4522ca4c1a0a1cc. * Revert "Revert "export FW_PATH"" This reverts commit 86e8d321d055c5f89cde7ee26a0014df1bcd5b39. * Revert "Revert "cleanup fw filename conventions (#1434)"" This reverts commit 5aae6716fa5506aac49dadd287229a45f0a3b94e. * cleaned up safety * cleanup subaru long safety * subaru_aeb -> stock_aeb for other platforms * fix unittests * pretty * need to upload this route * remove AEB stuff for now * remove unrequired rpm checks * add comment * added comment about acceleration and use throttle limit for rpm too * inactive_throttle_fix * Update board/safety/safety_subaru.h Co-authored-by: Shane Smiskol <shane@smiskol.com> * added comments about long limits * increase max brake * revert that * cleanup * rename throttle to gas * add safety replay * remove todo * rename throttle to gas * move subaru stuff out of common test * PR cleanup * added min gas * reduce initial complexity by not intercepting cruisecontrol or brake_status * create common gas brake safety test * remove unrelated subaru reference * also test below min_value * fix fwd hook test * better name and hardcoded * use same as acceleration limits * revert gm * remove callable * also limit rpm * remove safety replay for now * revert unrelated changes * pr cleanup * remove unused gasbrake safety test * fix ruff linter * PR cleanup * pr cleanup? * added common brake test and moved generic test to base safety class * remove duplicate test * wip * wip * rename longitudinalaccelsafety * revert limits correct test * fix controls allowed test * move gm over to long gas brake test * assert that limits are reasonable * fix typing * fix linter again * fix linter again * fix linter again * like to make it clear * typo * fix from merge * clearer names * dont need thesemore * subaru: use common test * fix merge issue * inactive gas from long limits * fix tests * linter * fix gen2 * fix linter * also test torque when doing long control * renamre transmision rpm * consistent whitespace * rename declarations too * rename transmission rpm * same line * actually is transmission rpm --------- Co-authored-by: Martin Lillepuu <martin@mlp.ee> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Shane Smiskol <shane@smiskol.com>
2023-08-16 09:51:13 +08:00
2019-03-14 02:52:50 +08:00
if __name__ == "__main__":
unittest.main()