mirror of https://github.com/commaai/panda.git
Mazda: only check ACC state for controls allowed (#753)
This commit is contained in:
parent
5f5f30eedc
commit
0d4e98f605
|
@ -23,12 +23,7 @@
|
|||
#define MAZDA_DRIVER_TORQUE_FACTOR 1
|
||||
#define MAZDA_MAX_TORQUE_ERROR 350
|
||||
|
||||
// lkas enable speed 52kph, disable at 45kph
|
||||
#define MAZDA_LKAS_ENABLE_SPEED 5200
|
||||
#define MAZDA_LKAS_DISABLE_SPEED 4500
|
||||
|
||||
const CanMsg MAZDA_TX_MSGS[] = {{MAZDA_LKAS, 0, 8}, {MAZDA_CRZ_BTNS, 0, 8}};
|
||||
bool mazda_lkas_allowed = false;
|
||||
|
||||
AddrCheckStruct mazda_addr_checks[] = {
|
||||
{.msg = {{MAZDA_CRZ_CTRL, 0, 8, .expected_timestep = 20000U}, { 0 }, { 0 }}},
|
||||
|
@ -49,17 +44,7 @@ static int mazda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||
if (addr == MAZDA_ENGINE_DATA) {
|
||||
// sample speed: scale by 0.01 to get kph
|
||||
int speed = (GET_BYTE(to_push, 2) << 8) | GET_BYTE(to_push, 3);
|
||||
|
||||
vehicle_moving = speed > 10; // moving when speed > 0.1 kph
|
||||
|
||||
// Enable LKAS at 52kph going up, disable at 45kph going down
|
||||
if (speed > MAZDA_LKAS_ENABLE_SPEED) {
|
||||
mazda_lkas_allowed = true;
|
||||
} else if (speed < MAZDA_LKAS_DISABLE_SPEED) {
|
||||
mazda_lkas_allowed = false;
|
||||
} else {
|
||||
// Misra-able appeasment block!
|
||||
}
|
||||
}
|
||||
|
||||
if (addr == MAZDA_STEER_TORQUE) {
|
||||
|
@ -73,13 +58,7 @@ static int mazda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||
bool cruise_engaged = GET_BYTE(to_push, 0) & 8;
|
||||
if (cruise_engaged) {
|
||||
if (!cruise_engaged_prev) {
|
||||
// do not engage until we hit the speed at which lkas is on
|
||||
if (mazda_lkas_allowed) {
|
||||
controls_allowed = 1;
|
||||
} else {
|
||||
controls_allowed = 0;
|
||||
cruise_engaged = false;
|
||||
}
|
||||
controls_allowed = 1;
|
||||
}
|
||||
} else {
|
||||
controls_allowed = 0;
|
||||
|
@ -183,7 +162,6 @@ static const addr_checks* mazda_init(int16_t param) {
|
|||
UNUSED(param);
|
||||
controls_allowed = false;
|
||||
relay_malfunction_reset();
|
||||
mazda_lkas_allowed = false;
|
||||
return &mazda_rx_checks;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,6 @@ class TestMazdaSafety(common.PandaSafetyTest):
|
|||
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_2017")
|
||||
|
@ -61,53 +59,6 @@ class TestMazdaSafety(common.PandaSafetyTest):
|
|||
values = {"CRZ_ACTIVE": enable}
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue