mirror of https://github.com/commaai/panda.git
VW: Allow inactive accel values at all times (#1247)
* allow inactive accel values at all times * cleaner * unnecessary, done by default * better comments * move test to common class * fix * flip * comment * append 0 and INACTIVE_ACCEL to test accels + check acc_07 sends if inactive only * cleanup * fix that * copy testing convention of VW and Honda --------- Co-authored-by: Shane Smiskol <shane@smiskol.com>
This commit is contained in:
parent
22b8e5df7f
commit
fddca54fd6
|
@ -493,13 +493,9 @@ float interpolate(struct lookup_t xy, float x) {
|
|||
|
||||
// Safety checks for longitudinal actuation
|
||||
bool longitudinal_accel_checks(int desired_accel, const LongitudinalLimits limits) {
|
||||
bool violation = false;
|
||||
if (!get_longitudinal_allowed()) {
|
||||
violation |= desired_accel != limits.inactive_accel;
|
||||
} else {
|
||||
violation |= max_limit_check(desired_accel, limits.max_accel, limits.min_accel);
|
||||
}
|
||||
return violation;
|
||||
bool accel_valid = get_longitudinal_allowed() && !max_limit_check(desired_accel, limits.max_accel, limits.min_accel);
|
||||
bool accel_inactive = desired_accel == limits.inactive_accel;
|
||||
return !(accel_valid || accel_inactive);
|
||||
}
|
||||
|
||||
bool longitudinal_speed_checks(int desired_speed, const LongitudinalLimits limits) {
|
||||
|
|
|
@ -156,16 +156,17 @@ class LongitudinalAccelSafetyTest(PandaSafetyTestBase, abc.ABC):
|
|||
(self.MIN_ACCEL, self.MAX_ACCEL, ALTERNATIVE_EXPERIENCE.RAISE_LONGITUDINAL_LIMITS_TO_ISO_MAX))
|
||||
|
||||
for min_accel, max_accel, alternative_experience in limits:
|
||||
for accel in np.arange(min_accel - 1, max_accel + 1, 0.05):
|
||||
# enforce we don't skip over 0 or inactive accel
|
||||
for accel in np.concatenate((np.arange(min_accel - 1, max_accel + 1, 0.05), [0, self.INACTIVE_ACCEL])):
|
||||
accel = round(accel, 2) # floats might not hit exact boundary conditions without rounding
|
||||
for controls_allowed in [True, False]:
|
||||
self.safety.set_controls_allowed(controls_allowed)
|
||||
self.safety.set_alternative_experience(alternative_experience)
|
||||
if stock_longitudinal:
|
||||
should_tx = False
|
||||
elif controls_allowed:
|
||||
should_tx = int(min_accel * 1000) <= int(accel * 1000) <= int(max_accel * 1000)
|
||||
else:
|
||||
should_tx = np.isclose(accel, self.INACTIVE_ACCEL, atol=0.0001)
|
||||
should_tx = controls_allowed and min_accel <= accel <= max_accel
|
||||
should_tx = should_tx or accel == self.INACTIVE_ACCEL
|
||||
self.assertEqual(should_tx, self._tx(self._accel_msg(accel)))
|
||||
|
||||
|
||||
|
|
|
@ -208,16 +208,18 @@ class TestVolkswagenMqbLongSafety(TestVolkswagenMqbSafety):
|
|||
|
||||
def test_accel_safety_check(self):
|
||||
for controls_allowed in [True, False]:
|
||||
for accel in np.arange(MIN_ACCEL - 2, MAX_ACCEL + 2, 0.03):
|
||||
# enforce we don't skip over 0 or inactive accel
|
||||
for accel in np.concatenate((np.arange(MIN_ACCEL - 2, MAX_ACCEL + 2, 0.03), [0, self.INACTIVE_ACCEL])):
|
||||
accel = round(accel, 2) # floats might not hit exact boundary conditions without rounding
|
||||
send = MIN_ACCEL <= accel <= MAX_ACCEL if controls_allowed else accel == self.INACTIVE_ACCEL
|
||||
is_inactive_accel = accel == self.INACTIVE_ACCEL
|
||||
send = (controls_allowed and MIN_ACCEL <= accel <= MAX_ACCEL) or is_inactive_accel
|
||||
self.safety.set_controls_allowed(controls_allowed)
|
||||
# primary accel request used by ECU
|
||||
self.assertEqual(send, self._tx(self._acc_06_msg(accel)), (controls_allowed, accel))
|
||||
# additional accel request used by ABS/ESP
|
||||
self.assertEqual(send, self._tx(self._acc_07_msg(accel)), (controls_allowed, accel))
|
||||
# ensure the optional secondary accel field remains disabled for now
|
||||
self.assertFalse(self._tx(self._acc_07_msg(accel, secondary_accel=accel)), (controls_allowed, accel))
|
||||
# ensure the optional secondary accel field remains inactive for now
|
||||
self.assertEqual(is_inactive_accel, self._tx(self._acc_07_msg(accel, secondary_accel=accel)), (controls_allowed, accel))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in New Issue