mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-29 16:23:55 +08:00
Release confirmed stopped lead departures through turns
This commit is contained in:
@@ -202,7 +202,9 @@ class LongitudinalPlanner:
|
||||
self.plan_drive_id = drive_id
|
||||
model_y_no_lead_takeoff = (faster_lead_takeoff and self.CP.carFingerprint == 'TESLA_MODEL_Y' and
|
||||
not any(lead.present for lead in (sm['radarState'].leadOne, sm['radarState'].leadTwo)))
|
||||
faster_takeoffs = bool(faster_lead_takeoff and not model_y_no_lead_takeoff)
|
||||
model_y_turn_takeoff = self.CP.carFingerprint == 'TESLA_MODEL_Y' and (
|
||||
sm['carState'].leftBlinker or sm['carState'].rightBlinker)
|
||||
faster_takeoffs = bool(faster_lead_takeoff and not model_y_no_lead_takeoff and not model_y_turn_takeoff)
|
||||
accel_ceiling = TAKEOFF_ACCEL_MAX if faster_takeoffs else ACCEL_MAX
|
||||
if self.max_accel_override is not None:
|
||||
accel_ceiling = min(accel_ceiling, self.max_accel_override)
|
||||
|
||||
@@ -11,6 +11,9 @@ from openpilot.starpilot.conditional_mode.stop import FROZEN_RAW_STOP_DISTANCE_M
|
||||
SOURCES = ('carState', 'carControl', 'controlsState', 'selfdriveState', 'radarState', 'modelV2')
|
||||
MAX_AGE_NS = 150_000_000
|
||||
CLEAR_DWELL_NS = 500_000_000
|
||||
MIN_TURN_PATH_M = 45.0
|
||||
MIN_TURN_FORWARD_M = 36.0
|
||||
MIN_TURN_LEAD_GAP_M = 4.0
|
||||
|
||||
|
||||
def _supported(cp):
|
||||
@@ -54,14 +57,23 @@ class StoppedLeadRelease:
|
||||
self.reset()
|
||||
return False
|
||||
extent = _standstill_path_extent(model)
|
||||
if extent is None or extent < max(FROZEN_RAW_STOP_DISTANCE_M, detector.commit_distance_m) + STOP_MODEL_RELEASE_MARGIN_M:
|
||||
turning = False
|
||||
if extent is not None and car.leftBlinker != car.rightBlinker:
|
||||
x, y = tuple(model.position.x), tuple(model.position.y)
|
||||
if len(x) == len(y) and all(math.isfinite(v) for v in y):
|
||||
turn_displacement = y[-1] - y[0]
|
||||
turning = (turn_displacement * (-1 if car.leftBlinker else 1) >= 3. and
|
||||
sum(math.hypot(b - a, d - c) for a, b, c, d in zip(x, x[1:], y, y[1:], strict=False)) >= MIN_TURN_PATH_M)
|
||||
minimum_extent = MIN_TURN_FORWARD_M if turning else FROZEN_RAW_STOP_DISTANCE_M + STOP_MODEL_RELEASE_MARGIN_M
|
||||
if extent is None or extent < max(minimum_extent, detector.commit_distance_m + STOP_MODEL_RELEASE_MARGIN_M):
|
||||
self.reset()
|
||||
return False
|
||||
velocities, times = tuple(model.velocity.x), tuple(ModelConstants.T_IDXS)
|
||||
# A stationary Model Y can predict a few centimeters of reverse motion at launch.
|
||||
prefix_noise = cp.carFingerprint == 'TESLA_MODEL_Y' and min(model.position.x) >= -.03
|
||||
prefix_min_velocity = -.09 if turning else -.08
|
||||
if (len(velocities) != 33 or len(times) != 33 or
|
||||
not all(math.isfinite(v) and (-.08 if prefix_noise and t < .2 else -.05) <= v <= 100.
|
||||
not all(math.isfinite(v) and (prefix_min_velocity if prefix_noise and t < .2 else -.05) <= v <= 100.
|
||||
for v, t in zip(velocities, times, strict=True))):
|
||||
self.reset()
|
||||
return False
|
||||
@@ -70,26 +82,37 @@ class StoppedLeadRelease:
|
||||
self.reset()
|
||||
return False
|
||||
leads = [(slot, lead) for slot, lead in enumerate((sm['radarState'].leadOne, sm['radarState'].leadTwo)) if lead.present]
|
||||
minimum_gap = MIN_TURN_LEAD_GAP_M if turning else 6.3
|
||||
if not leads or any(lead.radar and lead.radarTrackId < 0 or not all(math.isfinite(v) for v in
|
||||
(lead.dRel, lead.vLead, lead.aLeadK, lead.yRel, lead.modelProb)) or
|
||||
not 6.3 <= lead.dRel <= 18. or lead.vLead < .6 or lead.aLeadK < -.15 or
|
||||
abs(lead.yRel) > 1. or lead.modelProb < .95 for _, lead in leads):
|
||||
not minimum_gap <= lead.dRel <= 18. or lead.vLead < .6 or lead.aLeadK < -.15 or
|
||||
abs(lead.yRel) > 1. for _, lead in leads):
|
||||
self.reset()
|
||||
return False
|
||||
primary = leads[0][1]
|
||||
for slot, lead in leads:
|
||||
# The model can emit the same departing car in both temporal slots.
|
||||
# A weaker duplicate still has to agree with the primary and its own projection.
|
||||
duplicate = (turning and slot == 1 and leads[0][0] == 0 and not (primary.radar or lead.radar) and
|
||||
all(abs(getattr(primary, field) - getattr(lead, field)) <= .25
|
||||
for field in ('dRel', 'yRel', 'vLead', 'aLeadK')))
|
||||
minimum_probability = .9 if duplicate else .95
|
||||
if lead.modelProb < minimum_probability:
|
||||
self.reset()
|
||||
return False
|
||||
if not lead.radar:
|
||||
if lead.radarTrackId != -1:
|
||||
self.reset()
|
||||
return False
|
||||
source = model.leadsV3[slot]
|
||||
projected = get_RadarState_from_vision(source, car.vEgo, model.velocity.x[0], source.prob)
|
||||
if (source.prob < .95 or not math.isfinite(source.prob) or
|
||||
if (source.prob < minimum_probability or not math.isfinite(source.prob) or
|
||||
any(not math.isfinite(projected[field]) or abs(projected[field] - getattr(lead, field)) > .5
|
||||
for field in ('dRel', 'yRel', 'vLead', 'aLeadK'))):
|
||||
self.reset()
|
||||
return False
|
||||
key = (drive_id, cp.carFingerprint, tuple((str(config.safetyModel), config.safetyParam) for config in cp.safetyConfigs),
|
||||
tuple((slot, bool(lead.radar), lead.radarTrackId if lead.radar else -1) for slot, lead in leads))
|
||||
turning, tuple((slot, bool(lead.radar), lead.radarTrackId if lead.radar else -1) for slot, lead in leads))
|
||||
stamp = int(sm.logMonoTime['modelV2'])
|
||||
if (key != self.key or not self.last_ns < now_ns <= self.last_ns + MAX_AGE_NS or stamp <= self.model_ns):
|
||||
self.reset()
|
||||
|
||||
@@ -191,3 +191,41 @@ def test_departure_tolerates_only_bounded_model_y_prefix_noise(fingerprint, slot
|
||||
results.append(owner.sample(sm, cp, planner, detector, now_ns=now, drive_id=green.MONO-1_000_000_000))
|
||||
assert not any(results[:10])
|
||||
assert results[10:] == [clear] * 3
|
||||
|
||||
|
||||
@pytest.mark.parametrize('case', ('matched-turn', 'duplicate', 'distinct', 'weak-primary', 'prefix-noise', 'large-prefix',
|
||||
'opposite-signal', 'no-signal', 'short-path', 'no-lead', 'model-stop', 'native-stop'))
|
||||
def test_shorter_turn_path_can_release_only_with_matching_lead_and_no_stop(case):
|
||||
cp = CarParams(openpilotLongitudinalControl=True, carFingerprint='TESLA_MODEL_Y')
|
||||
owner = StoppedLeadRelease()
|
||||
detector = SimpleNamespace(committed=True, standstill_committed=True, standstill_reason='light', commit_distance_m=5.)
|
||||
planner = SimpleNamespace(mpc=SimpleNamespace(solution_status=0), output_should_stop=case == 'native-stop', output_a_target=.5,
|
||||
force_stop_plan=SimpleNamespace(forcing=False, should_stop=False))
|
||||
results = []
|
||||
for tick in range(13):
|
||||
now = green.MONO + 1_000_000_000 + tick * 50_000_000
|
||||
sm = scene(now, True)
|
||||
car, model = sm['carState'], sm['modelV2']
|
||||
car.leftBlinker, car.rightBlinker = case not in ('no-signal', 'opposite-signal'), case == 'opposite-signal'
|
||||
path = list(model.position.x)
|
||||
forward = 25. if case == 'short-path' else 43.
|
||||
model.position.x = [x * forward / path[-1] for x in path]
|
||||
model.position.y = [-x * 20. / path[-1] for x in path]
|
||||
if case in ('prefix-noise', 'large-prefix'):
|
||||
xs, velocities = list(model.position.x), list(model.velocity.x)
|
||||
xs[4], velocities[4] = -.027, -.085 if case == 'prefix-noise' else -.091
|
||||
model.position.x, model.velocity.x = xs, velocities
|
||||
model.action.shouldStop = case == 'model-stop'
|
||||
for slot, lead in enumerate((sm['radarState'].leadOne, sm['radarState'].leadTwo)):
|
||||
if lead.present:
|
||||
raw = model.leadsV3[slot]
|
||||
offset = .4 if case == 'distinct' and slot == 1 else 0.
|
||||
raw.x = [x - raw.x[0] + 6.02 + offset for x in raw.x]
|
||||
if (case in ('duplicate', 'distinct') and slot == 1) or (case == 'weak-primary' and slot == 0):
|
||||
raw.prob = .92
|
||||
lead.from_dict(get_RadarState_from_vision(raw, car.vEgo, model.velocity.x[0], raw.prob))
|
||||
if case == 'no-lead':
|
||||
lead.present = False
|
||||
results.append(owner.sample(sm, cp, planner, detector, now_ns=now, drive_id=green.MONO-1_000_000_000))
|
||||
assert not any(results[:10])
|
||||
assert results[10:] == [case in ('matched-turn', 'duplicate', 'prefix-noise')] * 3
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "42c0ceaa618fe3882427db01e93da4424b7bee2e877a9be2d0fa0e5b13ad0863", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "ccb2755d88165b8cb1c59a5d243e5f514433bf5e2a1d01427dfb42708a681c84", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user