mirror of https://github.com/commaai/panda.git
Tesla: add longitudinal controls allowed safety (#890)
* no long actuation if controls not allowed * comment (bump) * don't compare floats * tesla longitudinal test * clean up * forgot all * update constant * fix
This commit is contained in:
parent
c8f6cb0dd3
commit
31d70299ae
|
@ -26,6 +26,8 @@ const CanMsg TESLA_PT_TX_MSGS[] = {
|
|||
};
|
||||
#define TESLA_PT_TX_LEN (sizeof(TESLA_PT_TX_MSGS) / sizeof(TESLA_PT_TX_MSGS[0]))
|
||||
|
||||
const int TESLA_NO_ACCEL_VALUE = 375; // value sent when not requesting acceleration
|
||||
|
||||
AddrCheckStruct tesla_addr_checks[] = {
|
||||
{.msg = {{0x370, 0, 8, .expected_timestep = 40000U}, { 0 }, { 0 }}}, // EPAS_sysStatus (25Hz)
|
||||
{.msg = {{0x108, 0, 8, .expected_timestep = 10000U}, { 0 }, { 0 }}}, // DI_torque1 (100Hz)
|
||||
|
@ -192,6 +194,13 @@ static int tesla_tx_hook(CANPacket_t *to_send) {
|
|||
if ((accel_max < TESLA_MIN_ACCEL) || (accel_min < TESLA_MIN_ACCEL)){
|
||||
violation = true;
|
||||
}
|
||||
|
||||
// Don't allow longitudinal actuation if controls aren't allowed
|
||||
if (!controls_allowed) {
|
||||
if ((raw_accel_max != TESLA_NO_ACCEL_VALUE) || (raw_accel_min != TESLA_NO_ACCEL_VALUE)) {
|
||||
violation = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
violation = true;
|
||||
}
|
||||
|
|
|
@ -177,15 +177,18 @@ class TestTeslaLongitudinalSafety(TestTeslaSafety):
|
|||
self.assertEqual(self._tx(self._long_control_msg(10, aeb_event=aeb_event)), aeb_event == 0)
|
||||
|
||||
def test_acc_accel_limits(self):
|
||||
for min_accel in np.arange(MIN_ACCEL - 1, MAX_ACCEL + 1, 0.1):
|
||||
for max_accel in np.arange(MIN_ACCEL - 1, MAX_ACCEL + 1, 0.1):
|
||||
# floats might not hit exact boundary conditions without rounding
|
||||
min_accel = round(min_accel, 2)
|
||||
max_accel = round(max_accel, 2)
|
||||
|
||||
self.safety.set_controls_allowed(True)
|
||||
send = (MIN_ACCEL <= min_accel <= MAX_ACCEL) and (MIN_ACCEL <= max_accel <= MAX_ACCEL)
|
||||
self.assertEqual(self._tx(self._long_control_msg(10, acc_val=4, accel_limits=[min_accel, max_accel])), send)
|
||||
for controls_allowed in [True, False]:
|
||||
self.safety.set_controls_allowed(controls_allowed)
|
||||
for min_accel in np.arange(MIN_ACCEL - 1, MAX_ACCEL + 1, 0.1):
|
||||
for max_accel in np.arange(MIN_ACCEL - 1, MAX_ACCEL + 1, 0.1):
|
||||
# floats might not hit exact boundary conditions without rounding
|
||||
min_accel = round(min_accel, 2)
|
||||
max_accel = round(max_accel, 2)
|
||||
if controls_allowed:
|
||||
send = (MIN_ACCEL <= min_accel <= MAX_ACCEL) and (MIN_ACCEL <= max_accel <= MAX_ACCEL)
|
||||
else:
|
||||
send = np.all(np.isclose([min_accel, max_accel], 0, atol=0.0001))
|
||||
self.assertEqual(send, self._tx(self._long_control_msg(10, acc_val=4, accel_limits=[min_accel, max_accel])))
|
||||
|
||||
class TestTeslaChassisLongitudinalSafety(TestTeslaLongitudinalSafety):
|
||||
TX_MSGS = [[0x488, 0], [0x45, 0], [0x45, 2], [0x2B9, 0]]
|
||||
|
|
Loading…
Reference in New Issue