mirror of https://github.com/commaai/panda.git
honda bosch longitudinal safety
This commit is contained in:
parent
66250c41d3
commit
c31b899a58
|
@ -14,6 +14,7 @@
|
|||
#define GET_BYTE(msg, b) (((int)(b) > 3) ? (((msg)->RDHR >> (8U * ((unsigned int)(b) % 4U))) & 0xFFU) : (((msg)->RDLR >> (8U * (unsigned int)(b))) & 0xFFU))
|
||||
#define GET_BYTES_04(msg) ((msg)->RDLR)
|
||||
#define GET_BYTES_48(msg) ((msg)->RDHR)
|
||||
#define GET_FLAG(value, mask) (((__typeof__(mask))param & mask) == mask)
|
||||
|
||||
#define CAN_INIT_TIMEOUT_MS 500U
|
||||
#define CAN_NAME_FROM_CANIF(CAN_DEV) (((CAN_DEV)==CAN1) ? "CAN1" : (((CAN_DEV) == CAN2) ? "CAN2" : "CAN3"))
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
const CanMsg HONDA_N_TX_MSGS[] = {{0xE4, 0, 5}, {0x194, 0, 4}, {0x1FA, 0, 8}, {0x200, 0, 6}, {0x30C, 0, 8}, {0x33D, 0, 5}};
|
||||
const CanMsg HONDA_BG_TX_MSGS[] = {{0xE4, 2, 5}, {0xE5, 2, 8}, {0x296, 0, 4}, {0x33D, 2, 5}}; // Bosch Giraffe
|
||||
const CanMsg HONDA_BH_TX_MSGS[] = {{0xE4, 0, 5}, {0xE5, 0, 8}, {0x296, 1, 4}, {0x33D, 0, 5}}; // Bosch Harness
|
||||
const CanMsg HONDA_BG_LONG_TX_MSGS[] = {{0xE4, 0, 5}, {0x1DF, 0, 8}, {0x1EF, 0, 8}, {0x1FA, 0, 8}, {0x30C, 0, 8}, {0x33D, 0, 5}, {0x39F, 0, 8}, {0x18DAB0F1, 0, 8}}; // Bosch Giraffe w/ gas and brakes
|
||||
const CanMsg HONDA_BH_LONG_TX_MSGS[] = {{0xE4, 1, 5}, {0x1DF, 1, 8}, {0x1EF, 1, 8}, {0x1FA, 1, 8}, {0x30C, 1, 8}, {0x33D, 1, 5}, {0x39F, 1, 8}, {0x18DAB0F1, 1, 8}}; // Bosch Harness w/ gas and brakes
|
||||
|
||||
// Roughly calculated using the offsets in openpilot +5%:
|
||||
// In openpilot: ((gas1_norm + gas2_norm)/2) > 15
|
||||
|
@ -18,12 +20,16 @@ const CanMsg HONDA_BH_TX_MSGS[] = {{0xE4, 0, 5}, {0xE5, 0, 8}, {0x296, 1, 4}, {0
|
|||
// In this safety: ((gas1 + (gas2/2))/2) > THRESHOLD
|
||||
const int HONDA_GAS_INTERCEPTOR_THRESHOLD = 344;
|
||||
#define HONDA_GET_INTERCEPTOR(msg) (((GET_BYTE((msg), 0) << 8) + GET_BYTE((msg), 1) + ((GET_BYTE((msg), 2) << 8) + GET_BYTE((msg), 3)) / 2 ) / 2) // avg between 2 tracks
|
||||
const int HONDA_BOSCH_NO_GAS_VALUE = -30000; // value sent when not requesting gas
|
||||
const int HONDA_BOSCH_GAS_MAX = 2000;
|
||||
const int HONDA_BOSCH_ACCEL_MIN = -350; // max braking == -3.5m/s2
|
||||
|
||||
// Nidec and Bosch giraffe have pt on bus 0
|
||||
AddrCheckStruct honda_rx_checks[] = {
|
||||
{.msg = {{0x1A6, 0, 8}, {0x296, 0, 4}}, .check_checksum = true, .max_counter = 3U, .expected_timestep = 40000U},
|
||||
{.msg = {{0x158, 0, 8}}, .check_checksum = true, .max_counter = 3U, .expected_timestep = 10000U},
|
||||
{.msg = {{0x17C, 0, 8}}, .check_checksum = true, .max_counter = 3U, .expected_timestep = 10000U},
|
||||
{.msg = {{0x1BE, 0, 3}}, .check_checksum = true, .max_counter = 3U, .expected_timestep = 10000U},
|
||||
};
|
||||
const int HONDA_RX_CHECKS_LEN = sizeof(honda_rx_checks) / sizeof(honda_rx_checks[0]);
|
||||
|
||||
|
@ -32,12 +38,17 @@ AddrCheckStruct honda_bh_rx_checks[] = {
|
|||
{.msg = {{0x296, 1, 4}}, .check_checksum = true, .max_counter = 3U, .expected_timestep = 40000U},
|
||||
{.msg = {{0x158, 1, 8}}, .check_checksum = true, .max_counter = 3U, .expected_timestep = 10000U},
|
||||
{.msg = {{0x17C, 1, 8}}, .check_checksum = true, .max_counter = 3U, .expected_timestep = 10000U},
|
||||
{.msg = {{0x1BE, 1, 3}}, .check_checksum = true, .max_counter = 3U, .expected_timestep = 10000U},
|
||||
};
|
||||
const int HONDA_BH_RX_CHECKS_LEN = sizeof(honda_bh_rx_checks) / sizeof(honda_bh_rx_checks[0]);
|
||||
|
||||
const uint16_t HONDA_PARAM_ALT_BRAKE = 1;
|
||||
const uint16_t HONDA_PARAM_BOSCH_LONG = 2;
|
||||
|
||||
int honda_brake = 0;
|
||||
bool honda_alt_brake_msg = false;
|
||||
bool honda_fwd_brake = false;
|
||||
bool honda_bosch_long = false;
|
||||
enum {HONDA_N_HW, HONDA_BG_HW, HONDA_BH_HW} honda_hw = HONDA_N_HW;
|
||||
|
||||
|
||||
|
@ -191,10 +202,14 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||
int addr = GET_ADDR(to_send);
|
||||
int bus = GET_BUS(to_send);
|
||||
|
||||
if (honda_hw == HONDA_BG_HW) {
|
||||
if ((honda_hw == HONDA_BG_HW) && !honda_bosch_long) {
|
||||
tx = msg_allowed(to_send, HONDA_BG_TX_MSGS, sizeof(HONDA_BG_TX_MSGS)/sizeof(HONDA_BG_TX_MSGS[0]));
|
||||
} else if (honda_hw == HONDA_BH_HW) {
|
||||
} else if ((honda_hw == HONDA_BG_HW) && honda_bosch_long) {
|
||||
tx = msg_allowed(to_send, HONDA_BG_LONG_TX_MSGS, sizeof(HONDA_BG_LONG_TX_MSGS)/sizeof(HONDA_BG_LONG_TX_MSGS[0]));
|
||||
} else if ((honda_hw == HONDA_BH_HW) && !honda_bosch_long) {
|
||||
tx = msg_allowed(to_send, HONDA_BH_TX_MSGS, sizeof(HONDA_BH_TX_MSGS)/sizeof(HONDA_BH_TX_MSGS[0]));
|
||||
} else if ((honda_hw == HONDA_BH_HW) && honda_bosch_long) {
|
||||
tx = msg_allowed(to_send, HONDA_BH_LONG_TX_MSGS, sizeof(HONDA_BH_LONG_TX_MSGS)/sizeof(HONDA_BH_LONG_TX_MSGS[0]));
|
||||
} else {
|
||||
tx = msg_allowed(to_send, HONDA_N_TX_MSGS, sizeof(HONDA_N_TX_MSGS)/sizeof(HONDA_N_TX_MSGS[0]));
|
||||
}
|
||||
|
@ -211,9 +226,10 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||
pedal_pressed = pedal_pressed || gas_pressed_prev || (gas_interceptor_prev > HONDA_GAS_INTERCEPTOR_THRESHOLD);
|
||||
}
|
||||
bool current_controls_allowed = controls_allowed && !(pedal_pressed);
|
||||
int bus_pt = (honda_hw == HONDA_BH_HW)? 1 : 0;
|
||||
|
||||
// BRAKE: safety check
|
||||
if ((addr == 0x1FA) && (bus == 0)) {
|
||||
// BRAKE: safety check (nidec)
|
||||
if ((addr == 0x1FA) && (bus == bus_pt)) {
|
||||
honda_brake = (GET_BYTE(to_send, 0) << 2) + ((GET_BYTE(to_send, 1) >> 6) & 0x3);
|
||||
if (!current_controls_allowed) {
|
||||
if (honda_brake != 0) {
|
||||
|
@ -228,6 +244,31 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||
}
|
||||
}
|
||||
|
||||
// BRAKE/GAS: safety check (bosch)
|
||||
if ((addr == 0x1DF) && (bus == bus_pt)) {
|
||||
int accel = (GET_BYTE(to_send, 3) << 3) | ((GET_BYTE(to_send, 4) >> 5) & 0x7);
|
||||
accel = to_signed(accel, 11);
|
||||
if (!current_controls_allowed) {
|
||||
if (accel != 0) {
|
||||
tx = 0;
|
||||
}
|
||||
}
|
||||
if (accel < HONDA_BOSCH_ACCEL_MIN) {
|
||||
tx = 0;
|
||||
}
|
||||
|
||||
int gas = (GET_BYTE(to_send, 0) << 8) | GET_BYTE(to_send, 1);
|
||||
gas = to_signed(gas, 16);
|
||||
if (!current_controls_allowed) {
|
||||
if (gas != HONDA_BOSCH_NO_GAS_VALUE) {
|
||||
tx = 0;
|
||||
}
|
||||
}
|
||||
if (gas > HONDA_BOSCH_GAS_MAX) {
|
||||
tx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// STEER: safety check
|
||||
if ((addr == 0xE4) || (addr == 0x194)) {
|
||||
if (!current_controls_allowed) {
|
||||
|
@ -245,7 +286,7 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||
}
|
||||
}
|
||||
|
||||
// GAS: safety check
|
||||
// GAS: safety check (interceptor)
|
||||
if (addr == 0x200) {
|
||||
if (!current_controls_allowed) {
|
||||
if (GET_BYTE(to_send, 0) || GET_BYTE(to_send, 1)) {
|
||||
|
@ -257,7 +298,6 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||
// FORCE CANCEL: safety check only relevant when spamming the cancel button in Bosch HW
|
||||
// ensuring that only the cancel button press is sent (VAL 2) when controls are off.
|
||||
// This avoids unintended engagements while still allowing resume spam
|
||||
int bus_pt = (honda_hw == HONDA_BH_HW)? 1 : 0;
|
||||
if ((addr == 0x296) && !current_controls_allowed && (bus == bus_pt)) {
|
||||
if (((GET_BYTE(to_send, 0) >> 5) & 0x7) != 2) {
|
||||
tx = 0;
|
||||
|
@ -275,6 +315,7 @@ static void honda_nidec_init(int16_t param) {
|
|||
gas_interceptor_detected = 0;
|
||||
honda_hw = HONDA_N_HW;
|
||||
honda_alt_brake_msg = false;
|
||||
honda_bosch_long = false;
|
||||
}
|
||||
|
||||
static void honda_bosch_giraffe_init(int16_t param) {
|
||||
|
@ -282,7 +323,9 @@ static void honda_bosch_giraffe_init(int16_t param) {
|
|||
relay_malfunction_reset();
|
||||
honda_hw = HONDA_BG_HW;
|
||||
// Checking for alternate brake override from safety parameter
|
||||
honda_alt_brake_msg = (param == 1) ? true : false;
|
||||
honda_alt_brake_msg = GET_FLAG(param, HONDA_PARAM_ALT_BRAKE);
|
||||
// radar disabled so allow gas/brakes
|
||||
honda_bosch_long = GET_FLAG(param, HONDA_PARAM_BOSCH_LONG);
|
||||
}
|
||||
|
||||
static void honda_bosch_harness_init(int16_t param) {
|
||||
|
@ -290,7 +333,9 @@ static void honda_bosch_harness_init(int16_t param) {
|
|||
relay_malfunction_reset();
|
||||
honda_hw = HONDA_BH_HW;
|
||||
// Checking for alternate brake override from safety parameter
|
||||
honda_alt_brake_msg = (param == 1) ? true : false;
|
||||
honda_alt_brake_msg = GET_FLAG(param, HONDA_PARAM_ALT_BRAKE);
|
||||
// radar disabled so allow gas/brakes
|
||||
honda_bosch_long = GET_FLAG(param, HONDA_PARAM_BOSCH_LONG);
|
||||
}
|
||||
|
||||
static int honda_nidec_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
|
||||
|
|
|
@ -66,6 +66,7 @@ void init_tests(void);
|
|||
void init_tests_honda(void);
|
||||
void set_honda_fwd_brake(bool);
|
||||
void set_honda_alt_brake_msg(bool);
|
||||
void set_honda_bosch_long(bool c);
|
||||
int get_honda_hw(void);
|
||||
|
||||
void init_tests_chrysler(void);
|
||||
|
|
|
@ -71,6 +71,7 @@ void fault_recovered(uint32_t fault) {
|
|||
#define GET_BYTE(msg, b) (((int)(b) > 3) ? (((msg)->RDHR >> (8U * ((unsigned int)(b) % 4U))) & 0XFFU) : (((msg)->RDLR >> (8U * (unsigned int)(b))) & 0xFFU))
|
||||
#define GET_BYTES_04(msg) ((msg)->RDLR)
|
||||
#define GET_BYTES_48(msg) ((msg)->RDHR)
|
||||
#define GET_FLAG(value, mask) (((__typeof__(mask))param & mask) == mask)
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
|
@ -183,6 +184,10 @@ void set_honda_alt_brake_msg(bool c){
|
|||
honda_alt_brake_msg = c;
|
||||
}
|
||||
|
||||
void set_honda_bosch_long(bool c){
|
||||
honda_bosch_long = c;
|
||||
}
|
||||
|
||||
int get_honda_hw(void) {
|
||||
return honda_hw;
|
||||
}
|
||||
|
|
|
@ -7,8 +7,6 @@ import panda.tests.safety.common as common
|
|||
from panda.tests.safety.common import CANPackerPanda, make_msg, \
|
||||
MAX_WRONG_COUNTERS, UNSAFE_MODE
|
||||
|
||||
MAX_BRAKE = 255
|
||||
|
||||
class Btn:
|
||||
CANCEL = 2
|
||||
SET = 3
|
||||
|
@ -20,11 +18,14 @@ HONDA_BH_HW = 2
|
|||
|
||||
|
||||
class TestHondaSafety(common.PandaSafetyTest):
|
||||
MAX_BRAKE = 255
|
||||
PT_BUS = None # must be set when inherited
|
||||
STEER_BUS = None # must be set when inherited
|
||||
|
||||
cnt_speed = 0
|
||||
cnt_gas = 0
|
||||
cnt_button = 0
|
||||
|
||||
PT_BUS = 0
|
||||
cnt_brake = 0
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
@ -58,15 +59,13 @@ class TestHondaSafety(common.PandaSafetyTest):
|
|||
self.__class__.cnt_gas += 1
|
||||
return self.packer.make_can_msg_panda("POWERTRAIN_DATA", self.PT_BUS, values)
|
||||
|
||||
def _send_brake_msg(self, brake):
|
||||
values = {}
|
||||
if self.safety.get_honda_hw() == HONDA_N_HW:
|
||||
values = {"COMPUTER_BRAKE": brake}
|
||||
return self.packer.make_can_msg_panda("BRAKE_COMMAND", 0, values)
|
||||
|
||||
def _send_steer_msg(self, steer):
|
||||
values = {"STEER_TORQUE": steer}
|
||||
return self.packer.make_can_msg_panda("STEERING_CONTROL", 0, values)
|
||||
return self.packer.make_can_msg_panda("STEERING_CONTROL", self.STEER_BUS, values)
|
||||
|
||||
def _send_brake_msg(self, brake):
|
||||
# must be implemented when inherited
|
||||
raise NotImplementedError()
|
||||
|
||||
def test_resume_button(self):
|
||||
self.safety.set_controls_allowed(0)
|
||||
|
@ -157,13 +156,14 @@ class TestHondaSafety(common.PandaSafetyTest):
|
|||
hw = self.safety.get_honda_hw()
|
||||
if hw == HONDA_N_HW:
|
||||
self.safety.set_honda_fwd_brake(False)
|
||||
self.assertEqual(allow_ctrl, self._tx(self._send_brake_msg(MAX_BRAKE)))
|
||||
self.assertEqual(allow_ctrl, self._tx(self._send_brake_msg(self.MAX_BRAKE)))
|
||||
self.assertEqual(allow_ctrl, self._tx(self._send_steer_msg(0x1000)))
|
||||
|
||||
# reset status
|
||||
self.safety.set_controls_allowed(0)
|
||||
self.safety.set_unsafe_mode(UNSAFE_MODE.DEFAULT)
|
||||
self._tx(self._send_brake_msg(0))
|
||||
if hw == HONDA_N_HW:
|
||||
self._tx(self._send_brake_msg(0))
|
||||
self._tx(self._send_steer_msg(0))
|
||||
if pedal == 'brake':
|
||||
self._rx(self._speed_msg(0))
|
||||
|
@ -181,6 +181,9 @@ class TestHondaNidecSafety(TestHondaSafety, common.InterceptorSafetyTest):
|
|||
FWD_BLACKLISTED_ADDRS = {2: [0xE4, 0x194, 0x33D, 0x30C]}
|
||||
FWD_BUS_LOOKUP = {0: 2, 2: 0}
|
||||
|
||||
PT_BUS = 0
|
||||
STEER_BUS = 0
|
||||
|
||||
INTERCEPTOR_THRESHOLD = 344
|
||||
|
||||
def setUp(self):
|
||||
|
@ -197,6 +200,10 @@ class TestHondaNidecSafety(TestHondaSafety, common.InterceptorSafetyTest):
|
|||
((gas2 & 0xff) << 24) | ((gas2 & 0xff00) << 8)
|
||||
return to_send
|
||||
|
||||
def _send_brake_msg(self, brake):
|
||||
values = {"COMPUTER_BRAKE": brake}
|
||||
return self.packer.make_can_msg_panda("BRAKE_COMMAND", 0, values)
|
||||
|
||||
def test_fwd_hook(self):
|
||||
# normal operation, not forwarding AEB
|
||||
self.FWD_BLACKLISTED_ADDRS[2].append(0x1FA)
|
||||
|
@ -212,13 +219,13 @@ class TestHondaNidecSafety(TestHondaSafety, common.InterceptorSafetyTest):
|
|||
def test_brake_safety_check(self):
|
||||
for fwd_brake in [False, True]:
|
||||
self.safety.set_honda_fwd_brake(fwd_brake)
|
||||
for brake in np.arange(0, MAX_BRAKE + 10, 1):
|
||||
for brake in np.arange(0, self.MAX_BRAKE + 10, 1):
|
||||
for controls_allowed in [True, False]:
|
||||
self.safety.set_controls_allowed(controls_allowed)
|
||||
if fwd_brake:
|
||||
send = False # block openpilot brake msg when fwd'ing stock msg
|
||||
elif controls_allowed:
|
||||
send = MAX_BRAKE >= brake >= 0
|
||||
send = self.MAX_BRAKE >= brake >= 0
|
||||
else:
|
||||
send = brake == 0
|
||||
self.assertEqual(send, self._tx(self._send_brake_msg(brake)))
|
||||
|
@ -234,7 +241,7 @@ class TestHondaNidecSafety(TestHondaSafety, common.InterceptorSafetyTest):
|
|||
|
||||
self.safety.set_controls_allowed(1)
|
||||
self.safety.set_honda_fwd_brake(False)
|
||||
self.assertEqual(allow_ctrl, self._tx(self._send_brake_msg(MAX_BRAKE)))
|
||||
self.assertEqual(allow_ctrl, self._tx(self._send_brake_msg(self.MAX_BRAKE)))
|
||||
self.assertEqual(allow_ctrl, self._tx(self._interceptor_msg(self.INTERCEPTOR_THRESHOLD, 0x200)))
|
||||
self.assertEqual(allow_ctrl, self._tx(self._send_steer_msg(0x1000)))
|
||||
|
||||
|
@ -247,35 +254,34 @@ class TestHondaNidecSafety(TestHondaSafety, common.InterceptorSafetyTest):
|
|||
self.safety.set_gas_interceptor_detected(False)
|
||||
|
||||
|
||||
class TestHondaBoschHarnessSafety(TestHondaSafety):
|
||||
TX_MSGS = [[0xE4, 0], [0xE5, 0], [0x296, 1], [0x33D, 0]] # Bosch Harness
|
||||
class TestHondaBoschSafety(TestHondaSafety):
|
||||
STANDSTILL_THRESHOLD = 0
|
||||
RELAY_MALFUNCTION_ADDR = 0xE4
|
||||
RELAY_MALFUNCTION_BUS = 0
|
||||
FWD_BLACKLISTED_ADDRS = {2: [0xE4, 0xE5, 0x33D]}
|
||||
FWD_BUS_LOOKUP = {0: 2, 2: 0}
|
||||
|
||||
PT_BUS = 1
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
if cls.__name__ == "TestHondaBoschSafety":
|
||||
cls.packer = None
|
||||
cls.safety = None
|
||||
raise unittest.SkipTest
|
||||
|
||||
def setUp(self):
|
||||
self.packer = CANPackerPanda("honda_accord_s2t_2018_can_generated")
|
||||
self.safety = libpandasafety_py.libpandasafety
|
||||
self.safety.set_safety_hooks(Panda.SAFETY_HONDA_BOSCH_HARNESS, 0)
|
||||
self.safety.init_tests_honda()
|
||||
|
||||
def _alt_brake_msg(self, brake):
|
||||
to_send = make_msg(0, 0x1BE)
|
||||
to_send[0].RDLR = 0x10 if brake else 0
|
||||
return to_send
|
||||
values = {"BRAKE_PRESSED": brake, "COUNTER": self.cnt_brake % 4}
|
||||
self.__class__.cnt_brake += 1
|
||||
return self.packer.make_can_msg_panda("BRAKE_MODULE", self.PT_BUS, values)
|
||||
|
||||
def test_spam_cancel_safety_check(self):
|
||||
self.safety.set_controls_allowed(0)
|
||||
self.assertTrue(self._tx(self._button_msg(Btn.CANCEL)))
|
||||
self.assertFalse(self._tx(self._button_msg(Btn.RESUME)))
|
||||
self.assertFalse(self._tx(self._button_msg(Btn.SET)))
|
||||
# do not block resume if we are engaged already
|
||||
def test_alt_brake_rx_hook(self):
|
||||
self.safety.set_honda_alt_brake_msg(1)
|
||||
self.safety.set_controls_allowed(1)
|
||||
self.assertTrue(self._tx(self._button_msg(Btn.RESUME)))
|
||||
to_push = self._alt_brake_msg(0)
|
||||
self.assertTrue(self._rx(to_push))
|
||||
to_push[0].RDLR = to_push[0].RDLR & 0xFFF0FFFF # invalidate checksum
|
||||
self.assertFalse(self._rx(to_push))
|
||||
self.assertFalse(self.safety.get_controls_allowed())
|
||||
|
||||
def test_alt_disengage_on_brake(self):
|
||||
self.safety.set_honda_alt_brake_msg(1)
|
||||
|
@ -289,25 +295,108 @@ class TestHondaBoschHarnessSafety(TestHondaSafety):
|
|||
self.assertTrue(self.safety.get_controls_allowed())
|
||||
|
||||
|
||||
class TestHondaBoschHarnessSafety(TestHondaBoschSafety):
|
||||
TX_MSGS = [[0xE4, 0], [0xE5, 0], [0x296, 1], [0x33D, 0]] # Bosch Harness
|
||||
RELAY_MALFUNCTION_BUS = 0
|
||||
FWD_BLACKLISTED_ADDRS = {2: [0xE4, 0xE5, 0x33D]}
|
||||
FWD_BUS_LOOKUP = {0: 2, 2: 0}
|
||||
|
||||
PT_BUS = 1
|
||||
STEER_BUS = 0
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.safety.set_safety_hooks(Panda.SAFETY_HONDA_BOSCH_HARNESS, 0)
|
||||
self.safety.init_tests_honda()
|
||||
|
||||
def test_spam_cancel_safety_check(self):
|
||||
self.safety.set_controls_allowed(0)
|
||||
self.assertTrue(self._tx(self._button_msg(Btn.CANCEL)))
|
||||
self.assertFalse(self._tx(self._button_msg(Btn.RESUME)))
|
||||
self.assertFalse(self._tx(self._button_msg(Btn.SET)))
|
||||
# do not block resume if we are engaged already
|
||||
self.safety.set_controls_allowed(1)
|
||||
self.assertTrue(self._tx(self._button_msg(Btn.RESUME)))
|
||||
|
||||
|
||||
class TestHondaBoschGiraffeSafety(TestHondaBoschHarnessSafety):
|
||||
TX_MSGS = [[0xE4, 2], [0xE5, 2], [0x296, 0], [0x33D, 2]] # Bosch Giraffe
|
||||
STANDSTILL_THRESHOLD = 0
|
||||
RELAY_MALFUNCTION_ADDR = 0xE4
|
||||
RELAY_MALFUNCTION_BUS = 2
|
||||
FWD_BLACKLISTED_ADDRS = {1: [0xE4, 0xE5, 0x33D]}
|
||||
FWD_BUS_LOOKUP = {1: 2, 2: 1}
|
||||
|
||||
PT_BUS = 0
|
||||
STEER_BUS = 2
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.safety = libpandasafety_py.libpandasafety
|
||||
self.safety.set_safety_hooks(Panda.SAFETY_HONDA_BOSCH_GIRAFFE, 0)
|
||||
self.safety.init_tests_honda()
|
||||
|
||||
def _send_steer_msg(self, steer):
|
||||
values = {"STEER_TORQUE": steer}
|
||||
return self.packer.make_can_msg_panda("STEERING_CONTROL", 2, values)
|
||||
|
||||
class TestHondaBoschLongSafety(TestHondaBoschSafety):
|
||||
NO_GAS = -30000
|
||||
MAX_GAS = 2000
|
||||
MAX_BRAKE = -3.5
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
if cls.__name__ == "TestHondaBoschLongSafety":
|
||||
cls.packer = None
|
||||
cls.safety = None
|
||||
raise unittest.SkipTest
|
||||
|
||||
def _send_gas_brake_msg(self, gas, accel):
|
||||
values = {
|
||||
"GAS_COMMAND": gas,
|
||||
"ACCEL_COMMAND": accel,
|
||||
"BRAKE_REQUEST": accel < 0,
|
||||
}
|
||||
return self.packer.make_can_msg_panda("ACC_CONTROL", self.PT_BUS, values)
|
||||
|
||||
def test_gas_safety_check(self):
|
||||
for controls_allowed in [True, False]:
|
||||
for gas in np.arange(self.NO_GAS, self.MAX_GAS + 2000, 100):
|
||||
accel = 0 if gas < 0 else gas / 1000
|
||||
self.safety.set_controls_allowed(controls_allowed)
|
||||
send = gas <= self.MAX_GAS if controls_allowed else gas == self.NO_GAS
|
||||
self.assertEqual(send, self.safety.safety_tx_hook(self._send_gas_brake_msg(gas, accel)), gas)
|
||||
|
||||
def test_brake_safety_check(self):
|
||||
for controls_allowed in [True, False]:
|
||||
for accel in np.arange(0, self.MAX_BRAKE - 1, -0.1):
|
||||
self.safety.set_controls_allowed(controls_allowed)
|
||||
send = self.MAX_BRAKE <= accel <= 0 if controls_allowed else accel == 0
|
||||
self.assertEqual(send, self._tx(self._send_gas_brake_msg(self.NO_GAS, accel)), (controls_allowed, accel))
|
||||
|
||||
class TestHondaBoschLongHarnessSafety(TestHondaBoschLongSafety):
|
||||
TX_MSGS = [[0xE4, 1], [0x1DF, 1], [0x1EF, 1], [0x1FA, 1], [0x30C, 1], [0x33D, 1], [0x39F, 1], [0x18DAB0F1, 1]] # Bosch Harness w/ gas and brakes
|
||||
RELAY_MALFUNCTION_BUS = 0
|
||||
FWD_BLACKLISTED_ADDRS = {2: [0xE4, 0xE5, 0x33D]}
|
||||
FWD_BUS_LOOKUP = {0: 2, 2: 0}
|
||||
|
||||
PT_BUS = 1
|
||||
STEER_BUS = 1
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.safety.set_safety_hooks(Panda.SAFETY_HONDA_BOSCH_HARNESS, 2)
|
||||
self.safety.init_tests_honda()
|
||||
|
||||
|
||||
class TestHondaBoschLongGiraffeSafety(TestHondaBoschLongSafety):
|
||||
TX_MSGS = [[0xE4, 0], [0x1DF, 0], [0x1EF, 0], [0x1FA, 0], [0x30C, 0], [0x33D, 0], [0x39F, 0], [0x18DAB0F1, 0]] # Bosch Giraffe w/ gas and brakes
|
||||
RELAY_MALFUNCTION_BUS = 2
|
||||
FWD_BLACKLISTED_ADDRS = {1: [0xE4, 0xE5, 0x33D]}
|
||||
FWD_BUS_LOOKUP = {1: 2, 2: 1}
|
||||
|
||||
PT_BUS = 0
|
||||
STEER_BUS = 0
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.safety.set_safety_hooks(Panda.SAFETY_HONDA_BOSCH_GIRAFFE, 2)
|
||||
self.safety.init_tests_honda()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in New Issue