-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mazda: safety tests add missing safety checks (#525)
* Mazda: add safety test Signed-off-by: Jafar Al-Gharaibeh <to.jafar@gmail.com> * Update mazda safety to capture more events * gas press * brake press * speed - lkas on/off Signed-off-by: Jafar Al-Gharaibeh <to.jafar@gmail.com> * Customize safety tests Signed-off-by: Jafar Al-Gharaibeh <to.jafar@gmail.com> * Add RX checks Signed-off-by: Jafar Al-Gharaibeh <to.jafar@gmail.com> * Format Signed-off-by: Jafar Al-Gharaibeh <to.jafar@gmail.com> * Set lkas enable speed at 52 kph Signed-off-by: Jafar Al-Gharaibeh <to.jafar@gmail.com> * Test case when speed<enable_lkas_speed Signed-off-by: Jafar Al-Gharaibeh <to.jafar@gmail.com> * Be consistent with names in other places Signed-off-by: Jafar Al-Gharaibeh <to.jafar@gmail.com> * Add test case for lkas on when speed dips below lkas enable speed Signed-off-by: Jafar Al-Gharaibeh <to.jafar@gmail.com> * Make sure lkas disabled Signed-off-by: Jafar Al-Gharaibeh <to.jafar@gmail.com> * Use car's speed signal instead of wheel speed Signed-off-by: Jafar Al-Gharaibeh <to.jafar@gmail.com> * Allow acc cancel msg When gas is pressed OP disenages stock cruise doesn't get disengaged. panda needs to know when OP engages again. OP re-enageges on cruise button presses. This commit uses the same re-enage logic in panda. Signed-off-by: Jafar Al-Gharaibeh <to.jafar@gmail.com> * rebase Signed-off-by: Jafar Al-Gharaibeh <to.jafar@gmail.com> * allow acc_cancel in safety tests Signed-off-by: Jafar Al-Gharaibeh <to.jafar@gmail.com> * rename variable, fix comment Signed-off-by: Jafar Al-Gharaibeh <to.jafar@gmail.com>
- Loading branch information
Showing
2 changed files
with
225 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#!/usr/bin/env python3 | ||
import unittest | ||
from panda import Panda | ||
from panda.tests.safety import libpandasafety_py | ||
import panda.tests.safety.common as common | ||
from panda.tests.safety.common import CANPackerPanda | ||
|
||
MAX_RATE_UP = 10 | ||
MAX_RATE_DOWN = 25 | ||
MAX_STEER = 2047 | ||
|
||
MAX_RT_DELTA = 940 | ||
RT_INTERVAL = 250000 | ||
|
||
DRIVER_TORQUE_ALLOWANCE = 15 | ||
DRIVER_TORQUE_FACTOR = 1 | ||
|
||
|
||
class TestMazdaSafety(common.PandaSafetyTest): | ||
|
||
TX_MSGS = [[0x243, 0], [0x09d, 0]] | ||
STANDSTILL_THRESHOLD = .1 | ||
RELAY_MALFUNCTION_ADDR = 0x243 | ||
RELAY_MALFUNCTION_BUS = 0 | ||
FWD_BLACKLISTED_ADDRS = {2: [0x243]} | ||
FWD_BUS_LOOKUP = {0: 2, 2: 0} | ||
LKAS_ENABLE_SPEED = 52 | ||
LKAS_DISABLE_SPEED = 45 | ||
|
||
def setUp(self): | ||
self.packer = CANPackerPanda("mazda_cx5_gt_2017") | ||
self.safety = libpandasafety_py.libpandasafety | ||
self.safety.set_safety_hooks(Panda.SAFETY_MAZDA, 0) | ||
self.safety.init_tests() | ||
|
||
def _torque_meas_msg(self, torque): | ||
values = {"STEER_TORQUE_MOTOR": torque} | ||
return self.packer.make_can_msg_panda("STEER_TORQUE", 0, values) | ||
|
||
# def _torque_driver_msg(self, torque): | ||
# values = {"STEER_TORQUE_DRIVER": torque} | ||
# return self.packer.make_can_msg_panda("STEER_TORQUE", 0, values) | ||
|
||
def _torque_msg(self, torque): | ||
values = {"LKAS_REQUEST": torque} | ||
return self.packer.make_can_msg_panda("CAM_LKAS", 0, values) | ||
|
||
def _speed_msg(self, s): | ||
values = {"SPEED": s} | ||
return self.packer.make_can_msg_panda("ENGINE_DATA", 0, values) | ||
|
||
def _brake_msg(self, pressed): | ||
values = {"BRAKE_ON": pressed} | ||
return self.packer.make_can_msg_panda("PEDALS", 0, values) | ||
|
||
def _gas_msg(self, pressed): | ||
values = {"PEDAL_GAS": pressed} | ||
return self.packer.make_can_msg_panda("ENGINE_DATA", 0, values) | ||
|
||
def _pcm_status_msg(self, cruise_on): | ||
values = {"CRZ_ACTIVE": cruise_on} | ||
return self.packer.make_can_msg_panda("CRZ_CTRL", 0, values) | ||
|
||
def test_enable_control_allowed_from_cruise(self): | ||
self._rx(self._pcm_status_msg(False)) | ||
self.assertFalse(self.safety.get_controls_allowed()) | ||
|
||
self._rx(self._speed_msg(self.LKAS_DISABLE_SPEED - 1)) | ||
self._rx(self._speed_msg(self.LKAS_ENABLE_SPEED - 1)) | ||
self._rx(self._pcm_status_msg(True)) | ||
self.assertFalse(self.safety.get_controls_allowed()) | ||
|
||
self._rx(self._pcm_status_msg(False)) | ||
|
||
self._rx(self._speed_msg(self.LKAS_ENABLE_SPEED + 1)) | ||
self._rx(self._speed_msg(self.LKAS_ENABLE_SPEED - 1)) | ||
self._rx(self._pcm_status_msg(True)) | ||
self.assertTrue(self.safety.get_controls_allowed()) | ||
|
||
self._rx(self._speed_msg(self.LKAS_ENABLE_SPEED + 1)) | ||
self._rx(self._pcm_status_msg(True)) | ||
self.assertTrue(self.safety.get_controls_allowed()) | ||
|
||
self._rx(self._speed_msg(self.LKAS_ENABLE_SPEED - 1)) | ||
self.assertTrue(self.safety.get_controls_allowed()) | ||
|
||
# Enabled going down | ||
self._rx(self._speed_msg(self.LKAS_DISABLE_SPEED - 1)) | ||
self.assertTrue(self.safety.get_controls_allowed()) | ||
|
||
self._rx(self._pcm_status_msg(False)) | ||
|
||
# Disabled going up | ||
self._rx(self._speed_msg(self.LKAS_DISABLE_SPEED + 1)) | ||
self._rx(self._pcm_status_msg(True)) | ||
self.assertFalse(self.safety.get_controls_allowed()) | ||
|
||
def test_cruise_engaged_prev(self): | ||
self._rx(self._pcm_status_msg(False)) | ||
self._rx(self._speed_msg(self.LKAS_ENABLE_SPEED - 1)) | ||
self._rx(self._pcm_status_msg(True)) | ||
self.assertFalse(self.safety.get_cruise_engaged_prev()) | ||
|
||
self._rx(self._speed_msg(self.LKAS_ENABLE_SPEED + 1)) | ||
|
||
for engaged in [True, False]: | ||
self._rx(self._pcm_status_msg(engaged)) | ||
self.assertEqual(engaged, self.safety.get_cruise_engaged_prev()) | ||
self._rx(self._pcm_status_msg(not engaged)) | ||
self.assertEqual(not engaged, self.safety.get_cruise_engaged_prev()) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |