cap parked car nudge by lateral accel

This commit is contained in:
natehuby76
2026-11-27 17:42:45 -05:00
parent 5ef7a8d977
commit 3d57f1fc8e
3 changed files with 23 additions and 5 deletions
@@ -13,7 +13,8 @@ from openpilot.starpilot.lateral.parked_clearance import (
from openpilot.starpilot.saved_source import read_saved
GAIN = 0.45
MAX_CORRECTION = 0.0012
MAX_CORRECTION = 0.006
MAX_LATERAL_ACCEL = 0.5
DEFAULT_GAP = 1.5
DEFAULT_LIMIT = MAX_SHIFT
MAX_RADAR_GAP_S = 0.25
@@ -125,7 +126,7 @@ class ParkedClearanceHost:
self.reason = self.detector.reason
elif watch:
self.detector.shift, self.detector.demand, self.detector.hold, self.reason = 0.0, 0.0, 0.0, 'inactive'
self.correction = clip_scalar(-2.0 * self.detector.shift / lookahead ** 2 * GAIN, -MAX_CORRECTION * max(1.0, self.settings.limit / MAX_SHIFT), 0.0)
self.correction = clip_scalar(-2.0 * self.detector.shift / lookahead ** 2 * GAIN, -min(MAX_CORRECTION, MAX_LATERAL_ACCEL / speed ** 2), 0.0)
self.shift = float(self.detector.shift)
return self.correction
except (AttributeError, IndexError, TypeError, ValueError, OverflowError):
@@ -82,7 +82,8 @@ class TestParkedRuntime(unittest.TestCase):
def test_parked_car_steers_left_within_cap(self):
subject = host()
correction = drive(subject, 4.0, PARKED)[0]
self.assertEqual(correction, -runtime.MAX_CORRECTION)
self.assertAlmostEqual(correction, -2.0 * 0.3 / 11.0 ** 2 * runtime.GAIN, places=9)
self.assertLessEqual(-correction, min(runtime.MAX_CORRECTION, runtime.MAX_LATERAL_ACCEL / 11.0 ** 2))
self.assertEqual(subject.reason, 'parked')
subject = host(gap=1.4)
correction = drive(subject, 4.0, [(7, 20.0, -3.1, -11.0)])[0]
@@ -94,9 +95,25 @@ class TestParkedRuntime(unittest.TestCase):
self.assertAlmostEqual(drive(small, 4.0, PARKED)[0], -2.0 * 0.1 / 11.0 ** 2 * runtime.GAIN, places=7)
self.assertAlmostEqual(small.shift, 0.1, places=5)
wide = model_message(line_prob=0.05)
self.assertAlmostEqual(drive(large, 6.0, PARKED, model=wide)[0], -runtime.MAX_CORRECTION * 0.5 / 0.3, places=7)
correction = drive(large, 6.0, PARKED, model=wide)[0]
self.assertAlmostEqual(correction, -2.0 * 0.5 / 11.0 ** 2 * runtime.GAIN, places=9)
self.assertLessEqual(-correction, min(runtime.MAX_CORRECTION, runtime.MAX_LATERAL_ACCEL / 11.0 ** 2))
self.assertLessEqual(large.shift, 0.5)
def test_city_speed_shift_is_not_clipped(self):
subject = host(gap=2.0, limit=0.5)
correction = drive(subject, 6.0, [(7, 20.0, -2.6, -9.0)], speed=9.0, model=model_message(line_prob=0.05))[0]
self.assertAlmostEqual(subject.shift, 0.5, places=5)
self.assertAlmostEqual(correction, -0.9 * 0.5 / 81.0, places=9)
def test_lateral_accel_stays_bounded_at_speed(self):
subject = host(gap=2.0, limit=0.5)
start = 1_000_000_000
for _ in range(12):
correction, _, start = drive(subject, 0.5, [(7, 20.0, -2.6, -17.0)], speed=17.0, model=model_message(line_prob=0.05), start=start)
self.assertLessEqual(-correction * 17.0 ** 2, runtime.MAX_LATERAL_ACCEL + 1e-12)
self.assertLess(correction, 0.0)
def test_clear_road_and_far_objects_add_nothing(self):
self.assertEqual(drive(host(), 3.0, [])[0], 0.0)
self.assertEqual(drive(host(), 3.0, [(7, 20.0, -4.5, -11.0), (8, 20.0, 2.6, -11.0), (9, 20.0, -2.6, 0.0)])[0], 0.0)
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "125ecda3a5a447b18d740f8fc704aecf782aeccadae82c9f56c8702b5c3e26cb", "schema_version": 1}
{"protected_inventory_sha256": "6ce178be2a614f2d00448c520fb5b7fd23f9f071d6eab8307dd9792256c5f719", "schema_version": 1}