From 9fd7738cd5898a73a7d8e32565d8b187b02fcfba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=AF=D1=80=D0=BE=D1=81=D0=BB=D0=B0=D0=B2=20=D0=9A=D0=B0?= =?UTF-8?q?=D1=80=D1=82=D0=B0=D1=88=D0=BE=D0=B2?= Date: Fri, 13 Nov 2026 14:28:09 +0700 Subject: [PATCH 1/5] Prepare focus-aware PTZ17 zoom candidate --- integration/ptz17_focus_zoom/README.md | 11 + integration/ptz17_focus_zoom/pins.json | 6 + integration/ptz17_focus_zoom/server.patch | 264 ++++++++++++++++++++++ 3 files changed, 281 insertions(+) create mode 100644 integration/ptz17_focus_zoom/README.md create mode 100644 integration/ptz17_focus_zoom/pins.json create mode 100644 integration/ptz17_focus_zoom/server.patch diff --git a/integration/ptz17_focus_zoom/README.md b/integration/ptz17_focus_zoom/README.md new file mode 100644 index 0000000..bae67a2 --- /dev/null +++ b/integration/ptz17_focus_zoom/README.md @@ -0,0 +1,11 @@ +# PTZ17 · зум и контроль резкости + +Локальный кандидат поверх установленного PR №13. Прямое и обратное применение патча проверены побайтно. SHA-256 базовой и кандидатной версий в `pins.json`. + +На широком угле кандидат проверяет, может ли уже разрешённый первый обычный импульс native 10 начаться с длительностью до 340 мс и жёстким пределом 400 мс. Для этого нужны текущий кадр OSTrack, свежее подтверждение YOLO, свежая оптика, допустимая скорость в кадре и полная штатная проекция рамки. Повторное разрешение допускает только исходный запрос того же владельца. При запрете базового контроллера запрос остаётся нулевым. Функции модели, тревог и транспорт STOP сохранены. + +При HFOV до 18° на PTZ17 оценка резкости проверяет область самой цели. Для решения о паузе подходят рамки с короткой стороной от 20 px. Штатный порог запроса автофокуса остаётся отдельным. Низкая резкость или неоцениваемый кадр удерживают текущее увеличение. Возобновление требует свежего резкого кадра. Пауза относится к новым положительным импульсам, поэтому Pan/Tilt и защитное расширение FOV сохраняют штатные пути. + +На записи пролёта 14:12:02 измерение рамки на PTS 95 возвращает `unassessable` и устанавливает паузу. На PTS 116 свежая резкая рамка снимает её. У трёх сохранённых кадров нет покадровой привязки к UTC. Замеры AIM разрежены. Первый записанный полный безопасный запас от края появился на +9,869 с, после первой полевой команды на +6,041 с. Ускорение первого оптического приближения на данном пролёте по доступным данным не подтверждено. + +Проверки охватывают свежесть, владельца импульса, отказ при малом запасе от края, превышении угловой зоны и скорости, сохранение нулевого запроса, паузу по размытому кадру и снятие паузы по свежему резкому кадру. Реакция привода и время до распознаваемого кадра требуют дополнительных данных. Кандидат не установлен. diff --git a/integration/ptz17_focus_zoom/pins.json b/integration/ptz17_focus_zoom/pins.json new file mode 100644 index 0000000..46dc4aa --- /dev/null +++ b/integration/ptz17_focus_zoom/pins.json @@ -0,0 +1,6 @@ +{ + "base_sha256": "6cf484271ef3659028b0b4d43041addb05102f91d2758ab472d968a52d24e911", + "candidate_sha256": "7377065d96b5b32717fb131daf1024931171574a21bd572d0d75bbba7509951c", + "patch_sha256": "26cbba549d56074a7291076cfb0177adc267543f2844a5a10e83495c7304ad4e", + "installed": false +} diff --git a/integration/ptz17_focus_zoom/server.patch b/integration/ptz17_focus_zoom/server.patch new file mode 100644 index 0000000..5c67819 --- /dev/null +++ b/integration/ptz17_focus_zoom/server.patch @@ -0,0 +1,264 @@ +--- a/postprocess.py ++++ b/postprocess.py +@@ -690,6 +690,8 @@ + def _focus_quality_score( + frame_bgr: np.ndarray, + bbox: Tuple[int, int, int, int] | list[int], ++ *, ++ roi_scale: float | None = None, + ) -> float | None: + """Return Laplacian focus energy from a bounded ROI around the target. + +@@ -708,7 +710,7 @@ + if not np.isfinite([x1, y1, x2, y2]).all() or x2 <= x1 or y2 <= y1: + return None + +- scale = max(1.0, float(getattr(config, "AUTOFOCUS_ROI_SCALE", 2.5))) ++ scale = max(1.0, float(getattr(config, "AUTOFOCUS_ROI_SCALE", 2.5) if roi_scale is None else roi_scale)) + cx = (x1 + x2) * 0.5 + cy = (y1 + y2) * 0.5 + roi_w = max(16.0, (x2 - x1) * scale) +@@ -741,6 +743,89 @@ + return score if math.isfinite(score) else None + + ++@dataclass(frozen=True, slots=True) ++class _PTZ17ZoomTuning: ++ focus_max_hfov_deg: float = 18.0 ++ focus_min_side_px: int = 20 ++ frame_max_age_s: float = 0.25 ++ detector_max_age_s: float = 0.65 ++ first_pulse_s: float = 0.34 ++ hard_stop_s: float = 0.40 ++ startup_native: int = 10 ++ projected_margin_min: float = 0.16 ++ edge_margin_min: float = 0.30 ++ center_max_norm: float = 0.12 ++ image_rate_max_norm_s: float = 0.04 ++ ++ ++_PTZ17_ZOOM = _PTZ17ZoomTuning() ++ ++ ++def _ptz17_focus_hold( ++ st: dict, *, hfov_deg: float, side_px: int, frame_is_current: bool, ++) -> str | None: ++ """Keep the lens at its current FOV while the settled target is blurry.""" ++ owner = visual_control.owner(st) ++ if owner[2] <= 0.0 or not 0.0 < hfov_deg <= _PTZ17_ZOOM.focus_max_hfov_deg: ++ st.pop("ptz17_focus_hold", None) ++ return None ++ previous = st.get("ptz17_focus_hold") ++ reason = previous[1] if previous is not None and previous[0] == owner else None ++ if not frame_is_current: ++ return reason ++ focus_state = st.get("focus_state") ++ if focus_state == "disabled": ++ reason = None ++ elif side_px >= _PTZ17_ZOOM.focus_min_side_px: ++ if focus_state == "sharp": ++ reason = None ++ elif focus_state in { ++ "blur_suspected", "blur_fast_suspected", "blur_cooldown", "blur_wait", ++ "unassessable", "requested", "settling", ++ }: ++ reason = str(focus_state) ++ if reason is not None: ++ st["ptz17_focus_hold"] = (owner, reason) ++ else: ++ st.pop("ptz17_focus_hold", None) ++ return reason ++ ++ ++def _ptz17_first_useful_timing( ++ st: dict, timing: tuple[float, float], *, native: int, normal_onset: bool, ++ frame_age_s: float, detector_age_s: float, hfov_deg: float, wide_hfov_deg: float, ++ approach_margin: float | None, edge_margin: float, center_error: float, image_rate: float, ++) -> tuple[float, float]: ++ """Select the longer measured-response candidate within existing deadlines.""" ++ tuning = _PTZ17_ZOOM ++ if ( ++ not normal_onset or timing[0] <= 0.0 or native != tuning.startup_native ++ or st.get("zoom_no_effect_blocked") ++ or st.get("zoom_stop_obligation_active") or st.get("lens_move_stop_required") ++ or not 0.0 <= frame_age_s <= tuning.frame_max_age_s ++ or not 0.0 <= detector_age_s <= tuning.detector_max_age_s ++ or not 0.0 < hfov_deg <= wide_hfov_deg < 180.0 ++ or hfov_deg < wide_hfov_deg * max(.85, float(getattr(config, "ZOOM_RESPONSE_WIDE_RATIO", .85))) ++ or approach_margin is None or not tuning.projected_margin_min <= approach_margin <= .5 ++ or not tuning.edge_margin_min <= edge_margin <= .5 ++ or not 0.0 <= center_error <= tuning.center_max_norm ++ or not 0.0 <= image_rate <= tuning.image_rate_max_norm_s ++ ): ++ return timing ++ if st.get("zoom_step_pending"): ++ # Revalidate only the original request created by the PTZ17 profile. ++ # The existing pulse gate owns the pending timer and expiry. ++ marker = st.get("ptz17_first_timing_owner") ++ if marker == (visual_control.owner(st), st.get("zoom_step_pending_id")): ++ return (float(st["zoom_step_pending_pulse_sec"]), float(st["zoom_step_pending_hard_sec"])) ++ return timing ++ if int(st.get("zoom_step_request_id", 0) or 0) != 0: ++ return timing ++ pulse = min(tuning.first_pulse_s, float(getattr(config, "ZOOM_RESPONSE_MAX_PULSE_SEC", .34))) ++ hard = min(tuning.hard_stop_s, float(getattr(config, "ZOOM_RESPONSE_MAX_HARD_STOP_SEC", .40))) ++ return (pulse, hard) if timing[0] < pulse <= hard and timing[1] <= hard else timing ++ ++ + def _clear_focus_low_evidence(st: dict) -> None: + st["focus_quality_low_frames"] = 0 + st["focus_quality_low_since"] = None +@@ -840,6 +925,16 @@ + st["focus_state"] = "unassessable" + _clear_focus_low_evidence(st) + return False ++ if cam_idx == _PTZ17_CAM_IDX and float(hfov_deg) <= _PTZ17_ZOOM.focus_max_hfov_deg: ++ # Reject surrounding skyline detail as proof that the actual target ++ # is sharp. Keep the existing contrast and blur thresholds. ++ target_score = _focus_quality_score(frame_bgr, bbox, roi_scale=1.0) ++ if target_score is None: ++ st["focus_state"] = "unassessable" ++ _clear_focus_low_evidence(st) ++ return False ++ score = min(score, target_score) ++ st["focus_quality_score"] = score + + alpha = clipf(float(getattr(config, "AUTOFOCUS_SCORE_EMA_ALPHA", 0.35)), 0.01, 1.0) + previous_ema = st.get("focus_quality_ema") +@@ -9537,6 +9632,47 @@ + max(0.0, float(getattr(config, min_key, 0.10))), + ) + zoom_cmd = min(max_effective, max(float(zoom_cmd), min_effective)) ++ ptz17_focus_reason = None ++ ptz17_focus_checked = False ++ if (cam_idx == _PTZ17_CAM_IDX and float(hfov_deg) <= _PTZ17_ZOOM.focus_max_hfov_deg ++ and not pulse_active and not st.get("zoom_step_pending")): ++ # Check the settled image before authorizing a fresh pulse. The ++ # existing autofocus worker and controller keep their own limits. ++ focus_wall_now = time.time() ++ lens_settled = ( ++ not st.get("lens_move_put_inflight") and not st.get("zoom_stop_obligation_active") ++ and not st.get("lens_move_stop_required") ++ and (st.get("last_ptz_physical_cmd") or (0.0, 0.0, 0.0))[2] == 0.0 ++ ) ++ if (lens_settled and zoom_cmd >= 0.0 and visual_only ++ and visual_control.current(cam_idx, visual_sample, focus_wall_now, ++ max_age=_PTZ17_ZOOM.frame_max_age_s)): ++ _maybe_request_autofocus( ++ cam_idx, st, frame_bgr, (x1, y1, x2, y2), now=float(now), ++ pan_cmd=float(pan_speed) + float(pan_rate_ff), ++ tilt_cmd=float(tilt_speed) + float(tilt_rate_ff), ++ zoom_cmd=0.0, center_err=float(center_err), hfov_deg=float(hfov_deg), ++ validation_age=float(visual_control_validation_age), ++ ) ++ ptz17_focus_checked = True ++ # A small but measurable crop can veto another zoom step. ++ # The higher size threshold for requesting autofocus still applies. ++ if (st.get("focus_state") == "target_too_small" ++ and min(x2 - x1, y2 - y1) >= _PTZ17_ZOOM.focus_min_side_px ++ and 0.0 <= visual_control_validation_age <= _PTZ17_ZOOM.detector_max_age_s): ++ target_score = _focus_quality_score(frame_bgr, (x1, y1, x2, y2), roi_scale=1.0) ++ threshold = float(getattr(config, "AUTOFOCUS_BLUR_THRESHOLD", 35.0)) ++ st["focus_state"] = ( ++ "unassessable" if target_score is None else ++ "sharp" if target_score >= threshold else "blur_suspected" ++ ) ++ ptz17_focus_reason = _ptz17_focus_hold( ++ st, hfov_deg=float(hfov_deg), side_px=min(x2 - x1, y2 - y1), ++ frame_is_current=ptz17_focus_checked, ++ ) ++ if ptz17_focus_reason is not None and zoom_cmd > 0.0: ++ zoom_cmd = 0.0 ++ zoom_zero_reason = "focus_hold" + if probe_start_candidate and identify_start_candidate: + pulse_kind = "probe_identify" + elif probe_start_candidate: +@@ -9645,6 +9781,27 @@ + zoom_cmd = 0.0 + st["zoom_useful_pulse_reason"] = "wait_response_framing" + zoom_zero_reason = "response_framing" ++ ptz17_timing_changed = False ++ if cam_idx == _PTZ17_CAM_IDX: ++ original_response_timing = response_timing ++ response_timing = _ptz17_first_useful_timing( ++ st, response_timing, native=timing_native, ++ normal_onset=(zoom_cmd > 0.0 and useful_reason == "useful" and useful_optics_fresh ++ and pulse_family == "normal" ++ and fast_approach and normal_zoom_quality_ok ++ and current_track_source == "visual" and not predictive_start ++ and bool(visual_only and visual_control.current( ++ cam_idx, visual_sample, zoom_gate_now, ++ max_age=_PTZ17_ZOOM.frame_max_age_s, ++ ))), ++ frame_age_s=zoom_gate_now - now, ++ detector_age_s=zoom_gate_now - last_visual_zoom_validation, ++ hfov_deg=float(hfov_deg), wide_hfov_deg=float(shared_wide_hfov), ++ approach_margin=approach_margin, edge_margin=float(edge_risk_margin), ++ center_error=max(abs(float(measured_dx)), abs(float(measured_dy))), ++ image_rate=max(float(vel), float(fast_drift)), ++ ) ++ ptz17_timing_changed = response_timing != original_response_timing + gate_stop = [] if decision_request else None + continuation_trace = [] if decision_request else None + zoom_cmd = _gate_zoom_in_pulse( +@@ -9667,6 +9824,9 @@ + ) + if predictive_start and zoom_cmd > 0.0 and st["zoom_step_request_id"] > request_id_before_gate: + st["predictive_zoom_request"] = st["zoom_step_pending_id"] ++ if (ptz17_timing_changed and zoom_cmd > 0.0 ++ and st["zoom_step_request_id"] > request_id_before_gate): ++ st["ptz17_first_timing_owner"] = (visual_control.owner(st), st["zoom_step_pending_id"]) + if gate_stop: + zoom_zero_reason = gate_stop[-1] + decision_generation = st.get("ptz_generation") +@@ -9693,23 +9853,24 @@ + elif zoom_cmd < 0.0 and float(size_est) <= max(0.05, zoomed_size_thr * 0.75): + st["was_zoomed_in"] = False + +- _maybe_request_autofocus( +- cam_idx, +- st, +- frame_bgr, +- (x1, y1, x2, y2), +- now=float(now), +- pan_cmd=float(pan_speed) + float(pan_rate_ff), +- tilt_cmd=float(tilt_speed) + float(tilt_rate_ff), +- zoom_cmd=float(zoom_cmd), +- center_err=float(center_err), +- hfov_deg=float(hfov_deg), +- validation_age=( +- float(visual_control_validation_age) +- if current_track_source == "visual" +- else 0.0 +- ), +- ) ++ if not ptz17_focus_checked: ++ _maybe_request_autofocus( ++ cam_idx, ++ st, ++ frame_bgr, ++ (x1, y1, x2, y2), ++ now=float(now), ++ pan_cmd=float(pan_speed) + float(pan_rate_ff), ++ tilt_cmd=float(tilt_speed) + float(tilt_rate_ff), ++ zoom_cmd=float(zoom_cmd), ++ center_err=float(center_err), ++ hfov_deg=float(hfov_deg), ++ validation_age=( ++ float(visual_control_validation_age) ++ if current_track_source == "visual" ++ else 0.0 ++ ), ++ ) + + st["fallback_done"] = False + +@@ -10222,6 +10383,8 @@ + if getattr(config, "PREDICTIVE_ZOOM_TELEMETRY_DIR", "logs/ptz_zoom"): + blocked = {} + if zoom_cmd <= 0.0 and raw_zoom_needed: ++ if ptz17_focus_reason is not None: ++ blocked["focus_hold"] = {"state": ptz17_focus_reason} + if not stable_ok: + blocked["centering"] = {"error": center_err, "limit": lock_gate, "stable_frames": st.get("stable_frames")} + if not zoom_safe: -- 2.17.1 From 05dcdcd06a14f13123553063ffa30d72286d1a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=AF=D1=80=D0=BE=D1=81=D0=BB=D0=B0=D0=B2=20=D0=9A=D0=B0?= =?UTF-8?q?=D1=80=D1=82=D0=B0=D1=88=D0=BE=D0=B2?= Date: Fri, 13 Nov 2026 14:34:25 +0700 Subject: [PATCH 2/5] Validate target sharpness on additional PTZ17 passages --- integration/ptz17_focus_zoom/README.md | 15 ++++++ integration/ptz17_focus_zoom/pins.json | 4 +- integration/ptz17_focus_zoom/server.patch | 59 ++++++++++++++--------- 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/integration/ptz17_focus_zoom/README.md b/integration/ptz17_focus_zoom/README.md index bae67a2..bda4283 100644 --- a/integration/ptz17_focus_zoom/README.md +++ b/integration/ptz17_focus_zoom/README.md @@ -6,6 +6,21 @@ При HFOV до 18° на PTZ17 оценка резкости проверяет область самой цели. Для решения о паузе подходят рамки с короткой стороной от 20 px. Штатный порог запроса автофокуса остаётся отдельным. Низкая резкость или неоцениваемый кадр удерживают текущее увеличение. Возобновление требует свежего резкого кадра. Пауза относится к новым положительным импульсам, поэтому Pan/Tilt и защитное расширение FOV сохраняют штатные пути. +Повторная проверка на пролёте 14:28 показала, что расширенная область низкоконтрастна и для размытого, и для различимого самолёта. Теперь при непригодной расширенной области проверяется ядро рамки с более строгим порогом. Для этого кандидата задан восьмикратный множитель относительно исходного порога дисперсии лапласиана. Множитель проверен на этой ограниченной выборке и остаётся параметром калибровки. + На записи пролёта 14:12:02 измерение рамки на PTS 95 возвращает `unassessable` и устанавливает паузу. На PTS 116 свежая резкая рамка снимает её. У трёх сохранённых кадров нет покадровой привязки к UTC. Замеры AIM разрежены. Первый записанный полный безопасный запас от края появился на +9,869 с, после первой полевой команды на +6,041 с. Ускорение первого оптического приближения на данном пролёте по доступным данным не подтверждено. Проверки охватывают свежесть, владельца импульса, отказ при малом запасе от края, превышении угловой зоны и скорости, сохранение нулевого запроса, паузу по размытому кадру и снятие паузы по свежему резкому кадру. Реакция привода и время до распознаваемого кадра требуют дополнительных данных. Кандидат не установлен. + +## Два дополнительных пролёта на PR №13 + +Время местное, UTC+7. Тайминги отсчитаны от входа в TRACK. Проекция берётся из разреженных строк AIM, поэтому её первое появление даёт только верхнюю границу времени появления в журнале. + +| Начало TRACK | Первый физический старт | Первое подтверждение оптики | Первая записанная безопасная проекция | До 2× / 4× / 8× | +| --- | ---: | ---: | ---: | --- | +| 14:24:57,917 | +8,118 с | +17,020 с | +11,230 с | 28,163 / 47,218 / 76,182 с | +| 14:28:06,389 | +4,294 с | +16,985 с | +13,713 с | 45,665 / 70,481 / 97,097 с | + +В первом пролёте два коротких импульса 100 и 220 мс не получили отдельного подтверждения оптики. Во втором исходный обычный импульс снят после PUT на фоне `image_motion`, два пробных импульса по 100 мс также остались без оптического подтверждения. Первое подтверждение получено на обычных запросах №3 и №5 соответственно. Первые записанные безопасные проекции в обоих случаях позже первого движения, поэтому изменение длительности из PR №14 ещё не подтверждает выигрыш на этих пролётах. Защитные остановки сохраняются. + +На кадрах второго пролёта PTS 94 и 114 расширенная область вернула `None`. Энергия в ядре рамки составила 142 и 8994 соответственно. При пороге 280 первый кадр удерживает паузу, второй её снимает. Два различимых кадра из пролёта 14:24 проходят проверку. Сопоставление PTS с UTC на уровне отдельных кадров не выполнено. В окнах обоих пролётов журнал не показывает отправку тревоги по WebSocket. diff --git a/integration/ptz17_focus_zoom/pins.json b/integration/ptz17_focus_zoom/pins.json index 46dc4aa..d70ecea 100644 --- a/integration/ptz17_focus_zoom/pins.json +++ b/integration/ptz17_focus_zoom/pins.json @@ -1,6 +1,6 @@ { "base_sha256": "6cf484271ef3659028b0b4d43041addb05102f91d2758ab472d968a52d24e911", - "candidate_sha256": "7377065d96b5b32717fb131daf1024931171574a21bd572d0d75bbba7509951c", - "patch_sha256": "26cbba549d56074a7291076cfb0177adc267543f2844a5a10e83495c7304ad4e", + "candidate_sha256": "da2a970deb041d6dc4897fd58c2efa2943803d46c3af6ddcf92d010a4ca0f589", + "patch_sha256": "6c6f5ee84f9be3976cf318431cfa505817f2322345215a76ae638873376d14c8", "installed": false } diff --git a/integration/ptz17_focus_zoom/server.patch b/integration/ptz17_focus_zoom/server.patch index 5c67819..c93aac9 100644 --- a/integration/ptz17_focus_zoom/server.patch +++ b/integration/ptz17_focus_zoom/server.patch @@ -18,7 +18,7 @@ cx = (x1 + x2) * 0.5 cy = (y1 + y2) * 0.5 roi_w = max(16.0, (x2 - x1) * scale) -@@ -741,6 +743,89 @@ +@@ -741,6 +743,106 @@ return score if math.isfinite(score) else None @@ -26,6 +26,7 @@ +class _PTZ17ZoomTuning: + focus_max_hfov_deg: float = 18.0 + focus_min_side_px: int = 20 ++ focus_core_only_threshold_scale: float = 8.0 + frame_max_age_s: float = 0.25 + detector_max_age_s: float = 0.65 + first_pulse_s: float = 0.34 @@ -40,6 +41,22 @@ +_PTZ17_ZOOM = _PTZ17ZoomTuning() + + ++def _ptz17_target_focus_score( ++ frame_bgr: np.ndarray, bbox: tuple[int, int, int, int] | list[int], ++) -> float | None: ++ """Assess target detail when the wider crop has little contrast.""" ++ core = _focus_quality_score(frame_bgr, bbox, roi_scale=1.0) ++ if core is None: ++ return None ++ expanded = _focus_quality_score(frame_bgr, bbox) ++ if expanded is not None: ++ return min(core, expanded) ++ threshold = max(0.0, float(getattr(config, "AUTOFOCUS_BLUR_THRESHOLD", 35.0))) ++ if core >= threshold * _PTZ17_ZOOM.focus_core_only_threshold_scale: ++ return core ++ return None ++ ++ +def _ptz17_focus_hold( + st: dict, *, hfov_deg: float, side_px: int, frame_is_current: bool, +) -> str | None: @@ -108,24 +125,20 @@ def _clear_focus_low_evidence(st: dict) -> None: st["focus_quality_low_frames"] = 0 st["focus_quality_low_since"] = None -@@ -840,6 +925,16 @@ - st["focus_state"] = "unassessable" - _clear_focus_low_evidence(st) - return False -+ if cam_idx == _PTZ17_CAM_IDX and float(hfov_deg) <= _PTZ17_ZOOM.focus_max_hfov_deg: -+ # Reject surrounding skyline detail as proof that the actual target -+ # is sharp. Keep the existing contrast and blur thresholds. -+ target_score = _focus_quality_score(frame_bgr, bbox, roi_scale=1.0) -+ if target_score is None: -+ st["focus_state"] = "unassessable" -+ _clear_focus_low_evidence(st) -+ return False -+ score = min(score, target_score) -+ st["focus_quality_score"] = score +@@ -833,7 +935,11 @@ + _clear_focus_low_evidence(st) + st["focus_last_hfov_deg"] = float(hfov_deg) - alpha = clipf(float(getattr(config, "AUTOFOCUS_SCORE_EMA_ALPHA", 0.35)), 0.01, 1.0) - previous_ema = st.get("focus_quality_ema") -@@ -9537,6 +9632,47 @@ +- score = _focus_quality_score(frame_bgr, bbox) ++ score = ( ++ _ptz17_target_focus_score(frame_bgr, bbox) ++ if cam_idx == _PTZ17_CAM_IDX and float(hfov_deg) <= _PTZ17_ZOOM.focus_max_hfov_deg ++ else _focus_quality_score(frame_bgr, bbox) ++ ) + st["focus_quality_last_eval_at"] = float(now) + st["focus_quality_score"] = score + if score is None: +@@ -9537,6 +9643,47 @@ max(0.0, float(getattr(config, min_key, 0.10))), ) zoom_cmd = min(max_effective, max(float(zoom_cmd), min_effective)) @@ -157,7 +170,7 @@ + if (st.get("focus_state") == "target_too_small" + and min(x2 - x1, y2 - y1) >= _PTZ17_ZOOM.focus_min_side_px + and 0.0 <= visual_control_validation_age <= _PTZ17_ZOOM.detector_max_age_s): -+ target_score = _focus_quality_score(frame_bgr, (x1, y1, x2, y2), roi_scale=1.0) ++ target_score = _ptz17_target_focus_score(frame_bgr, (x1, y1, x2, y2)) + threshold = float(getattr(config, "AUTOFOCUS_BLUR_THRESHOLD", 35.0)) + st["focus_state"] = ( + "unassessable" if target_score is None else @@ -173,7 +186,7 @@ if probe_start_candidate and identify_start_candidate: pulse_kind = "probe_identify" elif probe_start_candidate: -@@ -9645,6 +9781,27 @@ +@@ -9645,6 +9792,27 @@ zoom_cmd = 0.0 st["zoom_useful_pulse_reason"] = "wait_response_framing" zoom_zero_reason = "response_framing" @@ -201,7 +214,7 @@ gate_stop = [] if decision_request else None continuation_trace = [] if decision_request else None zoom_cmd = _gate_zoom_in_pulse( -@@ -9667,6 +9824,9 @@ +@@ -9667,6 +9835,9 @@ ) if predictive_start and zoom_cmd > 0.0 and st["zoom_step_request_id"] > request_id_before_gate: st["predictive_zoom_request"] = st["zoom_step_pending_id"] @@ -211,7 +224,7 @@ if gate_stop: zoom_zero_reason = gate_stop[-1] decision_generation = st.get("ptz_generation") -@@ -9693,23 +9853,24 @@ +@@ -9693,23 +9864,24 @@ elif zoom_cmd < 0.0 and float(size_est) <= max(0.05, zoomed_size_thr * 0.75): st["was_zoomed_in"] = False @@ -253,7 +266,7 @@ st["fallback_done"] = False -@@ -10222,6 +10383,8 @@ +@@ -10222,6 +10394,8 @@ if getattr(config, "PREDICTIVE_ZOOM_TELEMETRY_DIR", "logs/ptz_zoom"): blocked = {} if zoom_cmd <= 0.0 and raw_zoom_needed: -- 2.17.1 From 25c94c1e8d37a255fdebf96db8c873044a227f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=AF=D1=80=D0=BE=D1=81=D0=BB=D0=B0=D0=B2=20=D0=9A=D0=B0?= =?UTF-8?q?=D1=80=D1=82=D0=B0=D1=88=D0=BE=D0=B2?= Date: Fri, 13 Nov 2026 14:43:46 +0700 Subject: [PATCH 3/5] Add PTZ17 optics replay and bounded focus recovery --- integration/ptz17_focus_zoom/README.md | 16 +- integration/ptz17_focus_zoom/pins.json | 4 +- .../ptz17_focus_zoom/reference_fixture.json | 3285 +++++++++++++++++ .../ptz17_focus_zoom/reference_replay.json | 390 ++ .../replay_ptz17_reference.py | 135 + integration/ptz17_focus_zoom/server.patch | 150 +- .../ptz17_focus_zoom/test_reference_replay.py | 30 + 7 files changed, 3995 insertions(+), 15 deletions(-) create mode 100644 integration/ptz17_focus_zoom/reference_fixture.json create mode 100644 integration/ptz17_focus_zoom/reference_replay.json create mode 100644 integration/ptz17_focus_zoom/replay_ptz17_reference.py create mode 100644 integration/ptz17_focus_zoom/test_reference_replay.py diff --git a/integration/ptz17_focus_zoom/README.md b/integration/ptz17_focus_zoom/README.md index bda4283..9960ad2 100644 --- a/integration/ptz17_focus_zoom/README.md +++ b/integration/ptz17_focus_zoom/README.md @@ -4,7 +4,9 @@ На широком угле кандидат проверяет, может ли уже разрешённый первый обычный импульс native 10 начаться с длительностью до 340 мс и жёстким пределом 400 мс. Для этого нужны текущий кадр OSTrack, свежее подтверждение YOLO, свежая оптика, допустимая скорость в кадре и полная штатная проекция рамки. Повторное разрешение допускает только исходный запрос того же владельца. При запрете базового контроллера запрос остаётся нулевым. Функции модели, тревог и транспорт STOP сохранены. -При HFOV до 18° на PTZ17 оценка резкости проверяет область самой цели. Для решения о паузе подходят рамки с короткой стороной от 20 px. Штатный порог запроса автофокуса остаётся отдельным. Низкая резкость или неоцениваемый кадр удерживают текущее увеличение. Возобновление требует свежего резкого кадра. Пауза относится к новым положительным импульсам, поэтому Pan/Tilt и защитное расширение FOV сохраняют штатные пути. +При HFOV до 18° на PTZ17 оценка резкости проверяет область самой цели. Для решения о паузе подходят рамки с короткой стороной от 20 px. Штатный порог размера для автофокуса остаётся 24 px. Низкая резкость или неоцениваемый кадр удерживают текущее увеличение. Для выхода нужны два свежих резких кадра того же владельца с интервалом не более 250 мс. Один резкий отсчёт, дубликат и большой разрыв паузу не снимают. Пауза относится к новым положительным импульсам, поэтому Pan/Tilt и защитное расширение FOV сохраняют штатные пути. + +При непрерывных 600 мс неоцениваемой резкости после остановки линзы, свежем подтверждении цели и устойчивом положении рамки кандидат может поставить один восстановительный запрос в штатную очередь автофокуса на владельца трека. Повторный запрос требует смены владельца и соблюдения штатного cooldown. ACK фокуса сам по себе зум не возобновляет. Повторная проверка на пролёте 14:28 показала, что расширенная область низкоконтрастна и для размытого, и для различимого самолёта. Теперь при непригодной расширенной области проверяется ядро рамки с более строгим порогом. Для этого кандидата задан восьмикратный множитель относительно исходного порога дисперсии лапласиана. Множитель проверен на этой ограниченной выборке и остаётся параметром калибровки. @@ -24,3 +26,15 @@ В первом пролёте два коротких импульса 100 и 220 мс не получили отдельного подтверждения оптики. Во втором исходный обычный импульс снят после PUT на фоне `image_motion`, два пробных импульса по 100 мс также остались без оптического подтверждения. Первое подтверждение получено на обычных запросах №3 и №5 соответственно. Первые записанные безопасные проекции в обоих случаях позже первого движения, поэтому изменение длительности из PR №14 ещё не подтверждает выигрыш на этих пролётах. Защитные остановки сохраняются. На кадрах второго пролёта PTS 94 и 114 расширенная область вернула `None`. Энергия в ядре рамки составила 142 и 8994 соответственно. При пороге 280 первый кадр удерживает паузу, второй её снимает. Два различимых кадра из пролёта 14:24 проходят проверку. Сопоставление PTS с UTC на уровне отдельных кадров не выполнено. В окнах обоих пролётов журнал не показывает отправку тревоги по WebSocket. + +## Воспроизводимый эталон первых 20 секунд + +`replay_ptz17_reference.py` читает зафиксированные команды, завершения запросов и выборки свежего HFOV из `reference_fixture.json`. Запуск `python replay_ptz17_reference.py` восстанавливает `reference_replay.json`. В журнале время подтверждения и первое наблюдаемое изменение HFOV могут отличаться из-за округления меток и порядка записи. Время измеримого сужения определяется отдельно от подтверждения конкретного запроса. + +| TRACK, UTC+7 | Первый старт → первое подтверждение | Первый подтверждённый запрос | Свежие замеры HFOV за 20 с | +| --- | ---: | --- | ---: | +| 14:12:02 | 4,512 с | №3, 340 мс | 257 | +| 14:24:57 | 8,902 с | №3, 340 мс | 259 | +| 14:28:06 | 12,691 с | №5, 220 мс | 253 | + +Во всех трёх эпизодах поле зрения оставалось 59° до первого успешного запроса и затем сузилось до 54,12°. Это указывает на отсутствие измеримого сужения на ранних попытках. Из разреженных AIM нельзя восстановить разрешение более длинного первого импульса в момент решения или пересчитать физический контрфактический результат. Данные пригодны для сравнения по номеру запроса, времени первого оптического подтверждения и дальнейшим отметкам 2×/4×/8×. Для сравнения по времени до первого различимого резкого кадра нужна привязка PTS к UTC и покадровая проверка. diff --git a/integration/ptz17_focus_zoom/pins.json b/integration/ptz17_focus_zoom/pins.json index d70ecea..ba5c24c 100644 --- a/integration/ptz17_focus_zoom/pins.json +++ b/integration/ptz17_focus_zoom/pins.json @@ -1,6 +1,6 @@ { "base_sha256": "6cf484271ef3659028b0b4d43041addb05102f91d2758ab472d968a52d24e911", - "candidate_sha256": "da2a970deb041d6dc4897fd58c2efa2943803d46c3af6ddcf92d010a4ca0f589", - "patch_sha256": "6c6f5ee84f9be3976cf318431cfa505817f2322345215a76ae638873376d14c8", + "candidate_sha256": "26edb69b9d0bd0ae6ad4b9c18ff2f793bcb2a2cf035b38293a3e07d6fc833f8b", + "patch_sha256": "6a563f751871dcadc3c4daf730cc3cfb1ff6fd8edf1f379a2cee01f99302d4de", "installed": false } diff --git a/integration/ptz17_focus_zoom/reference_fixture.json b/integration/ptz17_focus_zoom/reference_fixture.json new file mode 100644 index 0000000..ea82d89 --- /dev/null +++ b/integration/ptz17_focus_zoom/reference_fixture.json @@ -0,0 +1,3285 @@ +{ + "1412": { + "start_utc": "2026-11-13T07:12:02.328+00:00", + "initial_send_s": 6.041, + "rows": { + "[ZOOM DELIVERY]": [ + [ + 6.115, + "[ZOOM DELIVERY] cam=6 request=1 kind=normal physical start seq=5714 pulse=0.100s hard=0.120s" + ], + [ + 6.231, + "[ZOOM DELIVERY] cam=6 request=1 result=delivered_wait_optics duration=0.191s min=0.070s optics=False reason=priority_stop:watchdog zstep=0 kind=normal native=10 stop_source=priority_stop stop_gen=7 stop_seq=-1 stop_requested=(0,0,0) stop_effective=(0,0,0)" + ], + [ + 7.766, + "[ZOOM DELIVERY] cam=6 request=2 kind=normal physical start seq=5724 pulse=0.220s hard=0.280s" + ], + [ + 8.086, + "[ZOOM DELIVERY] cam=6 request=2 result=delivered_wait_optics duration=0.402s min=0.154s optics=False reason=priority_stop:watchdog zstep=0 kind=normal native=10 stop_source=priority_stop stop_gen=7 stop_seq=-1 stop_requested=(0,0,0) stop_effective=(0,0,0)" + ], + [ + 10.164, + "[ZOOM DELIVERY] cam=6 request=3 kind=normal physical start seq=5736 pulse=0.340s hard=0.400s" + ], + [ + 10.496, + "[ZOOM DELIVERY] cam=6 request=3 result=delivered_wait_optics duration=0.395s min=0.238s optics=False reason=physical_stop zstep=0 kind=normal native=10 stop_source=track stop_gen=7 stop_seq=5739 stop_requested=(16,-7,0) stop_effective=(0,0,0)" + ], + [ + 10.627, + "[ZOOM DELIVERY] cam=6 request=3 optics confirmed source=status_poll zstep=1" + ], + [ + 14.109, + "[ZOOM DELIVERY] cam=6 request=4 kind=normal physical start seq=5757 pulse=0.100s hard=0.120s" + ], + [ + 14.182, + "[ZOOM DELIVERY] cam=6 request=4 result=discarded duration=0.147s min=0.070s optics=False reason=priority_stop:cancel_after_put zstep=1 kind=normal native=11 stop_source=priority_stop stop_gen=7 stop_seq=-1 stop_requested=(0,0,0) stop_effective=(0,0,0)" + ], + [ + 16.382, + "[ZOOM DELIVERY] cam=6 request=5 kind=normal physical start seq=5772 pulse=0.100s hard=0.120s" + ], + [ + 16.419, + "[ZOOM DELIVERY] cam=6 request=5 result=short duration=0.055s min=0.070s optics=False reason=physical_stop zstep=1 kind=normal native=11 stop_source=track stop_gen=7 stop_seq=5773 stop_requested=(17,3,0) stop_effective=(0,0,0)" + ], + [ + 17.247, + "[ZOOM DELIVERY] cam=6 request=6 kind=normal physical start seq=5778 pulse=0.340s hard=0.400s" + ], + [ + 17.445, + "[ZOOM DELIVERY] cam=6 request=6 result=delivered_wait_optics duration=0.244s min=0.238s optics=False reason=physical_stop zstep=1 kind=normal native=10 stop_source=track stop_gen=7 stop_seq=5779 stop_requested=(19,3,0) stop_effective=(0,0,0)" + ] + ], + "[ZOOM DECISION]": [ + [ + 10.481, + "[ZOOM DECISION] cam=6 frame=23879 request=3 source=track gen=7 seq=5739 queued_zoom=0 reason=recenter blockers=angle" + ], + [ + 14.055, + "[ZOOM DECISION] cam=6 frame=23907 request=4 source=track gen=7 seq=5759 queued_zoom=0 reason=recenter blockers=followup+angle+center_sample" + ], + [ + 16.399, + "[ZOOM DECISION] cam=6 frame=23925 request=5 source=track gen=7 seq=5773 queued_zoom=0 reason=size_controller blockers=angle" + ], + [ + 17.401, + "[ZOOM DECISION] cam=6 frame=23933 request=6 source=track gen=7 seq=5779 queued_zoom=0 reason=recenter blockers=angle" + ], + [ + 17.444, + "[ZOOM DECISION] cam=6 frame=23934 request=6 source=track gen=7 seq=5780 queued_zoom=0 reason=size_controller blockers=followup+angle+center_history+track_history" + ] + ] + }, + "status": [ + [ + 0.136, + 59.0 + ], + [ + 0.184, + 59.0 + ], + [ + 0.255, + 59.0 + ], + [ + 0.329, + 59.0 + ], + [ + 0.404, + 59.0 + ], + [ + 0.473, + 59.0 + ], + [ + 0.549, + 59.0 + ], + [ + 0.621, + 59.0 + ], + [ + 0.693, + 59.0 + ], + [ + 0.884, + 59.0 + ], + [ + 0.945, + 59.0 + ], + [ + 1.047, + 59.0 + ], + [ + 1.109, + 59.0 + ], + [ + 1.151, + 59.0 + ], + [ + 1.204, + 59.0 + ], + [ + 1.273, + 59.0 + ], + [ + 1.345, + 59.0 + ], + [ + 1.417, + 59.0 + ], + [ + 1.501, + 59.0 + ], + [ + 1.568, + 59.0 + ], + [ + 1.634, + 59.0 + ], + [ + 1.865, + 59.0 + ], + [ + 1.918, + 59.0 + ], + [ + 2.024, + 59.0 + ], + [ + 2.089, + 59.0 + ], + [ + 2.161, + 59.0 + ], + [ + 2.197, + 59.0 + ], + [ + 2.261, + 59.0 + ], + [ + 2.337, + 59.0 + ], + [ + 2.395, + 59.0 + ], + [ + 2.464, + 59.0 + ], + [ + 2.533, + 59.0 + ], + [ + 2.612, + 59.0 + ], + [ + 2.687, + 59.0 + ], + [ + 2.809, + 59.0 + ], + [ + 2.885, + 59.0 + ], + [ + 2.959, + 59.0 + ], + [ + 3.037, + 59.0 + ], + [ + 3.117, + 59.0 + ], + [ + 3.179, + 59.0 + ], + [ + 3.234, + 59.0 + ], + [ + 3.29, + 59.0 + ], + [ + 3.369, + 59.0 + ], + [ + 3.428, + 59.0 + ], + [ + 3.5, + 59.0 + ], + [ + 3.577, + 59.0 + ], + [ + 3.647, + 59.0 + ], + [ + 3.714, + 59.0 + ], + [ + 3.855, + 59.0 + ], + [ + 3.913, + 59.0 + ], + [ + 3.992, + 59.0 + ], + [ + 4.09, + 59.0 + ], + [ + 4.175, + 59.0 + ], + [ + 4.22, + 59.0 + ], + [ + 4.276, + 59.0 + ], + [ + 4.351, + 59.0 + ], + [ + 4.419, + 59.0 + ], + [ + 4.494, + 59.0 + ], + [ + 4.593, + 59.0 + ], + [ + 4.633, + 59.0 + ], + [ + 4.785, + 59.0 + ], + [ + 4.832, + 59.0 + ], + [ + 4.941, + 59.0 + ], + [ + 5.009, + 59.0 + ], + [ + 5.098, + 59.0 + ], + [ + 5.157, + 59.0 + ], + [ + 5.213, + 59.0 + ], + [ + 5.263, + 59.0 + ], + [ + 5.336, + 59.0 + ], + [ + 5.413, + 59.0 + ], + [ + 5.474, + 59.0 + ], + [ + 5.553, + 59.0 + ], + [ + 5.621, + 59.0 + ], + [ + 5.704, + 59.0 + ], + [ + 5.873, + 59.0 + ], + [ + 5.947, + 59.0 + ], + [ + 6.013, + 59.0 + ], + [ + 6.09, + 59.0 + ], + [ + 6.233, + 59.0 + ], + [ + 6.293, + 59.0 + ], + [ + 6.336, + 59.0 + ], + [ + 6.417, + 59.0 + ], + [ + 6.503, + 59.0 + ], + [ + 6.578, + 59.0 + ], + [ + 6.635, + 59.0 + ], + [ + 6.704, + 59.0 + ], + [ + 6.864, + 59.0 + ], + [ + 6.915, + 59.0 + ], + [ + 7.008, + 59.0 + ], + [ + 7.084, + 59.0 + ], + [ + 7.155, + 59.0 + ], + [ + 7.209, + 59.0 + ], + [ + 7.275, + 59.0 + ], + [ + 7.334, + 59.0 + ], + [ + 7.388, + 59.0 + ], + [ + 7.463, + 59.0 + ], + [ + 7.539, + 59.0 + ], + [ + 7.618, + 59.0 + ], + [ + 7.693, + 59.0 + ], + [ + 7.835, + 59.0 + ], + [ + 7.88, + 59.0 + ], + [ + 8.089, + 59.0 + ], + [ + 8.167, + 59.0 + ], + [ + 8.211, + 59.0 + ], + [ + 8.286, + 59.0 + ], + [ + 8.356, + 59.0 + ], + [ + 8.425, + 59.0 + ], + [ + 8.502, + 59.0 + ], + [ + 8.595, + 59.0 + ], + [ + 8.664, + 59.0 + ], + [ + 8.809, + 59.0 + ], + [ + 8.871, + 59.0 + ], + [ + 8.957, + 59.0 + ], + [ + 9.037, + 59.0 + ], + [ + 9.103, + 59.0 + ], + [ + 9.176, + 59.0 + ], + [ + 9.221, + 59.0 + ], + [ + 9.285, + 59.0 + ], + [ + 9.331, + 59.0 + ], + [ + 9.416, + 59.0 + ], + [ + 9.496, + 59.0 + ], + [ + 9.564, + 59.0 + ], + [ + 9.634, + 59.0 + ], + [ + 9.807, + 59.0 + ], + [ + 9.855, + 59.0 + ], + [ + 9.97, + 59.0 + ], + [ + 10.027, + 59.0 + ], + [ + 10.125, + 59.0 + ], + [ + 10.178, + 59.0 + ], + [ + 10.234, + 59.0 + ], + [ + 10.313, + 59.0 + ], + [ + 10.374, + 59.0 + ], + [ + 10.433, + 59.0 + ], + [ + 10.509, + 59.0 + ], + [ + 10.627, + 54.12173440987275 + ], + [ + 10.673, + 54.12173440987275 + ], + [ + 10.811, + 54.12173440987275 + ], + [ + 10.865, + 54.12173440987275 + ], + [ + 10.961, + 54.12173440987275 + ], + [ + 11.043, + 54.12173440987275 + ], + [ + 11.117, + 54.12173440987275 + ], + [ + 11.198, + 54.12173440987275 + ], + [ + 11.237, + 54.12173440987275 + ], + [ + 11.321, + 54.12173440987275 + ], + [ + 11.379, + 54.12173440987275 + ], + [ + 11.454, + 54.12173440987275 + ], + [ + 11.507, + 54.12173440987275 + ], + [ + 11.566, + 54.12173440987275 + ], + [ + 11.646, + 54.12173440987275 + ], + [ + 11.81, + 54.12173440987275 + ], + [ + 11.867, + 54.12173440987275 + ], + [ + 11.949, + 54.12173440987275 + ], + [ + 12.019, + 54.12173440987275 + ], + [ + 12.096, + 54.12173440987275 + ], + [ + 12.161, + 54.12173440987275 + ], + [ + 12.208, + 54.12173440987275 + ], + [ + 12.286, + 54.12173440987275 + ], + [ + 12.34, + 54.12173440987275 + ], + [ + 12.411, + 54.12173440987275 + ], + [ + 12.474, + 54.12173440987275 + ], + [ + 12.552, + 54.12173440987275 + ], + [ + 12.626, + 54.12173440987275 + ], + [ + 12.795, + 54.12173440987275 + ], + [ + 12.86, + 54.12173440987275 + ], + [ + 12.941, + 54.12173440987275 + ], + [ + 13.015, + 54.12173440987275 + ], + [ + 13.089, + 54.12173440987275 + ], + [ + 13.15, + 54.12173440987275 + ], + [ + 13.206, + 54.12173440987275 + ], + [ + 13.257, + 54.12173440987275 + ], + [ + 13.315, + 54.12173440987275 + ], + [ + 13.391, + 54.12173440987275 + ], + [ + 13.465, + 54.12173440987275 + ], + [ + 13.545, + 54.12173440987275 + ], + [ + 13.597, + 54.12173440987275 + ], + [ + 13.674, + 54.12173440987275 + ], + [ + 13.818, + 54.12173440987275 + ], + [ + 13.876, + 54.12173440987275 + ], + [ + 13.956, + 54.12173440987275 + ], + [ + 14.027, + 54.12173440987275 + ], + [ + 14.096, + 54.12173440987275 + ], + [ + 14.221, + 54.12173440987275 + ], + [ + 14.301, + 54.12173440987275 + ], + [ + 14.334, + 54.12173440987275 + ], + [ + 14.417, + 54.12173440987275 + ], + [ + 14.494, + 54.12173440987275 + ], + [ + 14.587, + 54.12173440987275 + ], + [ + 14.651, + 54.12173440987275 + ], + [ + 14.779, + 54.12173440987275 + ], + [ + 14.842, + 54.12173440987275 + ], + [ + 14.92, + 54.12173440987275 + ], + [ + 15.005, + 54.12173440987275 + ], + [ + 15.099, + 54.12173440987275 + ], + [ + 15.161, + 54.12173440987275 + ], + [ + 15.208, + 54.12173440987275 + ], + [ + 15.282, + 54.12173440987275 + ], + [ + 15.333, + 54.12173440987275 + ], + [ + 15.415, + 54.12173440987275 + ], + [ + 15.477, + 54.12173440987275 + ], + [ + 15.545, + 54.12173440987275 + ], + [ + 15.617, + 54.12173440987275 + ], + [ + 15.788, + 54.12173440987275 + ], + [ + 15.844, + 54.12173440987275 + ], + [ + 15.947, + 54.12173440987275 + ], + [ + 16.018, + 54.12173440987275 + ], + [ + 16.104, + 54.12173440987275 + ], + [ + 16.156, + 54.12173440987275 + ], + [ + 16.234, + 54.12173440987275 + ], + [ + 16.292, + 54.12173440987275 + ], + [ + 16.339, + 54.12173440987275 + ], + [ + 16.419, + 54.12173440987275 + ], + [ + 16.494, + 54.12173440987275 + ], + [ + 16.565, + 54.12173440987275 + ], + [ + 16.622, + 54.12173440987275 + ], + [ + 16.795, + 54.12173440987275 + ], + [ + 16.833, + 54.12173440987275 + ], + [ + 16.948, + 54.12173440987275 + ], + [ + 17.04, + 54.12173440987275 + ], + [ + 17.118, + 54.12173440987275 + ], + [ + 17.156, + 54.12173440987275 + ], + [ + 17.24, + 54.12173440987275 + ], + [ + 17.313, + 54.12173440987275 + ], + [ + 17.383, + 54.12173440987275 + ], + [ + 17.453, + 54.12173440987275 + ], + [ + 17.538, + 54.12173440987275 + ], + [ + 17.574, + 54.12173440987275 + ], + [ + 17.662, + 54.12173440987275 + ], + [ + 17.71, + 54.12173440987275 + ], + [ + 17.848, + 54.12173440987275 + ], + [ + 17.921, + 54.12173440987275 + ], + [ + 18.0, + 54.12173440987275 + ], + [ + 18.075, + 54.12173440987275 + ], + [ + 18.136, + 54.12173440987275 + ], + [ + 18.219, + 54.12173440987275 + ], + [ + 18.262, + 54.12173440987275 + ], + [ + 18.319, + 54.12173440987275 + ], + [ + 18.382, + 54.12173440987275 + ], + [ + 18.454, + 54.12173440987275 + ], + [ + 18.562, + 54.12173440987275 + ], + [ + 18.61, + 54.12173440987275 + ], + [ + 18.674, + 54.12173440987275 + ], + [ + 18.79, + 54.12173440987275 + ], + [ + 18.89, + 54.12173440987275 + ], + [ + 18.972, + 54.12173440987275 + ], + [ + 19.057, + 54.12173440987275 + ], + [ + 19.133, + 54.12173440987275 + ], + [ + 19.166, + 54.12173440987275 + ], + [ + 19.218, + 54.12173440987275 + ], + [ + 19.292, + 54.12173440987275 + ], + [ + 19.366, + 54.12173440987275 + ], + [ + 19.431, + 54.12173440987275 + ], + [ + 19.506, + 54.12173440987275 + ], + [ + 19.58, + 54.12173440987275 + ], + [ + 19.661, + 54.12173440987275 + ], + [ + 19.817, + 54.12173440987275 + ], + [ + 19.891, + 54.12173440987275 + ], + [ + 19.96, + 54.12173440987275 + ] + ], + "first_logged_projection_s": 9.869 + }, + "1424": { + "start_utc": "2026-11-13T07:24:57.917+00:00", + "initial_send_s": 8.054, + "rows": { + "[ZOOM DELIVERY]": [ + [ + 8.118, + "[ZOOM DELIVERY] cam=6 request=1 kind=normal physical start seq=7515 pulse=0.100s hard=0.120s" + ], + [ + 8.245, + "[ZOOM DELIVERY] cam=6 request=1 result=delivered_wait_optics duration=0.192s min=0.070s optics=False reason=priority_stop:watchdog zstep=0 kind=normal native=10 stop_source=priority_stop stop_gen=9 stop_seq=-1 stop_requested=(0,0,0) stop_effective=(0,0,0)" + ], + [ + 12.205, + "[ZOOM DELIVERY] cam=6 request=2 kind=normal physical start seq=7536 pulse=0.220s hard=0.280s" + ], + [ + 12.392, + "[ZOOM DELIVERY] cam=6 request=2 result=delivered_wait_optics duration=0.248s min=0.154s optics=False reason=physical_stop zstep=0 kind=normal native=10 stop_source=track stop_gen=9 stop_seq=7538 stop_requested=(20,-7,0) stop_effective=(0,0,0)" + ], + [ + 16.563, + "[ZOOM DELIVERY] cam=6 request=3 kind=normal physical start seq=7556 pulse=0.340s hard=0.400s" + ], + [ + 17.018, + "[ZOOM DELIVERY] cam=6 request=3 result=delivered_wait_optics duration=0.470s min=0.238s optics=False reason=priority_stop:watchdog zstep=0 kind=normal native=10 stop_source=priority_stop stop_gen=9 stop_seq=-1 stop_requested=(0,0,0) stop_effective=(0,0,0)" + ], + [ + 17.02, + "[ZOOM DELIVERY] cam=6 request=3 optics confirmed source=status_poll zstep=1" + ], + [ + 19.593, + "[ZOOM DELIVERY] cam=6 request=4 kind=normal physical start seq=7572 pulse=0.340s hard=0.400s" + ] + ], + "[ZOOM DECISION]": [ + [ + 12.379, + "[ZOOM DECISION] cam=6 frame=30317 request=2 source=track gen=9 seq=7538 queued_zoom=0 reason=recenter blockers=angle+center_sample" + ] + ] + }, + "status": [ + [ + 0.029, + 59.0 + ], + [ + 0.155, + 59.0 + ], + [ + 0.217, + 59.0 + ], + [ + 0.266, + 59.0 + ], + [ + 0.314, + 59.0 + ], + [ + 0.389, + 59.0 + ], + [ + 0.457, + 59.0 + ], + [ + 0.531, + 59.0 + ], + [ + 0.599, + 59.0 + ], + [ + 0.674, + 59.0 + ], + [ + 0.756, + 59.0 + ], + [ + 0.83, + 59.0 + ], + [ + 1.028, + 59.0 + ], + [ + 1.065, + 59.0 + ], + [ + 1.187, + 59.0 + ], + [ + 1.253, + 59.0 + ], + [ + 1.319, + 59.0 + ], + [ + 1.362, + 59.0 + ], + [ + 1.426, + 59.0 + ], + [ + 1.508, + 59.0 + ], + [ + 1.565, + 59.0 + ], + [ + 1.636, + 59.0 + ], + [ + 1.713, + 59.0 + ], + [ + 1.786, + 59.0 + ], + [ + 1.958, + 59.0 + ], + [ + 1.998, + 59.0 + ], + [ + 2.098, + 59.0 + ], + [ + 2.178, + 59.0 + ], + [ + 2.256, + 59.0 + ], + [ + 2.297, + 59.0 + ], + [ + 2.36, + 59.0 + ], + [ + 2.409, + 59.0 + ], + [ + 2.489, + 59.0 + ], + [ + 2.553, + 59.0 + ], + [ + 2.627, + 59.0 + ], + [ + 2.703, + 59.0 + ], + [ + 2.774, + 59.0 + ], + [ + 2.999, + 59.0 + ], + [ + 3.037, + 59.0 + ], + [ + 3.15, + 59.0 + ], + [ + 3.223, + 59.0 + ], + [ + 3.25, + 59.0 + ], + [ + 3.316, + 59.0 + ], + [ + 3.378, + 59.0 + ], + [ + 3.454, + 59.0 + ], + [ + 3.524, + 59.0 + ], + [ + 3.592, + 59.0 + ], + [ + 3.68, + 59.0 + ], + [ + 3.736, + 59.0 + ], + [ + 3.81, + 59.0 + ], + [ + 3.955, + 59.0 + ], + [ + 3.992, + 59.0 + ], + [ + 4.083, + 59.0 + ], + [ + 4.175, + 59.0 + ], + [ + 4.241, + 59.0 + ], + [ + 4.294, + 59.0 + ], + [ + 4.339, + 59.0 + ], + [ + 4.404, + 59.0 + ], + [ + 4.479, + 59.0 + ], + [ + 4.544, + 59.0 + ], + [ + 4.611, + 59.0 + ], + [ + 4.685, + 59.0 + ], + [ + 4.761, + 59.0 + ], + [ + 4.828, + 59.0 + ], + [ + 4.979, + 59.0 + ], + [ + 5.036, + 59.0 + ], + [ + 5.111, + 59.0 + ], + [ + 5.194, + 59.0 + ], + [ + 5.253, + 59.0 + ], + [ + 5.295, + 59.0 + ], + [ + 5.356, + 59.0 + ], + [ + 5.431, + 59.0 + ], + [ + 5.524, + 59.0 + ], + [ + 5.575, + 59.0 + ], + [ + 5.661, + 59.0 + ], + [ + 5.719, + 59.0 + ], + [ + 5.795, + 59.0 + ], + [ + 5.977, + 59.0 + ], + [ + 6.026, + 59.0 + ], + [ + 6.142, + 59.0 + ], + [ + 6.207, + 59.0 + ], + [ + 6.254, + 59.0 + ], + [ + 6.309, + 59.0 + ], + [ + 6.385, + 59.0 + ], + [ + 6.452, + 59.0 + ], + [ + 6.519, + 59.0 + ], + [ + 6.593, + 59.0 + ], + [ + 6.669, + 59.0 + ], + [ + 6.733, + 59.0 + ], + [ + 6.822, + 59.0 + ], + [ + 6.945, + 59.0 + ], + [ + 6.981, + 59.0 + ], + [ + 7.107, + 59.0 + ], + [ + 7.185, + 59.0 + ], + [ + 7.255, + 59.0 + ], + [ + 7.293, + 59.0 + ], + [ + 7.338, + 59.0 + ], + [ + 7.407, + 59.0 + ], + [ + 7.481, + 59.0 + ], + [ + 7.555, + 59.0 + ], + [ + 7.634, + 59.0 + ], + [ + 7.696, + 59.0 + ], + [ + 7.77, + 59.0 + ], + [ + 7.982, + 59.0 + ], + [ + 8.023, + 59.0 + ], + [ + 8.141, + 59.0 + ], + [ + 8.247, + 59.0 + ], + [ + 8.275, + 59.0 + ], + [ + 8.331, + 59.0 + ], + [ + 8.401, + 59.0 + ], + [ + 8.475, + 59.0 + ], + [ + 8.555, + 59.0 + ], + [ + 8.618, + 59.0 + ], + [ + 8.694, + 59.0 + ], + [ + 8.771, + 59.0 + ], + [ + 8.996, + 59.0 + ], + [ + 9.034, + 59.0 + ], + [ + 9.144, + 59.0 + ], + [ + 9.217, + 59.0 + ], + [ + 9.274, + 59.0 + ], + [ + 9.334, + 59.0 + ], + [ + 9.378, + 59.0 + ], + [ + 9.461, + 59.0 + ], + [ + 9.532, + 59.0 + ], + [ + 9.603, + 59.0 + ], + [ + 9.704, + 59.0 + ], + [ + 9.748, + 59.0 + ], + [ + 9.818, + 59.0 + ], + [ + 9.948, + 59.0 + ], + [ + 9.995, + 59.0 + ], + [ + 10.076, + 59.0 + ], + [ + 10.144, + 59.0 + ], + [ + 10.217, + 59.0 + ], + [ + 10.283, + 59.0 + ], + [ + 10.321, + 59.0 + ], + [ + 10.397, + 59.0 + ], + [ + 10.476, + 59.0 + ], + [ + 10.54, + 59.0 + ], + [ + 10.609, + 59.0 + ], + [ + 10.688, + 59.0 + ], + [ + 10.755, + 59.0 + ], + [ + 10.822, + 59.0 + ], + [ + 10.984, + 59.0 + ], + [ + 11.032, + 59.0 + ], + [ + 11.11, + 59.0 + ], + [ + 11.216, + 59.0 + ], + [ + 11.285, + 59.0 + ], + [ + 11.335, + 59.0 + ], + [ + 11.389, + 59.0 + ], + [ + 11.454, + 59.0 + ], + [ + 11.529, + 59.0 + ], + [ + 11.595, + 59.0 + ], + [ + 11.688, + 59.0 + ], + [ + 11.748, + 59.0 + ], + [ + 11.92, + 59.0 + ], + [ + 11.965, + 59.0 + ], + [ + 12.085, + 59.0 + ], + [ + 12.159, + 59.0 + ], + [ + 12.209, + 59.0 + ], + [ + 12.265, + 59.0 + ], + [ + 12.317, + 59.0 + ], + [ + 12.377, + 59.0 + ], + [ + 12.452, + 59.0 + ], + [ + 12.529, + 59.0 + ], + [ + 12.597, + 59.0 + ], + [ + 12.69, + 59.0 + ], + [ + 12.736, + 59.0 + ], + [ + 12.912, + 59.0 + ], + [ + 12.962, + 59.0 + ], + [ + 13.062, + 59.0 + ], + [ + 13.131, + 59.0 + ], + [ + 13.208, + 59.0 + ], + [ + 13.255, + 59.0 + ], + [ + 13.32, + 59.0 + ], + [ + 13.392, + 59.0 + ], + [ + 13.445, + 59.0 + ], + [ + 13.516, + 59.0 + ], + [ + 13.595, + 59.0 + ], + [ + 13.681, + 59.0 + ], + [ + 13.736, + 59.0 + ], + [ + 13.808, + 59.0 + ], + [ + 13.961, + 59.0 + ], + [ + 14.032, + 59.0 + ], + [ + 14.093, + 59.0 + ], + [ + 14.189, + 59.0 + ], + [ + 14.244, + 59.0 + ], + [ + 14.288, + 59.0 + ], + [ + 14.354, + 59.0 + ], + [ + 14.433, + 59.0 + ], + [ + 14.507, + 59.0 + ], + [ + 14.578, + 59.0 + ], + [ + 14.647, + 59.0 + ], + [ + 14.751, + 59.0 + ], + [ + 14.967, + 59.0 + ], + [ + 15.015, + 59.0 + ], + [ + 15.107, + 59.0 + ], + [ + 15.204, + 59.0 + ], + [ + 15.285, + 59.0 + ], + [ + 15.332, + 59.0 + ], + [ + 15.398, + 59.0 + ], + [ + 15.477, + 59.0 + ], + [ + 15.556, + 59.0 + ], + [ + 15.617, + 59.0 + ], + [ + 15.702, + 59.0 + ], + [ + 15.758, + 59.0 + ], + [ + 15.947, + 59.0 + ], + [ + 16.023, + 59.0 + ], + [ + 16.109, + 59.0 + ], + [ + 16.185, + 59.0 + ], + [ + 16.243, + 59.0 + ], + [ + 16.311, + 59.0 + ], + [ + 16.349, + 59.0 + ], + [ + 16.414, + 59.0 + ], + [ + 16.485, + 59.0 + ], + [ + 16.558, + 59.0 + ], + [ + 16.628, + 59.0 + ], + [ + 16.7, + 59.0 + ], + [ + 16.775, + 59.0 + ], + [ + 16.949, + 59.0 + ], + [ + 17.02, + 54.12173440987275 + ], + [ + 17.098, + 50.02128766445013 + ], + [ + 17.168, + 50.02128766445013 + ], + [ + 17.239, + 50.02128766445013 + ], + [ + 17.291, + 50.02128766445013 + ], + [ + 17.361, + 50.02128766445013 + ], + [ + 17.401, + 50.02128766445013 + ], + [ + 17.494, + 50.02128766445013 + ], + [ + 17.572, + 50.02128766445013 + ], + [ + 17.637, + 50.02128766445013 + ], + [ + 17.714, + 50.02128766445013 + ], + [ + 17.778, + 50.02128766445013 + ], + [ + 17.921, + 50.02128766445013 + ], + [ + 17.983, + 50.02128766445013 + ], + [ + 18.036, + 50.02128766445013 + ], + [ + 18.139, + 50.02128766445013 + ], + [ + 18.209, + 50.02128766445013 + ], + [ + 18.248, + 50.02128766445013 + ], + [ + 18.296, + 50.02128766445013 + ], + [ + 18.369, + 50.02128766445013 + ], + [ + 18.444, + 50.02128766445013 + ], + [ + 18.515, + 50.02128766445013 + ], + [ + 18.588, + 50.02128766445013 + ], + [ + 18.654, + 50.02128766445013 + ], + [ + 18.738, + 50.02128766445013 + ], + [ + 18.803, + 50.02128766445013 + ], + [ + 18.983, + 50.02128766445013 + ], + [ + 19.056, + 50.02128766445013 + ], + [ + 19.138, + 50.02128766445013 + ], + [ + 19.211, + 50.02128766445013 + ], + [ + 19.253, + 50.02128766445013 + ], + [ + 19.302, + 50.02128766445013 + ], + [ + 19.375, + 50.02128766445013 + ], + [ + 19.448, + 50.02128766445013 + ], + [ + 19.529, + 50.02128766445013 + ], + [ + 19.599, + 50.02128766445013 + ], + [ + 19.697, + 50.02128766445013 + ], + [ + 19.745, + 50.02128766445013 + ], + [ + 19.901, + 46.524147844879025 + ], + [ + 19.953, + 46.524147844879025 + ] + ], + "first_logged_projection_s": 11.23 + }, + "1428": { + "start_utc": "2026-11-13T07:28:06.389+00:00", + "initial_send_s": 4.227, + "rows": { + "[ZOOM DELIVERY]": [ + [ + 4.294, + "[ZOOM DELIVERY] cam=6 request=1 kind=normal physical start seq=8125 pulse=0.100s hard=0.120s" + ], + [ + 4.399, + "[ZOOM DELIVERY] cam=6 request=1 result=discarded duration=0.172s min=0.070s optics=False reason=priority_stop:cancel_after_put zstep=0 kind=normal native=10 stop_source=priority_stop stop_gen=11 stop_seq=-1 stop_requested=(0,0,0) stop_effective=(0,0,0)" + ], + [ + 6.302, + "[ZOOM DELIVERY] cam=6 request=2 kind=probe physical start seq=8137 pulse=0.100s hard=0.120s" + ], + [ + 6.448, + "[ZOOM DELIVERY] cam=6 request=2 result=discarded duration=0.208s min=0.070s optics=False reason=priority_stop:watchdog zstep=0 kind=probe native=10 stop_source=priority_stop stop_gen=11 stop_seq=-1 stop_requested=(0,0,0) stop_effective=(0,0,0)" + ], + [ + 10.195, + "[ZOOM DELIVERY] cam=6 request=3 kind=probe physical start seq=8157 pulse=0.100s hard=0.120s" + ], + [ + 10.365, + "[ZOOM DELIVERY] cam=6 request=3 result=delivered_wait_optics duration=0.208s min=0.070s optics=False reason=priority_stop:watchdog zstep=0 kind=probe native=10 stop_source=priority_stop stop_gen=11 stop_seq=-1 stop_requested=(0,0,0) stop_effective=(0,0,0)" + ], + [ + 14.181, + "[ZOOM DELIVERY] cam=6 request=4 kind=normal physical start seq=8178 pulse=0.220s hard=0.280s" + ], + [ + 14.273, + "[ZOOM DELIVERY] cam=6 request=4 result=discarded duration=0.121s min=0.154s optics=False reason=priority_stop:cancel_after_put zstep=0 kind=normal native=10 stop_source=priority_stop stop_gen=11 stop_seq=-1 stop_requested=(0,0,0) stop_effective=(0,0,0)" + ], + [ + 16.639, + "[ZOOM DELIVERY] cam=6 request=5 kind=normal physical start seq=8194 pulse=0.220s hard=0.280s" + ], + [ + 16.942, + "[ZOOM DELIVERY] cam=6 request=5 result=delivered_wait_optics duration=0.314s min=0.154s optics=False reason=priority_stop:watchdog zstep=0 kind=normal native=10 stop_source=priority_stop stop_gen=11 stop_seq=-1 stop_requested=(0,0,0) stop_effective=(0,0,0)" + ], + [ + 16.985, + "[ZOOM DELIVERY] cam=6 request=5 optics confirmed source=status_poll zstep=1" + ] + ], + "[ZOOM DECISION]": [ + [ + 4.235, + "[ZOOM DECISION] cam=6 frame=31790 request=1 source=track gen=11 seq=8127 queued_zoom=0 reason=image_motion blockers=-" + ], + [ + 10.261, + "[ZOOM DECISION] cam=6 frame=31843 request=3 source=track gen=11 seq=8158 queued_zoom=0 reason=size_controller blockers=angle" + ], + [ + 14.158, + "[ZOOM DECISION] cam=6 frame=31879 request=4 source=track gen=11 seq=8180 queued_zoom=0 reason=recenter blockers=angle+center_sample" + ], + [ + 16.894, + "[ZOOM DECISION] cam=6 frame=31903 request=5 source=track gen=11 seq=8196 queued_zoom=0 reason=size_controller blockers=angle" + ] + ] + }, + "status": [ + [ + 0.043, + 59.0 + ], + [ + 0.279, + 59.0 + ], + [ + 0.431, + 59.0 + ], + [ + 0.503, + 59.0 + ], + [ + 0.54, + 59.0 + ], + [ + 0.597, + 59.0 + ], + [ + 0.682, + 59.0 + ], + [ + 0.766, + 59.0 + ], + [ + 0.832, + 59.0 + ], + [ + 0.933, + 59.0 + ], + [ + 0.976, + 59.0 + ], + [ + 1.172, + 59.0 + ], + [ + 1.216, + 59.0 + ], + [ + 1.324, + 59.0 + ], + [ + 1.398, + 59.0 + ], + [ + 1.473, + 59.0 + ], + [ + 1.494, + 59.0 + ], + [ + 1.573, + 59.0 + ], + [ + 1.641, + 59.0 + ], + [ + 1.702, + 59.0 + ], + [ + 1.776, + 59.0 + ], + [ + 1.857, + 59.0 + ], + [ + 1.914, + 59.0 + ], + [ + 1.992, + 59.0 + ], + [ + 2.176, + 59.0 + ], + [ + 2.23, + 59.0 + ], + [ + 2.305, + 59.0 + ], + [ + 2.395, + 59.0 + ], + [ + 2.457, + 59.0 + ], + [ + 2.494, + 59.0 + ], + [ + 2.553, + 59.0 + ], + [ + 2.633, + 59.0 + ], + [ + 2.699, + 59.0 + ], + [ + 2.785, + 59.0 + ], + [ + 2.843, + 59.0 + ], + [ + 2.932, + 59.0 + ], + [ + 2.994, + 59.0 + ], + [ + 3.059, + 59.0 + ], + [ + 3.192, + 59.0 + ], + [ + 3.25, + 59.0 + ], + [ + 3.352, + 59.0 + ], + [ + 3.432, + 59.0 + ], + [ + 3.498, + 59.0 + ], + [ + 3.541, + 59.0 + ], + [ + 3.59, + 59.0 + ], + [ + 3.664, + 59.0 + ], + [ + 3.745, + 59.0 + ], + [ + 3.813, + 59.0 + ], + [ + 3.893, + 59.0 + ], + [ + 3.969, + 59.0 + ], + [ + 4.028, + 59.0 + ], + [ + 4.193, + 59.0 + ], + [ + 4.249, + 59.0 + ], + [ + 4.401, + 59.0 + ], + [ + 4.459, + 59.0 + ], + [ + 4.532, + 59.0 + ], + [ + 4.573, + 59.0 + ], + [ + 4.639, + 59.0 + ], + [ + 4.713, + 59.0 + ], + [ + 4.785, + 59.0 + ], + [ + 4.855, + 59.0 + ], + [ + 4.933, + 59.0 + ], + [ + 4.994, + 59.0 + ], + [ + 5.164, + 59.0 + ], + [ + 5.216, + 59.0 + ], + [ + 5.309, + 59.0 + ], + [ + 5.402, + 59.0 + ], + [ + 5.451, + 59.0 + ], + [ + 5.513, + 59.0 + ], + [ + 5.568, + 59.0 + ], + [ + 5.636, + 59.0 + ], + [ + 5.699, + 59.0 + ], + [ + 5.771, + 59.0 + ], + [ + 5.852, + 59.0 + ], + [ + 5.911, + 59.0 + ], + [ + 5.985, + 59.0 + ], + [ + 6.066, + 59.0 + ], + [ + 6.197, + 59.0 + ], + [ + 6.257, + 59.0 + ], + [ + 6.336, + 59.0 + ], + [ + 6.519, + 59.0 + ], + [ + 6.55, + 59.0 + ], + [ + 6.615, + 59.0 + ], + [ + 6.678, + 59.0 + ], + [ + 6.75, + 59.0 + ], + [ + 6.822, + 59.0 + ], + [ + 6.93, + 59.0 + ], + [ + 6.971, + 59.0 + ], + [ + 7.14, + 59.0 + ], + [ + 7.195, + 59.0 + ], + [ + 7.291, + 59.0 + ], + [ + 7.366, + 59.0 + ], + [ + 7.44, + 59.0 + ], + [ + 7.462, + 59.0 + ], + [ + 7.545, + 59.0 + ], + [ + 7.604, + 59.0 + ], + [ + 7.67, + 59.0 + ], + [ + 7.745, + 59.0 + ], + [ + 7.817, + 59.0 + ], + [ + 7.892, + 59.0 + ], + [ + 7.966, + 59.0 + ], + [ + 8.138, + 59.0 + ], + [ + 8.179, + 59.0 + ], + [ + 8.274, + 59.0 + ], + [ + 8.339, + 59.0 + ], + [ + 8.434, + 59.0 + ], + [ + 8.459, + 59.0 + ], + [ + 8.545, + 59.0 + ], + [ + 8.59, + 59.0 + ], + [ + 8.65, + 59.0 + ], + [ + 8.733, + 59.0 + ], + [ + 8.808, + 59.0 + ], + [ + 8.891, + 59.0 + ], + [ + 8.975, + 59.0 + ], + [ + 9.028, + 59.0 + ], + [ + 9.198, + 59.0 + ], + [ + 9.261, + 59.0 + ], + [ + 9.363, + 59.0 + ], + [ + 9.44, + 59.0 + ], + [ + 9.512, + 59.0 + ], + [ + 9.562, + 59.0 + ], + [ + 9.618, + 59.0 + ], + [ + 9.672, + 59.0 + ], + [ + 9.74, + 59.0 + ], + [ + 9.817, + 59.0 + ], + [ + 9.898, + 59.0 + ], + [ + 9.958, + 59.0 + ], + [ + 10.031, + 59.0 + ], + [ + 10.166, + 59.0 + ], + [ + 10.235, + 59.0 + ], + [ + 10.428, + 59.0 + ], + [ + 10.491, + 59.0 + ], + [ + 10.554, + 59.0 + ], + [ + 10.641, + 59.0 + ], + [ + 10.705, + 59.0 + ], + [ + 10.784, + 59.0 + ], + [ + 10.837, + 59.0 + ], + [ + 10.93, + 59.0 + ], + [ + 10.994, + 59.0 + ], + [ + 11.049, + 59.0 + ], + [ + 11.178, + 59.0 + ], + [ + 11.252, + 59.0 + ], + [ + 11.335, + 59.0 + ], + [ + 11.413, + 59.0 + ], + [ + 11.514, + 59.0 + ], + [ + 11.569, + 59.0 + ], + [ + 11.635, + 59.0 + ], + [ + 11.699, + 59.0 + ], + [ + 11.755, + 59.0 + ], + [ + 11.83, + 59.0 + ], + [ + 11.899, + 59.0 + ], + [ + 11.975, + 59.0 + ], + [ + 12.159, + 59.0 + ], + [ + 12.215, + 59.0 + ], + [ + 12.321, + 59.0 + ], + [ + 12.389, + 59.0 + ], + [ + 12.46, + 59.0 + ], + [ + 12.492, + 59.0 + ], + [ + 12.573, + 59.0 + ], + [ + 12.629, + 59.0 + ], + [ + 12.684, + 59.0 + ], + [ + 12.757, + 59.0 + ], + [ + 12.828, + 59.0 + ], + [ + 12.917, + 59.0 + ], + [ + 12.99, + 59.0 + ], + [ + 13.14, + 59.0 + ], + [ + 13.195, + 59.0 + ], + [ + 13.327, + 59.0 + ], + [ + 13.407, + 59.0 + ], + [ + 13.479, + 59.0 + ], + [ + 13.525, + 59.0 + ], + [ + 13.595, + 59.0 + ], + [ + 13.643, + 59.0 + ], + [ + 13.712, + 59.0 + ], + [ + 13.799, + 59.0 + ], + [ + 13.864, + 59.0 + ], + [ + 13.931, + 59.0 + ], + [ + 14.003, + 59.0 + ], + [ + 14.164, + 59.0 + ], + [ + 14.34, + 59.0 + ], + [ + 14.417, + 59.0 + ], + [ + 14.503, + 59.0 + ], + [ + 14.558, + 59.0 + ], + [ + 14.631, + 59.0 + ], + [ + 14.691, + 59.0 + ], + [ + 14.749, + 59.0 + ], + [ + 14.831, + 59.0 + ], + [ + 14.92, + 59.0 + ], + [ + 14.953, + 59.0 + ], + [ + 15.128, + 59.0 + ], + [ + 15.19, + 59.0 + ], + [ + 15.29, + 59.0 + ], + [ + 15.366, + 59.0 + ], + [ + 15.44, + 59.0 + ], + [ + 15.49, + 59.0 + ], + [ + 15.552, + 59.0 + ], + [ + 15.599, + 59.0 + ], + [ + 15.672, + 59.0 + ], + [ + 15.745, + 59.0 + ], + [ + 15.816, + 59.0 + ], + [ + 15.896, + 59.0 + ], + [ + 15.967, + 59.0 + ], + [ + 16.142, + 59.0 + ], + [ + 16.178, + 59.0 + ], + [ + 16.285, + 59.0 + ], + [ + 16.37, + 59.0 + ], + [ + 16.442, + 59.0 + ], + [ + 16.471, + 59.0 + ], + [ + 16.54, + 59.0 + ], + [ + 16.603, + 59.0 + ], + [ + 16.683, + 59.0 + ], + [ + 16.787, + 59.0 + ], + [ + 16.829, + 59.0 + ], + [ + 16.986, + 54.12173440987275 + ], + [ + 17.088, + 54.12173440987275 + ], + [ + 17.184, + 54.12173440987275 + ], + [ + 17.243, + 54.12173440987275 + ], + [ + 17.341, + 54.12173440987275 + ], + [ + 17.42, + 54.12173440987275 + ], + [ + 17.483, + 54.12173440987275 + ], + [ + 17.537, + 54.12173440987275 + ], + [ + 17.593, + 54.12173440987275 + ], + [ + 17.669, + 54.12173440987275 + ], + [ + 17.745, + 54.12173440987275 + ], + [ + 17.823, + 54.12173440987275 + ], + [ + 17.897, + 54.12173440987275 + ], + [ + 17.967, + 54.12173440987275 + ], + [ + 18.162, + 54.12173440987275 + ], + [ + 18.209, + 54.12173440987275 + ], + [ + 18.313, + 54.12173440987275 + ], + [ + 18.385, + 54.12173440987275 + ], + [ + 18.459, + 54.12173440987275 + ], + [ + 18.486, + 54.12173440987275 + ], + [ + 18.556, + 54.12173440987275 + ], + [ + 18.623, + 54.12173440987275 + ], + [ + 18.7, + 54.12173440987275 + ], + [ + 18.769, + 54.12173440987275 + ], + [ + 18.845, + 54.12173440987275 + ], + [ + 18.919, + 54.12173440987275 + ], + [ + 18.983, + 54.12173440987275 + ], + [ + 19.125, + 54.12173440987275 + ], + [ + 19.198, + 54.12173440987275 + ], + [ + 19.272, + 54.12173440987275 + ], + [ + 19.336, + 54.12173440987275 + ], + [ + 19.43, + 54.12173440987275 + ], + [ + 19.457, + 54.12173440987275 + ], + [ + 19.537, + 54.12173440987275 + ], + [ + 19.583, + 54.12173440987275 + ], + [ + 19.656, + 54.12173440987275 + ], + [ + 19.736, + 54.12173440987275 + ], + [ + 19.8, + 54.12173440987275 + ], + [ + 19.875, + 54.12173440987275 + ], + [ + 19.941, + 54.12173440987275 + ] + ], + "first_logged_projection_s": 13.713 + } +} diff --git a/integration/ptz17_focus_zoom/reference_replay.json b/integration/ptz17_focus_zoom/reference_replay.json new file mode 100644 index 0000000..5c1cfc1 --- /dev/null +++ b/integration/ptz17_focus_zoom/reference_replay.json @@ -0,0 +1,390 @@ +{ + "1412": { + "start_utc": "2026-11-13T07:12:02.328+00:00", + "status_samples": 257, + "first_send_s": 6.041, + "first_start_s": 6.115, + "first_confirmed_request": 3, + "first_optics_s": 10.627, + "startup_to_optics_s": 4.512, + "first_logged_projection_s": 9.869, + "first_request_projection_at_decision": "unknown", + "requests": [ + { + "request": 1, + "kind": "normal", + "seq": 5714, + "start_s": 6.115, + "nominal_s": 0.1, + "hard_limit_s": 0.12, + "final": { + "time_s": 6.231, + "status": "delivered_wait_optics", + "accounted_duration_s": 0.191, + "required_duration_s": 0.07, + "optics_at_finalize": false, + "reason": "priority_stop:watchdog" + }, + "explicit_confirmation_s": null, + "decisions": [], + "first_status_narrowing": null + }, + { + "request": 2, + "kind": "normal", + "seq": 5724, + "start_s": 7.766, + "nominal_s": 0.22, + "hard_limit_s": 0.28, + "final": { + "time_s": 8.086, + "status": "delivered_wait_optics", + "accounted_duration_s": 0.402, + "required_duration_s": 0.154, + "optics_at_finalize": false, + "reason": "priority_stop:watchdog" + }, + "explicit_confirmation_s": null, + "decisions": [], + "first_status_narrowing": null + }, + { + "request": 3, + "kind": "normal", + "seq": 5736, + "start_s": 10.164, + "nominal_s": 0.34, + "hard_limit_s": 0.4, + "final": { + "time_s": 10.496, + "status": "delivered_wait_optics", + "accounted_duration_s": 0.395, + "required_duration_s": 0.238, + "optics_at_finalize": false, + "reason": "physical_stop" + }, + "explicit_confirmation_s": 10.627, + "decisions": [ + { + "time_s": 10.481, + "reason": "recenter", + "blockers": "angle" + } + ], + "first_status_narrowing": { + "time_s": 10.627, + "hfov_deg": 54.12173440987275 + } + }, + { + "request": 4, + "kind": "normal", + "seq": 5757, + "start_s": 14.109, + "nominal_s": 0.1, + "hard_limit_s": 0.12, + "final": { + "time_s": 14.182, + "status": "discarded", + "accounted_duration_s": 0.147, + "required_duration_s": 0.07, + "optics_at_finalize": false, + "reason": "priority_stop:cancel_after_put" + }, + "explicit_confirmation_s": null, + "decisions": [ + { + "time_s": 14.055, + "reason": "recenter", + "blockers": "followup+angle+center_sample" + } + ], + "first_status_narrowing": null + }, + { + "request": 5, + "kind": "normal", + "seq": 5772, + "start_s": 16.382, + "nominal_s": 0.1, + "hard_limit_s": 0.12, + "final": { + "time_s": 16.419, + "status": "short", + "accounted_duration_s": 0.055, + "required_duration_s": 0.07, + "optics_at_finalize": false, + "reason": "physical_stop" + }, + "explicit_confirmation_s": null, + "decisions": [ + { + "time_s": 16.399, + "reason": "size_controller", + "blockers": "angle" + } + ], + "first_status_narrowing": null + }, + { + "request": 6, + "kind": "normal", + "seq": 5778, + "start_s": 17.247, + "nominal_s": 0.34, + "hard_limit_s": 0.4, + "final": { + "time_s": 17.445, + "status": "delivered_wait_optics", + "accounted_duration_s": 0.244, + "required_duration_s": 0.238, + "optics_at_finalize": false, + "reason": "physical_stop" + }, + "explicit_confirmation_s": null, + "decisions": [ + { + "time_s": 17.401, + "reason": "recenter", + "blockers": "angle" + }, + { + "time_s": 17.444, + "reason": "size_controller", + "blockers": "followup+angle+center_history+track_history" + } + ], + "first_status_narrowing": null + } + ] + }, + "1424": { + "start_utc": "2026-11-13T07:24:57.917+00:00", + "status_samples": 259, + "first_send_s": 8.054, + "first_start_s": 8.118, + "first_confirmed_request": 3, + "first_optics_s": 17.02, + "startup_to_optics_s": 8.902, + "first_logged_projection_s": 11.23, + "first_request_projection_at_decision": "unknown", + "requests": [ + { + "request": 1, + "kind": "normal", + "seq": 7515, + "start_s": 8.118, + "nominal_s": 0.1, + "hard_limit_s": 0.12, + "final": { + "time_s": 8.245, + "status": "delivered_wait_optics", + "accounted_duration_s": 0.192, + "required_duration_s": 0.07, + "optics_at_finalize": false, + "reason": "priority_stop:watchdog" + }, + "explicit_confirmation_s": null, + "decisions": [], + "first_status_narrowing": null + }, + { + "request": 2, + "kind": "normal", + "seq": 7536, + "start_s": 12.205, + "nominal_s": 0.22, + "hard_limit_s": 0.28, + "final": { + "time_s": 12.392, + "status": "delivered_wait_optics", + "accounted_duration_s": 0.248, + "required_duration_s": 0.154, + "optics_at_finalize": false, + "reason": "physical_stop" + }, + "explicit_confirmation_s": null, + "decisions": [ + { + "time_s": 12.379, + "reason": "recenter", + "blockers": "angle+center_sample" + } + ], + "first_status_narrowing": null + }, + { + "request": 3, + "kind": "normal", + "seq": 7556, + "start_s": 16.563, + "nominal_s": 0.34, + "hard_limit_s": 0.4, + "final": { + "time_s": 17.018, + "status": "delivered_wait_optics", + "accounted_duration_s": 0.47, + "required_duration_s": 0.238, + "optics_at_finalize": false, + "reason": "priority_stop:watchdog" + }, + "explicit_confirmation_s": 17.02, + "decisions": [], + "first_status_narrowing": { + "time_s": 17.02, + "hfov_deg": 54.12173440987275 + } + }, + { + "request": 4, + "kind": "normal", + "seq": 7572, + "start_s": 19.593, + "nominal_s": 0.34, + "hard_limit_s": 0.4, + "final": null, + "explicit_confirmation_s": null, + "decisions": [], + "first_status_narrowing": { + "time_s": 19.901, + "hfov_deg": 46.524147844879025 + } + } + ] + }, + "1428": { + "start_utc": "2026-11-13T07:28:06.389+00:00", + "status_samples": 253, + "first_send_s": 4.227, + "first_start_s": 4.294, + "first_confirmed_request": 5, + "first_optics_s": 16.985, + "startup_to_optics_s": 12.691, + "first_logged_projection_s": 13.713, + "first_request_projection_at_decision": "unknown", + "requests": [ + { + "request": 1, + "kind": "normal", + "seq": 8125, + "start_s": 4.294, + "nominal_s": 0.1, + "hard_limit_s": 0.12, + "final": { + "time_s": 4.399, + "status": "discarded", + "accounted_duration_s": 0.172, + "required_duration_s": 0.07, + "optics_at_finalize": false, + "reason": "priority_stop:cancel_after_put" + }, + "explicit_confirmation_s": null, + "decisions": [ + { + "time_s": 4.235, + "reason": "image_motion", + "blockers": "-" + } + ], + "first_status_narrowing": null + }, + { + "request": 2, + "kind": "probe", + "seq": 8137, + "start_s": 6.302, + "nominal_s": 0.1, + "hard_limit_s": 0.12, + "final": { + "time_s": 6.448, + "status": "discarded", + "accounted_duration_s": 0.208, + "required_duration_s": 0.07, + "optics_at_finalize": false, + "reason": "priority_stop:watchdog" + }, + "explicit_confirmation_s": null, + "decisions": [], + "first_status_narrowing": null + }, + { + "request": 3, + "kind": "probe", + "seq": 8157, + "start_s": 10.195, + "nominal_s": 0.1, + "hard_limit_s": 0.12, + "final": { + "time_s": 10.365, + "status": "delivered_wait_optics", + "accounted_duration_s": 0.208, + "required_duration_s": 0.07, + "optics_at_finalize": false, + "reason": "priority_stop:watchdog" + }, + "explicit_confirmation_s": null, + "decisions": [ + { + "time_s": 10.261, + "reason": "size_controller", + "blockers": "angle" + } + ], + "first_status_narrowing": null + }, + { + "request": 4, + "kind": "normal", + "seq": 8178, + "start_s": 14.181, + "nominal_s": 0.22, + "hard_limit_s": 0.28, + "final": { + "time_s": 14.273, + "status": "discarded", + "accounted_duration_s": 0.121, + "required_duration_s": 0.154, + "optics_at_finalize": false, + "reason": "priority_stop:cancel_after_put" + }, + "explicit_confirmation_s": null, + "decisions": [ + { + "time_s": 14.158, + "reason": "recenter", + "blockers": "angle+center_sample" + } + ], + "first_status_narrowing": null + }, + { + "request": 5, + "kind": "normal", + "seq": 8194, + "start_s": 16.639, + "nominal_s": 0.22, + "hard_limit_s": 0.28, + "final": { + "time_s": 16.942, + "status": "delivered_wait_optics", + "accounted_duration_s": 0.314, + "required_duration_s": 0.154, + "optics_at_finalize": false, + "reason": "priority_stop:watchdog" + }, + "explicit_confirmation_s": 16.985, + "decisions": [ + { + "time_s": 16.894, + "reason": "size_controller", + "blockers": "angle" + } + ], + "first_status_narrowing": { + "time_s": 16.986, + "hfov_deg": 54.12173440987275 + } + } + ] + } +} diff --git a/integration/ptz17_focus_zoom/replay_ptz17_reference.py b/integration/ptz17_focus_zoom/replay_ptz17_reference.py new file mode 100644 index 0000000..f89d775 --- /dev/null +++ b/integration/ptz17_focus_zoom/replay_ptz17_reference.py @@ -0,0 +1,135 @@ +"""Replay recorded PTZ17 lens transactions and their fresh HFOV samples.""" +from __future__ import annotations + +import argparse +from dataclasses import asdict, dataclass +import json +import math +from pathlib import Path +import re +from typing import Any + + +WINDOW_S = 20.0 +MIN_HFOV_CHANGE_RATIO = 0.004 +MAX_STATUS_AGE_S = 0.65 +MIN_PROJECTION_MARGIN = 0.16 +EPISODES = ("1412", "1424", "1428") +START = re.compile(r"request=(\d+) kind=(\w+) physical start seq=(\d+) pulse=([.\d]+)s hard=([.\d]+)s") +RESULT = re.compile(r"request=(\d+) result=(\w+) duration=([.\d]+)s min=([.\d]+)s optics=(True|False) reason=(\S+)") +DECISION = re.compile(r"request=(\d+).*?reason=(\S+) blockers=(\S+)") +CONFIRMED = re.compile(r"request=(\d+) optics confirmed\b") + + +@dataclass(frozen=True, slots=True) +class LensSample: + time_s: float + hfov_deg: float + + +def first_hfov_change( + baseline: LensSample, samples: list[LensSample], *, from_s: float, until_s: float, +) -> LensSample | None: + """Return the first fresh HFOV narrowing of at least 0.4 percent.""" + return next(( + sample for sample in samples + if math.isfinite(sample.time_s) and math.isfinite(sample.hfov_deg) + and 0.0 < sample.hfov_deg < 180.0 + and from_s <= sample.time_s < until_s and sample.time_s > baseline.time_s + and (baseline.hfov_deg - sample.hfov_deg) / baseline.hfov_deg >= MIN_HFOV_CHANGE_RATIO + ), None) + + +def make_fixture(path: Path) -> dict[str, Any]: + report = json.loads(path.read_bytes()) + assert report["status"] == "checked" + detail = report["detail"] + assert detail["covers"] + rows = detail["rows"] + own_status = [value["early_status"] for value in detail["telemetry"].values() if value["early_status"]] + assert len(own_status) == 1 + keys = ("[ZOOM DELIVERY]", "[ZOOM DECISION]") + return { + "start_utc": report["start"], + "initial_send_s": detail["axis_commands"]["first"][0][0], + "rows": {key: [row for row in rows.get(key, []) if 0.0 <= row[0] <= WINDOW_S] for key in keys}, + "status": own_status[0], + "first_logged_projection_s": next( + (t for t, row in rows.get("[AIM]", []) if 0.0 <= t <= WINDOW_S + and float(row.get("approach_margin", -1.0)) >= MIN_PROJECTION_MARGIN), None, + ), + } + + +def replay(episode: dict[str, Any]) -> dict[str, Any]: + samples = [LensSample(*row) for row in episode["status"]] + assert all(math.isfinite(s.time_s) and 0.0 < s.hfov_deg < 180.0 for s in samples) + assert samples and samples == sorted(samples, key=lambda sample: sample.time_s) + requests: dict[int, dict[str, Any]] = {} + for time_s, line in episode["rows"]["[ZOOM DELIVERY]"]: + if match := START.search(line): + request_id, kind, seq, pulse, hard = match.groups() + assert int(request_id) not in requests + requests[int(request_id)] = dict( + request=int(request_id), kind=kind, seq=int(seq), start_s=time_s, + nominal_s=float(pulse), hard_limit_s=float(hard), final=None, + explicit_confirmation_s=None, decisions=[], + ) + elif match := RESULT.search(line): + request_id, status, duration, minimum, optics, reason = match.groups() + request = requests[int(request_id)] + assert request["final"] is None + request["final"] = dict( + time_s=time_s, status=status, accounted_duration_s=float(duration), + required_duration_s=float(minimum), optics_at_finalize=optics == "True", reason=reason, + ) + elif match := CONFIRMED.search(line): + requests[int(match[1])]["explicit_confirmation_s"] = time_s + for time_s, line in episode["rows"]["[ZOOM DECISION]"]: + if (match := DECISION.search(line)) and int(match[1]) in requests: + requests[int(match[1])]["decisions"].append(dict(time_s=time_s, reason=match[2], blockers=match[3])) + + ordered = list(requests.values()) + for index, request in enumerate(ordered): + start_s = request["start_s"] + assert 0.0 < request["nominal_s"] <= request["hard_limit_s"] <= 0.4 + until_s = ordered[index + 1]["start_s"] if index + 1 < len(ordered) else math.nextafter(WINDOW_S, math.inf) + baseline = next((s for s in reversed(samples) if s.time_s < start_s), None) + measured = None + if baseline is not None and start_s - baseline.time_s <= MAX_STATUS_AGE_S: + measured = first_hfov_change(baseline, samples, from_s=start_s, until_s=until_s) + request["first_status_narrowing"] = asdict(measured) if measured is not None else None + final = request["final"] + if final is not None and final["status"] == "confirmed" and request["explicit_confirmation_s"] is None: + request["explicit_confirmation_s"] = final["time_s"] + first_confirmed = next((row for row in ordered if row["explicit_confirmation_s"] is not None), None) + first_s = ordered[0]["start_s"] if ordered else None + confirm_s = first_confirmed["explicit_confirmation_s"] if first_confirmed else None + return dict( + start_utc=episode["start_utc"], status_samples=len(samples), + first_send_s=episode["initial_send_s"], first_start_s=first_s, + first_confirmed_request=first_confirmed["request"] if first_confirmed else None, + first_optics_s=confirm_s, + startup_to_optics_s=round(confirm_s - first_s, 3) if confirm_s is not None else None, + first_logged_projection_s=episode["first_logged_projection_s"], + first_request_projection_at_decision="unknown", + requests=ordered, + ) + + +def main() -> None: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--session", type=Path, help="Build the fixture from the three bounded observer reports") + parser.add_argument("--fixture", type=Path, default=Path(__file__).with_name("reference_fixture.json")) + parser.add_argument("--output", type=Path, default=Path(__file__).with_name("reference_replay.json")) + args = parser.parse_args() + if args.session: + fixture = {key: make_fixture(args.session / f"ref_{key}.json") for key in EPISODES} + args.fixture.write_text(json.dumps(fixture, indent=2) + "\n", encoding="utf-8") + fixture = json.loads(args.fixture.read_bytes()) + result = {key: replay(value) for key, value in fixture.items()} + args.output.write_text(json.dumps(result, indent=2) + "\n", encoding="utf-8") + + +if __name__ == "__main__": + main() diff --git a/integration/ptz17_focus_zoom/server.patch b/integration/ptz17_focus_zoom/server.patch index c93aac9..209df9f 100644 --- a/integration/ptz17_focus_zoom/server.patch +++ b/integration/ptz17_focus_zoom/server.patch @@ -18,7 +18,7 @@ cx = (x1 + x2) * 0.5 cy = (y1 + y2) * 0.5 roi_w = max(16.0, (x2 - x1) * scale) -@@ -741,6 +743,106 @@ +@@ -741,6 +743,141 @@ return score if math.isfinite(score) else None @@ -27,6 +27,9 @@ + focus_max_hfov_deg: float = 18.0 + focus_min_side_px: int = 20 + focus_core_only_threshold_scale: float = 8.0 ++ focus_unknown_retry_s: float = 0.60 ++ focus_unknown_max_gap_s: float = 0.25 ++ focus_recovery_samples: int = 2 + frame_max_age_s: float = 0.25 + detector_max_age_s: float = 0.65 + first_pulse_s: float = 0.34 @@ -58,28 +61,41 @@ + + +def _ptz17_focus_hold( -+ st: dict, *, hfov_deg: float, side_px: int, frame_is_current: bool, ++ st: dict, *, hfov_deg: float, side_px: int, frame_is_current: bool, captured_at: float, +) -> str | None: + """Keep the lens at its current FOV while the settled target is blurry.""" + owner = visual_control.owner(st) + if owner[2] <= 0.0 or not 0.0 < hfov_deg <= _PTZ17_ZOOM.focus_max_hfov_deg: + st.pop("ptz17_focus_hold", None) ++ st.pop("ptz17_focus_recovery", None) + return None + previous = st.get("ptz17_focus_hold") + reason = previous[1] if previous is not None and previous[0] == owner else None -+ if not frame_is_current: ++ if not frame_is_current or not math.isfinite(captured_at): + return reason + focus_state = st.get("focus_state") + if focus_state == "disabled": + reason = None + elif side_px >= _PTZ17_ZOOM.focus_min_side_px: -+ if focus_state == "sharp": -+ reason = None ++ if focus_state == "sharp" and reason is not None: ++ recovery = st.get("ptz17_focus_recovery") ++ votes = 1 ++ if recovery is not None and recovery[0] == owner: ++ gap_s = captured_at - recovery[1] ++ if gap_s <= 0.0: ++ return reason ++ if gap_s <= _PTZ17_ZOOM.focus_unknown_max_gap_s: ++ votes += recovery[2] ++ st["ptz17_focus_recovery"] = (owner, captured_at, votes) ++ if votes >= _PTZ17_ZOOM.focus_recovery_samples: ++ reason = None + elif focus_state in { + "blur_suspected", "blur_fast_suspected", "blur_cooldown", "blur_wait", + "unassessable", "requested", "settling", + }: + reason = str(focus_state) ++ if focus_state != "sharp" or side_px < _PTZ17_ZOOM.focus_min_side_px or reason is None: ++ st.pop("ptz17_focus_recovery", None) + if reason is not None: + st["ptz17_focus_hold"] = (owner, reason) + else: @@ -87,6 +103,25 @@ + return reason + + ++def _ptz17_unassessable_retry_ready(st: dict, captured_at: float) -> bool: ++ """Authorize one recovery attempt per track owner after sustained low contrast.""" ++ owner = visual_control.owner(st) ++ evidence = st.get("ptz17_focus_unknown") ++ if owner[2] <= 0.0 or not math.isfinite(captured_at): ++ return False ++ if evidence is None or evidence[0] != owner: ++ st["ptz17_focus_unknown"] = (owner, captured_at, captured_at) ++ return False ++ if st.get("ptz17_focus_unknown_attempt") == owner: ++ return False ++ gap_s = captured_at - evidence[2] ++ if gap_s <= 0.0: ++ return False ++ since = captured_at if gap_s > _PTZ17_ZOOM.focus_unknown_max_gap_s else evidence[1] ++ st["ptz17_focus_unknown"] = (owner, since, captured_at) ++ return captured_at - since >= _PTZ17_ZOOM.focus_unknown_retry_s ++ ++ +def _ptz17_first_useful_timing( + st: dict, timing: tuple[float, float], *, native: int, normal_onset: bool, + frame_age_s: float, detector_age_s: float, hfov_deg: float, wide_hfov_deg: float, @@ -125,7 +160,15 @@ def _clear_focus_low_evidence(st: dict) -> None: st["focus_quality_low_frames"] = 0 st["focus_quality_low_since"] = None -@@ -833,7 +935,11 @@ +@@ -761,6 +898,7 @@ + center_err: float, + hfov_deg: float, + validation_age: float, ++ allow_unassessable_retry: bool = False, + ) -> bool: + """Measure settled target detail and queue one bounded autofocus request.""" + if not bool(getattr(config, "AUTOFOCUS_QUALITY_ENABLE", True)) or not bool( +@@ -833,14 +971,31 @@ _clear_focus_low_evidence(st) st["focus_last_hfov_deg"] = float(hfov_deg) @@ -137,8 +180,90 @@ + ) st["focus_quality_last_eval_at"] = float(now) st["focus_quality_score"] = score ++ unknown_retry = False if score is None: -@@ -9537,6 +9643,47 @@ + st["focus_state"] = "unassessable" + _clear_focus_low_evidence(st) +- return False +- ++ unknown_retry = ( ++ allow_unassessable_retry and cam_idx == _PTZ17_CAM_IDX ++ and 0.0 < hfov_deg <= _PTZ17_ZOOM.focus_max_hfov_deg ++ and 0.0 <= validation_age <= _PTZ17_ZOOM.detector_max_age_s ++ and _ptz17_unassessable_retry_ready(st, now) ++ ) ++ if not unknown_retry: ++ return False ++ else: ++ st.pop("ptz17_focus_unknown", None) ++ ++ if unknown_retry: ++ return _queue_focus_recovery(cam_idx, st, now, reason="unassessable") ++ assert score is not None + alpha = clipf(float(getattr(config, "AUTOFOCUS_SCORE_EMA_ALPHA", 0.35)), 0.01, 1.0) + previous_ema = st.get("focus_quality_ema") + ema = float(score) if not isinstance(previous_ema, (int, float)) else ( +@@ -870,7 +1025,10 @@ + if ema >= threshold: + # Keep the independent raw-drop evidence while the deliberately slow + # EMA still describes the previously sharp scene. +- st["focus_state"] = "blur_fast_suspected" if raw_drop else "sharp" ++ ptz17_instant_low = ( ++ allow_unassessable_retry and cam_idx == _PTZ17_CAM_IDX and score < threshold ++ ) ++ st["focus_state"] = "blur_fast_suspected" if raw_drop or ptz17_instant_low else "sharp" + st["focus_quality_low_frames"] = 0 + st["focus_quality_low_since"] = None + else: +@@ -916,12 +1074,19 @@ + if not confirmed_low: + return False + ++ return _queue_focus_recovery(cam_idx, st, now, reason="quality", score=score, ema=ema) ++ ++ ++def _queue_focus_recovery( ++ cam_idx: int, st: dict, now: float, *, reason: str, ++ score: float | None = None, ema: float | None = None, ++) -> bool: + request_cd = max(0.5, float(getattr(config, "AUTOFOCUS_REQUEST_COOLDOWN_SEC", 15.0))) + last_request = float(st.get("focus_last_request_at", 0.0) or 0.0) + if last_request > 0.0 and (float(now) - last_request) < request_cd: + st["focus_state"] = "blur_cooldown" + return False +- if not bool(call_autofocus(cam_idx, reason="quality")): ++ if not bool(call_autofocus(cam_idx, reason=reason)): + if str(st.get("focus_state", "")) not in { + "unsupported", + "unsupported_backoff", +@@ -931,6 +1096,8 @@ + st["focus_state"] = "blur_wait" + return False + ++ if reason == "unassessable": ++ st["ptz17_focus_unknown_attempt"] = visual_control.owner(st) + st["focus_state"] = "requested" + st["focus_last_request_at"] = float(now) + st["focus_settle_until"] = float(now) + max( +@@ -938,12 +1105,11 @@ + float(getattr(config, "AUTOFOCUS_SETTLE_HOLD_SEC", 0.80)), + ) + _clear_focus_low_evidence(st) +- logger.warning( +- "[FOCUS/QUALITY] cam=%s autofocus requested score=%.1f ema=%.1f", +- cam_idx, +- float(score), +- float(ema), +- ) ++ if score is not None and ema is not None: ++ logger.warning("[FOCUS/QUALITY] cam=%s autofocus requested score=%.1f ema=%.1f", ++ cam_idx, score, ema) ++ else: ++ logger.warning("[FOCUS/QUALITY] cam=%s autofocus requested reason=%s", cam_idx, reason) + return True + + +@@ -9537,6 +9703,48 @@ max(0.0, float(getattr(config, min_key, 0.10))), ) zoom_cmd = min(max_effective, max(float(zoom_cmd), min_effective)) @@ -163,6 +288,7 @@ + tilt_cmd=float(tilt_speed) + float(tilt_rate_ff), + zoom_cmd=0.0, center_err=float(center_err), hfov_deg=float(hfov_deg), + validation_age=float(visual_control_validation_age), ++ allow_unassessable_retry=True, + ) + ptz17_focus_checked = True + # A small but measurable crop can veto another zoom step. @@ -178,7 +304,7 @@ + ) + ptz17_focus_reason = _ptz17_focus_hold( + st, hfov_deg=float(hfov_deg), side_px=min(x2 - x1, y2 - y1), -+ frame_is_current=ptz17_focus_checked, ++ frame_is_current=ptz17_focus_checked, captured_at=float(now), + ) + if ptz17_focus_reason is not None and zoom_cmd > 0.0: + zoom_cmd = 0.0 @@ -186,7 +312,7 @@ if probe_start_candidate and identify_start_candidate: pulse_kind = "probe_identify" elif probe_start_candidate: -@@ -9645,6 +9792,27 @@ +@@ -9645,6 +9853,27 @@ zoom_cmd = 0.0 st["zoom_useful_pulse_reason"] = "wait_response_framing" zoom_zero_reason = "response_framing" @@ -214,7 +340,7 @@ gate_stop = [] if decision_request else None continuation_trace = [] if decision_request else None zoom_cmd = _gate_zoom_in_pulse( -@@ -9667,6 +9835,9 @@ +@@ -9667,6 +9896,9 @@ ) if predictive_start and zoom_cmd > 0.0 and st["zoom_step_request_id"] > request_id_before_gate: st["predictive_zoom_request"] = st["zoom_step_pending_id"] @@ -224,7 +350,7 @@ if gate_stop: zoom_zero_reason = gate_stop[-1] decision_generation = st.get("ptz_generation") -@@ -9693,23 +9864,24 @@ +@@ -9693,23 +9925,24 @@ elif zoom_cmd < 0.0 and float(size_est) <= max(0.05, zoomed_size_thr * 0.75): st["was_zoomed_in"] = False @@ -266,7 +392,7 @@ st["fallback_done"] = False -@@ -10222,6 +10394,8 @@ +@@ -10222,6 +10455,8 @@ if getattr(config, "PREDICTIVE_ZOOM_TELEMETRY_DIR", "logs/ptz_zoom"): blocked = {} if zoom_cmd <= 0.0 and raw_zoom_needed: diff --git a/integration/ptz17_focus_zoom/test_reference_replay.py b/integration/ptz17_focus_zoom/test_reference_replay.py new file mode 100644 index 0000000..b83ffab --- /dev/null +++ b/integration/ptz17_focus_zoom/test_reference_replay.py @@ -0,0 +1,30 @@ +from pathlib import Path +import json + +import pytest + +from replay_ptz17_reference import LensSample, first_hfov_change, replay + + +@pytest.mark.parametrize("key,start,request_id,confirmation,delay", [ + ("1412", 6.115, 3, 10.627, 4.512), + ("1424", 8.118, 3, 17.020, 8.902), + ("1428", 4.294, 5, 16.985, 12.691), +]) +def test_replays_observed_first_optics( + key: str, start: float, request_id: int, confirmation: float, delay: float, +) -> None: + fixture = json.loads(Path(__file__).with_name("reference_fixture.json").read_bytes()) + result = replay(fixture[key]) + assert result["first_start_s"] == start + assert result["first_confirmed_request"] == request_id + assert result["first_optics_s"] == confirmation and result["startup_to_optics_s"] == delay + assert all(row["first_status_narrowing"] is None for row in result["requests"][:request_id - 1]) + assert result["requests"][request_id - 1]["first_status_narrowing"]["hfov_deg"] == pytest.approx(54.122, abs=.001) + + +def test_measurement_does_not_cross_request_boundary() -> None: + assert first_hfov_change( + LensSample(1., 59.), [LensSample(1.1, float("nan")), LensSample(1.2, 58.9), LensSample(1.3, 54.)], + from_s=1.1, until_s=1.3, + ) is None -- 2.17.1 From f90c7da6829a521bf41ede7ba1b5e14c9835773a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=AF=D1=80=D0=BE=D1=81=D0=BB=D0=B0=D0=B2=20=D0=9A=D0=B0?= =?UTF-8?q?=D1=80=D1=82=D0=B0=D1=88=D0=BE=D0=B2?= Date: Fri, 13 Nov 2026 14:48:01 +0700 Subject: [PATCH 4/5] Log PTZ17 zoom decisions and focus evidence per frame --- integration/ptz17_focus_zoom/README.md | 2 + integration/ptz17_focus_zoom/pins.json | 4 +- integration/ptz17_focus_zoom/server.patch | 104 +++++++++++++++++++--- 3 files changed, 96 insertions(+), 14 deletions(-) diff --git a/integration/ptz17_focus_zoom/README.md b/integration/ptz17_focus_zoom/README.md index 9960ad2..607a02b 100644 --- a/integration/ptz17_focus_zoom/README.md +++ b/integration/ptz17_focus_zoom/README.md @@ -29,6 +29,8 @@ ## Воспроизводимый эталон первых 20 секунд +Для полевого сравнения PR №14 пишет `decision_frame` только для PTZ17 через существующую ограниченную асинхронную очередь. Событие связывает номер и время кадра с состоянием проверки, полем зрения, оценкой резкости, запросом зума, длительностью и итоговой командой. Ненулевые команды и идентификаторы проверяются по журналу доставки и замерам оптики. Для первого резкого кадра учитывается только измерение с текущего кадра и размер рамки от 20 px. Эталон предыдущей версии располагает лишь редкими строками оценки резкости и выборочными JPEG. + `replay_ptz17_reference.py` читает зафиксированные команды, завершения запросов и выборки свежего HFOV из `reference_fixture.json`. Запуск `python replay_ptz17_reference.py` восстанавливает `reference_replay.json`. В журнале время подтверждения и первое наблюдаемое изменение HFOV могут отличаться из-за округления меток и порядка записи. Время измеримого сужения определяется отдельно от подтверждения конкретного запроса. | TRACK, UTC+7 | Первый старт → первое подтверждение | Первый подтверждённый запрос | Свежие замеры HFOV за 20 с | diff --git a/integration/ptz17_focus_zoom/pins.json b/integration/ptz17_focus_zoom/pins.json index ba5c24c..4a896fa 100644 --- a/integration/ptz17_focus_zoom/pins.json +++ b/integration/ptz17_focus_zoom/pins.json @@ -1,6 +1,6 @@ { "base_sha256": "6cf484271ef3659028b0b4d43041addb05102f91d2758ab472d968a52d24e911", - "candidate_sha256": "26edb69b9d0bd0ae6ad4b9c18ff2f793bcb2a2cf035b38293a3e07d6fc833f8b", - "patch_sha256": "6a563f751871dcadc3c4daf730cc3cfb1ff6fd8edf1f379a2cee01f99302d4de", + "candidate_sha256": "fc0deb0c54fbd94a916493ee0c3159b02407876b32deebbbc3d819cc58a17500", + "patch_sha256": "e4a03e3dd4cd0f99995bc37acab29d063553cb32966fb13bdd93a46b8f7c5a9f", "installed": false } diff --git a/integration/ptz17_focus_zoom/server.patch b/integration/ptz17_focus_zoom/server.patch index 209df9f..b1ac814 100644 --- a/integration/ptz17_focus_zoom/server.patch +++ b/integration/ptz17_focus_zoom/server.patch @@ -1,5 +1,14 @@ --- a/postprocess.py +++ b/postprocess.py +@@ -12,7 +12,7 @@ + + from . import config, state, visual_control + from .zoom_controller import ( +- ZoomFrame, controller_for_track, expire_calibration, flush_zoom_blocks, record_zoom_blocks, telemetry_tick, ++ ZoomFrame, _episode_telemetry, controller_for_track, expire_calibration, flush_zoom_blocks, record_zoom_blocks, telemetry_tick, + ) + from . import motion_detector + from .utils import ( @@ -690,6 +690,8 @@ def _focus_quality_score( frame_bgr: np.ndarray, @@ -18,7 +27,7 @@ cx = (x1 + x2) * 0.5 cy = (y1 + y2) * 0.5 roi_w = max(16.0, (x2 - x1) * scale) -@@ -741,6 +743,141 @@ +@@ -741,6 +743,154 @@ return score if math.isfinite(score) else None @@ -44,6 +53,19 @@ +_PTZ17_ZOOM = _PTZ17ZoomTuning() + + ++def _record_ptz17_decision(st: dict, at: float, **fields: Any) -> None: ++ """Publish decision metadata to the existing bounded asynchronous queue.""" ++ generation, started_at = visual_control.owner(st)[1:3] ++ if started_at <= 0.0 or not math.isfinite(started_at): ++ return ++ values = { ++ key: None if isinstance(value, float) and not math.isfinite(value) else value ++ for key, value in fields.items() ++ } ++ _episode_telemetry(config, _PTZ17_CAM_IDX, (generation, started_at), ++ "decision_frame", at, **values) ++ ++ +def _ptz17_target_focus_score( + frame_bgr: np.ndarray, bbox: tuple[int, int, int, int] | list[int], +) -> float | None: @@ -160,7 +182,7 @@ def _clear_focus_low_evidence(st: dict) -> None: st["focus_quality_low_frames"] = 0 st["focus_quality_low_since"] = None -@@ -761,6 +898,7 @@ +@@ -761,6 +911,7 @@ center_err: float, hfov_deg: float, validation_age: float, @@ -168,7 +190,7 @@ ) -> bool: """Measure settled target detail and queue one bounded autofocus request.""" if not bool(getattr(config, "AUTOFOCUS_QUALITY_ENABLE", True)) or not bool( -@@ -833,14 +971,31 @@ +@@ -833,14 +984,31 @@ _clear_focus_low_evidence(st) st["focus_last_hfov_deg"] = float(hfov_deg) @@ -203,7 +225,7 @@ alpha = clipf(float(getattr(config, "AUTOFOCUS_SCORE_EMA_ALPHA", 0.35)), 0.01, 1.0) previous_ema = st.get("focus_quality_ema") ema = float(score) if not isinstance(previous_ema, (int, float)) else ( -@@ -870,7 +1025,10 @@ +@@ -870,7 +1038,10 @@ if ema >= threshold: # Keep the independent raw-drop evidence while the deliberately slow # EMA still describes the previously sharp scene. @@ -215,7 +237,7 @@ st["focus_quality_low_frames"] = 0 st["focus_quality_low_since"] = None else: -@@ -916,12 +1074,19 @@ +@@ -916,12 +1087,19 @@ if not confirmed_low: return False @@ -236,7 +258,7 @@ if str(st.get("focus_state", "")) not in { "unsupported", "unsupported_backoff", -@@ -931,6 +1096,8 @@ +@@ -931,6 +1109,8 @@ st["focus_state"] = "blur_wait" return False @@ -245,7 +267,7 @@ st["focus_state"] = "requested" st["focus_last_request_at"] = float(now) st["focus_settle_until"] = float(now) + max( -@@ -938,12 +1105,11 @@ +@@ -938,12 +1118,11 @@ float(getattr(config, "AUTOFOCUS_SETTLE_HOLD_SEC", 0.80)), ) _clear_focus_low_evidence(st) @@ -263,7 +285,7 @@ return True -@@ -9537,6 +9703,48 @@ +@@ -9537,6 +9716,50 @@ max(0.0, float(getattr(config, min_key, 0.10))), ) zoom_cmd = min(max_effective, max(float(zoom_cmd), min_effective)) @@ -297,6 +319,8 @@ + and min(x2 - x1, y2 - y1) >= _PTZ17_ZOOM.focus_min_side_px + and 0.0 <= visual_control_validation_age <= _PTZ17_ZOOM.detector_max_age_s): + target_score = _ptz17_target_focus_score(frame_bgr, (x1, y1, x2, y2)) ++ st["ptz17_small_focus_at"] = now ++ st["focus_quality_score"] = target_score + threshold = float(getattr(config, "AUTOFOCUS_BLUR_THRESHOLD", 35.0)) + st["focus_state"] = ( + "unassessable" if target_score is None else @@ -312,7 +336,7 @@ if probe_start_candidate and identify_start_candidate: pulse_kind = "probe_identify" elif probe_start_candidate: -@@ -9645,6 +9853,27 @@ +@@ -9645,8 +9868,30 @@ zoom_cmd = 0.0 st["zoom_useful_pulse_reason"] = "wait_response_framing" zoom_zero_reason = "response_framing" @@ -339,8 +363,11 @@ + ptz17_timing_changed = response_timing != original_response_timing gate_stop = [] if decision_request else None continuation_trace = [] if decision_request else None ++ ptz17_zoom_before_gate = float(zoom_cmd) if cam_idx == _PTZ17_CAM_IDX else None zoom_cmd = _gate_zoom_in_pulse( -@@ -9667,6 +9896,9 @@ + st, + # Keep new-request expiry tied to the frame that authorized +@@ -9667,9 +9912,15 @@ ) if predictive_start and zoom_cmd > 0.0 and st["zoom_step_request_id"] > request_id_before_gate: st["predictive_zoom_request"] = st["zoom_step_pending_id"] @@ -350,7 +377,13 @@ if gate_stop: zoom_zero_reason = gate_stop[-1] decision_generation = st.get("ptz_generation") -@@ -9693,23 +9925,24 @@ ++ ptz17_request_after_gate = ( ++ int(st.get("zoom_step_pending_id", 0) or 0) if cam_idx == _PTZ17_CAM_IDX else 0 ++ ) + if ( + probe_start_candidate + and zoom_cmd > 0.0 +@@ -9693,23 +9944,24 @@ elif zoom_cmd < 0.0 and float(size_est) <= max(0.05, zoomed_size_thr * 0.75): st["was_zoomed_in"] = False @@ -392,7 +425,54 @@ st["fallback_done"] = False -@@ -10222,6 +10455,8 @@ +@@ -10191,7 +10443,7 @@ + stop_ptz(cam_idx, source='stop', generation=int(st.get('ptz_generation', 0) or 0)) + return + zoom_decision = None +- if decision_request and zoom_cmd <= 0.0: ++ if (decision_request or cam_idx == _PTZ17_CAM_IDX) and zoom_cmd <= 0.0: + blockers = tuple(name for name, blocked in ( + ("quality", not zoom_quality_ok), + ("framing", not zoom_safe), +@@ -10210,7 +10462,36 @@ + ("stale", visual_control_stale), + ("brake", final_guard_active), + ) if blocked) +- zoom_decision = (source_seq, decision_request, zoom_zero_reason, "+".join(blockers) or "-") ++ if decision_request: ++ zoom_decision = (source_seq, decision_request, zoom_zero_reason, "+".join(blockers) or "-") ++ if (cam_idx == _PTZ17_CAM_IDX and st.get("mode") == "TRACK" ++ and st.get("tracking_active") and source_seq is not None ++ and int(source_seq) > 0): ++ _record_ptz17_decision( ++ st, time.time(), frame_seq=int(source_seq), frame_utc=float(now), ++ frame_age_at_gate_s=zoom_gate_now - now, source=current_track_source, ++ bbox_px=[int(x1), int(y1), int(x2), int(y2)], ++ detector_age_at_gate_s=zoom_gate_now - last_visual_zoom_validation, ++ detector_conf=float(st.get("visual_tracker_last_detector_conf", 0.0) or 0.0), ++ tracker_score=float(st.get("visual_tracker_score", 0.0) or 0.0), ++ hfov_deg=float(hfov_deg), optics_age_s=float(optics_age), ++ center_error_norm=max(abs(float(measured_dx)), abs(float(measured_dy))), ++ edge_margin_norm=float(edge_risk_margin), approach_margin_norm=approach_margin, ++ image_rate_norm_s=max(float(vel), float(fast_drift)), ++ zoom_requested=bool(raw_zoom_needed), zoom_before_gate=ptz17_zoom_before_gate, ++ zoom_command=float(zoom_cmd), proposed_native=int(timing_native), ++ reason=zoom_zero_reason if zoom_cmd <= 0.0 else "positive_command", ++ blockers=list(blockers) if zoom_cmd <= 0.0 else [], ++ pulse_kind=str(pulse_kind), nominal_s=float(response_timing[0]), ++ hard_limit_s=float(response_timing[1]), timing_profile_changed=ptz17_timing_changed, ++ request_before_gate=decision_request, request_after_gate=ptz17_request_after_gate, ++ request_created=bool(ptz17_request_after_gate > request_id_before_gate), ++ focus_state=st.get("focus_state"), focus_hold=ptz17_focus_reason, ++ focus_sample_current=bool(st.get("focus_quality_last_eval_at") == now or ( ++ ptz17_focus_checked and st.get("ptz17_small_focus_at") == now ++ )), ++ focus_score=st.get("focus_quality_score"), ++ ) + if predictive_decision is not None: + with _zoom_command_lock(cam_idx): + telemetry_tick( +@@ -10222,6 +10503,8 @@ if getattr(config, "PREDICTIVE_ZOOM_TELEMETRY_DIR", "logs/ptz_zoom"): blocked = {} if zoom_cmd <= 0.0 and raw_zoom_needed: -- 2.17.1 From c74c8fb82f17a6f9b78d327cef3d4e788e240e74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=AF=D1=80=D0=BE=D1=81=D0=BB=D0=B0=D0=B2=20=D0=9A=D0=B0?= =?UTF-8?q?=D1=80=D1=82=D0=B0=D1=88=D0=BE=D0=B2?= Date: Mon, 16 Nov 2026 12:31:35 +0700 Subject: [PATCH 5/5] Record PTZ17 HOLD and reacquisition frame evidence --- integration/ptz17_focus_zoom/README.md | 10 + integration/ptz17_focus_zoom/pins.json | 4 +- integration/ptz17_focus_zoom/server.patch | 331 +++++++++++++++++- .../test_recovery_telemetry.py | 231 ++++++++++++ 4 files changed, 558 insertions(+), 18 deletions(-) create mode 100644 integration/ptz17_focus_zoom/test_recovery_telemetry.py diff --git a/integration/ptz17_focus_zoom/README.md b/integration/ptz17_focus_zoom/README.md index 607a02b..9411b26 100644 --- a/integration/ptz17_focus_zoom/README.md +++ b/integration/ptz17_focus_zoom/README.md @@ -1,5 +1,15 @@ # PTZ17 · зум и контроль резкости +## Диагностика HOLD и повторного захвата + +Событие `recovery_frame` в очереди JSONL PTZ17 связывает причину отказа или восстановления с поколением трека, номером кадра, временем наблюдения и размером изображения обработки. Координаты `xyxy` отсчитываются от левого верхнего угла. Для промежуточного OSTrack и привязанного к нему YOLO время наблюдения соответствует получению декодированного кадра. Для отдельного детекторного прохода оно соответствует входу в обработчик. Поле `input_kind` различает эти источники. Номера кадров OSTrack и управляющего прохода записываются отдельно. + +Телеметрия содержит последнюю принятую рамку, опору сопоставления, рамку и оценку OSTrack, кандидатов YOLO с оценками и классами, результат сопоставления, выбранную рамку и результат переинициализации. Записываются счётчики голосов повторного захвата и разрешения зума. При геометрическом HOLD журнал различает отсутствие сопоставления, отбрасывание по площади относительно принятой рамки, ожидание подтверждения и отказ переинициализации. При позднем YOLO событие отмечает, что кадр использован для верификации или привёл к штатному STOP из-за конфликта. + +Списки содержат до 12 рамок, которые дошли до соответствующих проверок контроллера. Общие количества и выбранная рамка записываются отдельно. Сырые результаты YOLO до фильтрации представлены счётчиком. Для событий, ожидающих подтверждения, `yolo_match` показывает возможное совпадение, а `yolo_selected` остаётся пустым. Писатель использует существующую ограниченную очередь. Переполнение увеличивает `dropped_before` у следующих событий. + +Для офлайн-проверки `test_recovery_telemetry.py` укажите пути `PTZ17_TEST_RUNTIME`, `PTZ17_TEST_BASELINE` и `PTZ17_TEST_CANDIDATE`. Базовая версия для этих тестов — предыдущий коммит PR №14. Тесты сравнивают команды Pan/Tilt/Zoom, защитные STOP, вызовы тревог и состояние контроллера на одинаковых входах со смоделированными детекциями. Полевое время от HOLD до повторного разрешения зума остаётся измерить после сбора новых событий. + Локальный кандидат поверх установленного PR №13. Прямое и обратное применение патча проверены побайтно. SHA-256 базовой и кандидатной версий в `pins.json`. На широком угле кандидат проверяет, может ли уже разрешённый первый обычный импульс native 10 начаться с длительностью до 340 мс и жёстким пределом 400 мс. Для этого нужны текущий кадр OSTrack, свежее подтверждение YOLO, свежая оптика, допустимая скорость в кадре и полная штатная проекция рамки. Повторное разрешение допускает только исходный запрос того же владельца. При запрете базового контроллера запрос остаётся нулевым. Функции модели, тревог и транспорт STOP сохранены. diff --git a/integration/ptz17_focus_zoom/pins.json b/integration/ptz17_focus_zoom/pins.json index 4a896fa..d553369 100644 --- a/integration/ptz17_focus_zoom/pins.json +++ b/integration/ptz17_focus_zoom/pins.json @@ -1,6 +1,6 @@ { "base_sha256": "6cf484271ef3659028b0b4d43041addb05102f91d2758ab472d968a52d24e911", - "candidate_sha256": "fc0deb0c54fbd94a916493ee0c3159b02407876b32deebbbc3d819cc58a17500", - "patch_sha256": "e4a03e3dd4cd0f99995bc37acab29d063553cb32966fb13bdd93a46b8f7c5a9f", + "candidate_sha256": "f04d8a8d7a4105fe6812afaed00655dc42cbf7e6fb014e01d9f5efb306db13ca", + "patch_sha256": "555d329a1c437187e254330384ec1dab60dc3fb8ac859c710c9cef517ac59dd5", "installed": false } diff --git a/integration/ptz17_focus_zoom/server.patch b/integration/ptz17_focus_zoom/server.patch index b1ac814..227ada5 100644 --- a/integration/ptz17_focus_zoom/server.patch +++ b/integration/ptz17_focus_zoom/server.patch @@ -9,7 +9,15 @@ ) from . import motion_detector from .utils import ( -@@ -690,6 +690,8 @@ +@@ -46,6 +46,7 @@ + from .tracking_policy import should_allow_offsector_park, should_enforce_track_sector_limits + from .bt_tracker import ByteTracker + from .visual_tracker import ( ++ VisualTrackResult, + bbox_center_distance_norm, + bbox_iou, + visual_tracker_manager, +@@ -690,6 +691,8 @@ def _focus_quality_score( frame_bgr: np.ndarray, bbox: Tuple[int, int, int, int] | list[int], @@ -18,7 +26,7 @@ ) -> float | None: """Return Laplacian focus energy from a bounded ROI around the target. -@@ -708,7 +710,7 @@ +@@ -708,7 +711,7 @@ if not np.isfinite([x1, y1, x2, y2]).all() or x2 <= x1 or y2 <= y1: return None @@ -27,7 +35,7 @@ cx = (x1 + x2) * 0.5 cy = (y1 + y2) * 0.5 roi_w = max(16.0, (x2 - x1) * scale) -@@ -741,6 +743,154 @@ +@@ -741,6 +744,221 @@ return score if math.isfinite(score) else None @@ -66,6 +74,73 @@ + "decision_frame", at, **values) + + ++_PTZ17_RECOVERY_BOX_LIMIT = 12 ++_PTZ17_RECOVERY_REASON_LIMIT = 160 ++_DetectorBox = tuple[list[int], float, int] ++ ++ ++def _recovery_box_px(box: tuple[int, ...] | list[int] | None) -> list[int] | None: ++ """Snapshot xyxy pixels from the top left of the processing image, x right and y down.""" ++ if box is None or len(box) != 4: ++ return None ++ try: ++ return [int(value) for value in box] ++ except (TypeError, ValueError, OverflowError): ++ return None ++ ++ ++def _recovery_detector_box(candidate: _DetectorBox | None) -> dict[str, Any] | None: ++ if candidate is None: ++ return None ++ box, score, class_id = candidate ++ confidence = float(score) ++ return dict(bbox_px=_recovery_box_px(box), confidence=confidence if math.isfinite(confidence) else None, ++ class_id=int(class_id)) ++ ++ ++def _record_ptz17_recovery( ++ cam_idx: int, st: dict, observation_utc: float, source_seq: int | None, ++ frame_w: int, frame_h: int, visual_result: VisualTrackResult, *, ++ input_kind: str, outcome: str, trusted_bbox: tuple[int, ...] | list[int] | None, ++ reference_bbox: tuple[int, ...] | list[int] | None, ++ validation_targets: list[_DetectorBox], reacquire_targets: list[_DetectorBox], ++ raw_box_count: int, expected_track_class: int | None = None, detector_match: _DetectorBox | None = None, ++ selected: _DetectorBox | None = None, seeded: VisualTrackResult | None = None, ++) -> None: ++ """Record already available inputs and the recovery outcome off the control thread.""" ++ if (cam_idx != _PTZ17_CAM_IDX or st.get("mode") != "TRACK" or not st.get("tracking_active") ++ or not getattr(config, "PREDICTIVE_ZOOM_TELEMETRY_DIR", "logs/ptz_zoom")): ++ return ++ _, generation, started_at, rearm_epoch = visual_control.owner(st) ++ if started_at <= 0.0 or not math.isfinite(started_at) or not math.isfinite(observation_utc): ++ return ++ ++ def tracker_fields(result: VisualTrackResult) -> dict[str, Any]: ++ score = float(result.score) ++ return dict(bbox_px=_recovery_box_px(result.bbox), ok=bool(result.ok), ++ score=score if math.isfinite(score) else None, class_id=int(result.target_class), ++ frame_seq=int(result.source_seq) if result.source_seq is not None else None, ++ reason=str(result.reason)[:_PTZ17_RECOVERY_REASON_LIMIT]) ++ ++ _episode_telemetry( ++ config, cam_idx, (generation, started_at), "recovery_frame", time.time(), ++ observation_utc=observation_utc, frame_seq=int(source_seq) if source_seq is not None else None, ++ frame_size_px=[frame_w, frame_h], input_kind=input_kind, outcome=outcome, ++ expected_track_class=expected_track_class, ++ trusted_bbox_px=_recovery_box_px(trusted_bbox), association_reference_bbox_px=_recovery_box_px(reference_bbox), ++ ostrack=tracker_fields(visual_result), reinitialized_ostrack=tracker_fields(seeded) if seeded is not None else None, ++ yolo_raw_count=raw_box_count, ++ yolo_validation_count=len(validation_targets), yolo_reacquire_count=len(reacquire_targets), ++ yolo_validation=[_recovery_detector_box(box) for box in validation_targets[:_PTZ17_RECOVERY_BOX_LIMIT]], ++ yolo_reacquire=[_recovery_detector_box(box) for box in reacquire_targets[:_PTZ17_RECOVERY_BOX_LIMIT]], ++ yolo_match=_recovery_detector_box(detector_match), yolo_selected=_recovery_detector_box(selected), ++ reacquire_votes=int(st.get("visual_reacquire_votes", 0) or 0), ++ reacquire_vote_frame_seq=int(st.get("visual_reacquire_source_seq", -1)), ++ zoom_rearm_epoch=rearm_epoch, zoom_rearm_required=bool(st.get("zoom_rearm_required")), ++ zoom_rearm_votes=int(st.get("zoom_rearm_votes", 0) or 0), ++ ) ++ ++ +def _ptz17_target_focus_score( + frame_bgr: np.ndarray, bbox: tuple[int, int, int, int] | list[int], +) -> float | None: @@ -182,7 +257,7 @@ def _clear_focus_low_evidence(st: dict) -> None: st["focus_quality_low_frames"] = 0 st["focus_quality_low_since"] = None -@@ -761,6 +911,7 @@ +@@ -761,6 +979,7 @@ center_err: float, hfov_deg: float, validation_age: float, @@ -190,7 +265,7 @@ ) -> bool: """Measure settled target detail and queue one bounded autofocus request.""" if not bool(getattr(config, "AUTOFOCUS_QUALITY_ENABLE", True)) or not bool( -@@ -833,14 +984,31 @@ +@@ -833,14 +1052,31 @@ _clear_focus_low_evidence(st) st["focus_last_hfov_deg"] = float(hfov_deg) @@ -225,7 +300,7 @@ alpha = clipf(float(getattr(config, "AUTOFOCUS_SCORE_EMA_ALPHA", 0.35)), 0.01, 1.0) previous_ema = st.get("focus_quality_ema") ema = float(score) if not isinstance(previous_ema, (int, float)) else ( -@@ -870,7 +1038,10 @@ +@@ -870,7 +1106,10 @@ if ema >= threshold: # Keep the independent raw-drop evidence while the deliberately slow # EMA still describes the previously sharp scene. @@ -237,7 +312,7 @@ st["focus_quality_low_frames"] = 0 st["focus_quality_low_since"] = None else: -@@ -916,12 +1087,19 @@ +@@ -916,12 +1155,19 @@ if not confirmed_low: return False @@ -258,7 +333,7 @@ if str(st.get("focus_state", "")) not in { "unsupported", "unsupported_backoff", -@@ -931,6 +1109,8 @@ +@@ -931,6 +1177,8 @@ st["focus_state"] = "blur_wait" return False @@ -267,7 +342,7 @@ st["focus_state"] = "requested" st["focus_last_request_at"] = float(now) st["focus_settle_until"] = float(now) + max( -@@ -938,12 +1118,11 @@ +@@ -938,12 +1186,11 @@ float(getattr(config, "AUTOFOCUS_SETTLE_HOLD_SEC", 0.80)), ) _clear_focus_low_evidence(st) @@ -285,7 +360,231 @@ return True -@@ -9537,6 +9716,50 @@ +@@ -6757,11 +7004,20 @@ + detector_targets: list[tuple[list[int], float, int]], + validation_targets: list[tuple[list[int], float, int]], width: int, height: int, + steering_targets: list[tuple[list[float], float, int]] | None = None, ++ *, recovery_targets: list[_DetectorBox] | None = None, raw_box_count: int = 0, + ) -> None: + """Validate the same image without rewinding live control or loss recovery.""" + result = sample.result + bbox = result.bbox + if not result.ok or bbox is None: ++ if recovery_targets is not None: ++ _record_ptz17_recovery( ++ cam_idx, st, float(sample.captured_at), sample.source_seq, width, height, result, ++ input_kind="paired_detector", outcome="paired_tracker_unusable", ++ trusted_bbox=st.get("last_bbox"), reference_bbox=bbox, ++ validation_targets=validation_targets, reacquire_targets=recovery_targets, ++ raw_box_count=raw_box_count, ++ ) + return + now = float(sample.captured_at) + target_class = int(result.target_class) +@@ -6783,6 +7039,14 @@ + visual_tracker_manager.reset(cam_idx, reason='paired detector identity mismatch') + stop_ptz(cam_idx, source='stop', generation=int(st.get('ptz_generation', 0) or 0)) + alarms.ingest_detection(cam_idx, False) ++ if recovery_targets is not None: ++ _record_ptz17_recovery( ++ cam_idx, st, now, sample.source_seq, width, height, result, ++ input_kind="paired_detector", outcome="paired_identity_stop", ++ trusted_bbox=st.get("last_bbox"), reference_bbox=bbox, ++ validation_targets=candidates, reacquire_targets=recovery_targets, ++ raw_box_count=raw_box_count, expected_track_class=target_class, ++ ) + return + st['visual_tracker_mismatch_frames'] = 0 + if matched is not None and now >= float(st.get('visual_tracker_last_detector_at', 0.) or 0.): +@@ -6802,6 +7066,14 @@ + detector_conf=max(alarm_conf, identity_conf), + alarm_eligible=alarm_eligible, cam_idx=cam_idx) + alarms.ingest_detection(cam_idx, alarm_eligible) ++ if recovery_targets is not None: ++ _record_ptz17_recovery( ++ cam_idx, st, now, sample.source_seq, width, height, result, ++ input_kind="paired_detector", outcome="validation_only", ++ trusted_bbox=st.get("last_bbox"), reference_bbox=bbox, ++ validation_targets=candidates, reacquire_targets=recovery_targets, ++ raw_box_count=raw_box_count, expected_track_class=target_class, detector_match=matched, ++ ) + + + @visual_control.serialized_control +@@ -7259,8 +7531,14 @@ + ) + + if evidence_only: +- _consume_paired_detector_evidence(cam_idx, st, visual_sample, detector_targets, +- validation_targets, w, h, steering_targets) ++ trace_recovery = cam_idx == _PTZ17_CAM_IDX and ( ++ not visual_sample.result.ok or visual_sample.result.reason == "recovered" ++ or st.get("loss_since") is not None or st.get("zoom_rearm_reason") == "geometry_reject" ++ ) ++ _consume_paired_detector_evidence( ++ cam_idx, st, visual_sample, detector_targets, validation_targets, w, h, steering_targets, ++ recovery_targets=reacquire_targets if trace_recovery else None, raw_box_count=raw_box_count, ++ ) + return + + if bt_active: +@@ -7580,6 +7858,7 @@ + # its own gate, but a bad backend result/config override must still + # be unable to move the camera by following a remote cloud edge. + previous_control_bbox = st.get("last_bbox") ++ recovery_input_kind = "visual_control" if visual_only else "detector_control" + gross_visual_jump = False + visual_control_jump = 0.0 + visual_control_limit = float( +@@ -7622,6 +7901,9 @@ + ("center jump", "area ratio", "validated area ratio") + ) + ) ++ geometry_match = validated_geometry_target = None ++ seeded_geometry = None ++ geometry_outcome = "geometry_no_box" + if (gross_visual_jump or geometric_reject) and visual_result.bbox is not None: + # A large motion is safe only when the *current* detector agrees + # with that new location. A backend result that passed its own +@@ -7643,6 +7925,8 @@ + ), + allow_target_class_compatibility=True, + ) ++ geometry_match = validated_geometry_target ++ geometry_outcome = "geometry_no_match" + if ( + validated_geometry_target is not None + and isinstance(previous_control_bbox, (tuple, list)) +@@ -7673,6 +7957,7 @@ + ) + ): + validated_geometry_target = None ++ geometry_outcome = "geometry_trusted_area_rejected" + if geometric_reject and validated_geometry_target is not None: + validated_geometry_target = _confirm_loss_reacquire_candidate( + st, +@@ -7682,6 +7967,7 @@ + h, + source_seq=source_seq, + ) ++ geometry_outcome = "geometry_confirmation_pending" + if validated_geometry_target is not None: + preserved_track_class = ( + int(visual_result.target_class) +@@ -7701,6 +7987,7 @@ + now=now, + source_seq=source_seq, + ) ++ geometry_outcome = "geometry_seed_failed" + if seeded_geometry.ok and seeded_geometry.bbox is not None: + logger.info( + "[OSTRACK/IDENTITY] cam=%s detector validated geometry jump; reinitialized", +@@ -7714,6 +8001,16 @@ + _arm_zoom_revalidation( + st, now, "geometry_reinitialized", cam_idx=cam_idx + ) ++ if cam_idx == _PTZ17_CAM_IDX: ++ _record_ptz17_recovery( ++ cam_idx, st, now, source_seq, w, h, visual_result, ++ input_kind=recovery_input_kind, outcome="geometry_reinitialized", ++ trusted_bbox=previous_control_bbox, reference_bbox=visual_result.bbox, ++ validation_targets=validation_targets, reacquire_targets=reacquire_targets, ++ raw_box_count=raw_box_count, detector_match=geometry_match, ++ selected=validated_geometry_target, seeded=seeded_geometry, ++ expected_track_class=expected_track_class, ++ ) + visual_result = seeded_geometry + reference_bbox = seeded_geometry.bbox + gross_visual_jump = False +@@ -7743,6 +8040,16 @@ + source="stop", + generation=int(st.get("ptz_generation", 0) or 0), + ) ++ if cam_idx == _PTZ17_CAM_IDX: ++ _record_ptz17_recovery( ++ cam_idx, st, now, source_seq, w, h, visual_result, ++ input_kind=recovery_input_kind, outcome=geometry_outcome, ++ trusted_bbox=previous_control_bbox, reference_bbox=visual_result.bbox, ++ validation_targets=validation_targets, reacquire_targets=reacquire_targets, ++ raw_box_count=raw_box_count, ++ detector_match=geometry_match, selected=validated_geometry_target, ++ seeded=seeded_geometry, expected_track_class=expected_track_class, ++ ) + logger.warning( + "[OSTRACK/IDENTITY] cam=%s HOLD rejected geometry reason=%s; awaiting recovery", + cam_idx, +@@ -7771,6 +8078,16 @@ + source="stop", + generation=int(st.get("ptz_generation", 0) or 0), + ) ++ if cam_idx == _PTZ17_CAM_IDX: ++ _record_ptz17_recovery( ++ cam_idx, st, now, source_seq, w, h, visual_result, ++ input_kind=recovery_input_kind, outcome="control_jump_stop", ++ trusted_bbox=previous_control_bbox, reference_bbox=visual_result.bbox, ++ validation_targets=validation_targets, reacquire_targets=reacquire_targets, ++ raw_box_count=raw_box_count, detector_match=geometry_match, ++ selected=validated_geometry_target, seeded=seeded_geometry, ++ expected_track_class=expected_track_class, ++ ) + logger.warning( + "[OSTRACK/IDENTITY] cam=%s STOP rejected geometry reason=%s", + cam_idx, +@@ -7782,6 +8099,7 @@ + + matched_validation = None + matched_reacquire = None ++ widened_candidate = None + if reference_bbox is not None: + matched_validation = _find_visual_validation_target( + reference_bbox, +@@ -8062,6 +8380,17 @@ + det_xyxy.append(tuple(visual_result.bbox)) + visual_track_label_index = len(det_labels) + det_labels.append("target track") ++ if cam_idx == _PTZ17_CAM_IDX and not geometry_reinitialized and ( ++ visual_result.reason == "recovered" or st.get("loss_since") is not None ++ ): ++ _record_ptz17_recovery( ++ cam_idx, st, now, source_seq, w, h, visual_result, ++ input_kind=recovery_input_kind, outcome="visual_recovered", ++ trusted_bbox=previous_control_bbox, reference_bbox=reference_bbox, ++ validation_targets=validation_targets, reacquire_targets=reacquire_targets, ++ raw_box_count=raw_box_count, detector_match=matched_validation, ++ expected_track_class=expected_track_class, ++ ) + else: + ptz17_validation_timeout = bool( + visual_only and _ptz17_validation_timeout_steering( +@@ -8105,6 +8434,7 @@ + _arm_zoom_revalidation( + st, now, "visual_reacquire", cam_idx=cam_idx + ) ++ seeded = None + if matched_reacquire is not None: + preserved_track_class = ( + int(visual_result.target_class) +@@ -8148,6 +8478,19 @@ + target_source = "none" + st["visual_tracker_score"] = float(visual_result.score) + st["visual_tracker_last_reason"] = visual_result.reason ++ if cam_idx == _PTZ17_CAM_IDX: ++ _record_ptz17_recovery( ++ cam_idx, st, now, source_seq, w, h, visual_result, ++ input_kind=recovery_input_kind, ++ outcome=target_source if matched_reacquire is not None else ++ "loss_confirmation_pending" if widened_candidate is not None else "loss_no_match", ++ trusted_bbox=previous_control_bbox, reference_bbox=reference_bbox, ++ validation_targets=validation_targets, reacquire_targets=reacquire_targets, ++ raw_box_count=raw_box_count, ++ detector_match=widened_candidate if widened_candidate is not None else matched_reacquire, ++ selected=matched_reacquire, seeded=seeded, ++ expected_track_class=expected_track_class, ++ ) + elif best_target is not None: + # ACQUIRE has already approved this target. Seed the appearance + # tracker on the same frame before entering full TRACK. +@@ -9537,6 +9880,50 @@ max(0.0, float(getattr(config, min_key, 0.10))), ) zoom_cmd = min(max_effective, max(float(zoom_cmd), min_effective)) @@ -336,7 +635,7 @@ if probe_start_candidate and identify_start_candidate: pulse_kind = "probe_identify" elif probe_start_candidate: -@@ -9645,8 +9868,30 @@ +@@ -9645,8 +10032,30 @@ zoom_cmd = 0.0 st["zoom_useful_pulse_reason"] = "wait_response_framing" zoom_zero_reason = "response_framing" @@ -367,7 +666,7 @@ zoom_cmd = _gate_zoom_in_pulse( st, # Keep new-request expiry tied to the frame that authorized -@@ -9667,9 +9912,15 @@ +@@ -9667,9 +10076,15 @@ ) if predictive_start and zoom_cmd > 0.0 and st["zoom_step_request_id"] > request_id_before_gate: st["predictive_zoom_request"] = st["zoom_step_pending_id"] @@ -383,7 +682,7 @@ if ( probe_start_candidate and zoom_cmd > 0.0 -@@ -9693,23 +9944,24 @@ +@@ -9693,23 +10108,24 @@ elif zoom_cmd < 0.0 and float(size_est) <= max(0.05, zoomed_size_thr * 0.75): st["was_zoomed_in"] = False @@ -425,7 +724,7 @@ st["fallback_done"] = False -@@ -10191,7 +10443,7 @@ +@@ -10191,7 +10607,7 @@ stop_ptz(cam_idx, source='stop', generation=int(st.get('ptz_generation', 0) or 0)) return zoom_decision = None @@ -434,7 +733,7 @@ blockers = tuple(name for name, blocked in ( ("quality", not zoom_quality_ok), ("framing", not zoom_safe), -@@ -10210,7 +10462,36 @@ +@@ -10210,7 +10626,36 @@ ("stale", visual_control_stale), ("brake", final_guard_active), ) if blocked) @@ -472,7 +771,7 @@ if predictive_decision is not None: with _zoom_command_lock(cam_idx): telemetry_tick( -@@ -10222,6 +10503,8 @@ +@@ -10222,6 +10667,8 @@ if getattr(config, "PREDICTIVE_ZOOM_TELEMETRY_DIR", "logs/ptz_zoom"): blocked = {} if zoom_cmd <= 0.0 and raw_zoom_needed: diff --git a/integration/ptz17_focus_zoom/test_recovery_telemetry.py b/integration/ptz17_focus_zoom/test_recovery_telemetry.py new file mode 100644 index 0000000..678bb63 --- /dev/null +++ b/integration/ptz17_focus_zoom/test_recovery_telemetry.py @@ -0,0 +1,231 @@ +"""Offline comparison of TRACK recovery with and without PTZ17 telemetry.""" +from contextlib import ExitStack +import importlib.util +import json +import math +import os +from pathlib import Path +import sys +from types import SimpleNamespace +from unittest.mock import Mock, patch + +import numpy as np +import pytest +import torch + + +HERE = Path(__file__).resolve().parent +TRUSTED = (620, 350, 640, 364) +REJECTED = (570, 325, 680, 382) +GOOD = [622, 351, 643, 365] +WRONG = [590, 335, 670, 372] +MOVED = [760, 350, 780, 364] + + +@pytest.fixture(scope="module") +def versions(): + runtime = Path(os.environ["PTZ17_TEST_RUNTIME"]) + package = "_ptz17_recovery_runtime" + paths = [runtime / "__init__.py", Path(os.environ["PTZ17_TEST_BASELINE"]), + Path(os.environ["PTZ17_TEST_CANDIDATE"])] + modules = [] + for name, path in zip((package, package + ".baseline", package + ".candidate"), paths, strict=True): + spec = importlib.util.spec_from_file_location( + name, path, submodule_search_locations=[str(runtime)] if name == package else None, + ) + assert spec and spec.loader + module = importlib.util.module_from_spec(spec) + sys.modules[name] = module + spec.loader.exec_module(module) + modules.append(module) + return modules[1:] + + +class Boxes: + def __init__(self, observations): + self.xyxy = torch.tensor([box for box, _, _ in observations], dtype=torch.float32) + self.conf = torch.tensor([confidence for _, confidence, _ in observations]) + self.cls = torch.tensor([class_id for _, _, class_id in observations]) + + def __len__(self): + return len(self.conf) + + +def exercise(module, scenario, *, cam=6, enabled=True): + st = module.state._default_ptz_state(cam) + st.update(tracking_active=True, mode="TRACK", ptz_generation=31, track_started_at=90.0, + last_seen=99.8, last_zoom_seen=99.8, last_bbox=TRUSTED, track_source="visual", + hfov_deg=59.0, zoom_status_at=99.95, abs_zoom=1.0, identity_class=0, + visual_tracker_last_detector_at=99.9, visual_tracker_last_zoom_detector_at=99.9, + visual_tracker_last_detector_conf=0.80) + result_type = module.visual_tracker_manager.update.__globals__["VisualTrackResult"] + frame = np.zeros((720, 1280, 3), dtype=np.uint8) + operations, telemetry = [], [] + + def emit(_config, _cam, owner, name, at, **fields): + json.dumps(fields, allow_nan=False) + if name == "recovery_frame": + telemetry.append((owner, at, fields)) + + with ExitStack() as stack: + stack.enter_context(patch.dict(module.state.ptz_states, {cam: st})) + for key, value in { + "PTZ_VISUAL_CONTROL_ENABLE": True, "PREDICTIVE_ZOOM_TELEMETRY_DIR": "offline" if enabled else "", + "DETECT_CONF_BY_CLASS": {0: .65, 1: .65}, "DETECT_CONF": .65, + "DRONE_ONLY": False, "MOTION_DETECT_ENABLE": False, "BT_ENABLE": True, + "VISUAL_TRACKER_MATCH_CENTER_NORM": .10, "VISUAL_TRACKER_LOSS_REACQUIRE_CENTER_BASE": .15, + "VISUAL_TRACKER_LOSS_REACQUIRE_CONFIRM_MAX_GAP_SEC": .65, + }.items(): + stack.enter_context(patch.object(module.config, key, value, create=True)) + clock = stack.enter_context(patch.object(module.time, "time")) + update = stack.enter_context(patch.object(module.visual_tracker_manager, "update")) + for name in ("_publish_with_boxes", "notify_detected", "call_autofocus", "return_to_preset"): + stack.enter_context(patch.object(module, name)) + for name in ("stop_ptz", "move_ptz_bounded"): + stack.enter_context(patch.object(module, name, side_effect=lambda *a, key=name, **kw: + operations.append((key, a, kw)))) + stack.enter_context(patch.object(module.alarms, "is_armed", return_value=False)) + stack.enter_context(patch.object(module.alarms, "ingest_detection", side_effect=lambda *a: + operations.append(("alarm", a, {})))) + stack.enter_context(patch.object(module.visual_tracker_manager, "record_detector_validation")) + stack.enter_context(patch.object(module.visual_tracker_manager, "reset")) + stack.enter_context(patch.object(module.visual_tracker_manager, "should_refresh", return_value=False)) + stack.enter_context(patch.object(module, "_episode_telemetry", side_effect=emit)) + zoom_module = sys.modules[module.record_zoom_blocks.__module__] + stack.enter_context(patch.object(zoom_module, "_episode_telemetry", side_effect=emit)) + + def start(cam_idx, _image, box, *, target_class, detector_conf, now, source_seq): + operations.append(("seed", (cam_idx, tuple(box), target_class, detector_conf, now, source_seq), {})) + ok = scenario != "seed_failed" + return result_type(ok, tuple(box) if ok else None, .8, target_class, detector_conf, + 0, "initialized" if ok else "no template", source_seq) + + stack.enter_context(patch.object(module.visual_tracker_manager, "start", side_effect=start)) + + def frame_step(seq, at, tracker_box, reason, observations=(), *, paired=False, visual_only=False): + ok = reason in ("tracked", "recovered") + result = result_type(ok, tracker_box, .80 if ok else .29, 0, .80, 40, reason, seq) + update.return_value = result + clock.return_value = at + sample = module.visual_control.VisualSample(module.visual_control.owner(st), seq, at - .010, result) + module.postprocess_control(cam, frame, SimpleNamespace(boxes=Boxes(observations)), True, seq, + visual_sample=sample if paired or visual_only else None, + visual_only=visual_only) + + if scenario == "hold_then_strict": + frame_step(41, 100.0, REJECTED, "validated area ratio 11.34", + [(GOOD, .50, 0), (WRONG, .95, 0)]) + frame_step(42, 100.2, REJECTED, "low score", [(GOOD, .51, 0)]) + elif scenario == "wide_two_frames": + frame_step(41, 100.0, None, "low score", [(MOVED, .70, 0)]) + frame_step(42, 100.3, None, "low score", [(MOVED, .71, 0)]) + elif scenario == "seed_failed": + frame_step(41, 100.0, None, "low score", [(GOOD, .81, 0)]) + elif scenario == "visual_recovers": + frame_step(41, 100.0, REJECTED, "validated area ratio 11.34", visual_only=True) + frame_step(42, 100.1, TRUSTED, "recovered", visual_only=True) + elif scenario == "paired_hold": + frame_step(41, 100.0, REJECTED, "validated area ratio 11.34", visual_only=True) + frame_step(42, 100.1, TRUSTED, "tracked", [(GOOD, .81, 0)], paired=True) + elif scenario == "geometry_two_frames": + frame_step(41, 100.0, TRUSTED, "center jump", [(GOOD, .81, 0)]) + frame_step(42, 100.2, TRUSTED, "center jump", [(GOOD, .82, 0)]) + elif scenario == "ordinary_track": + frame_step(41, 100.0, TRUSTED, "tracked", [(GOOD, .81, 0)]) + else: + raise ValueError(scenario) + state_evidence = {key: st.get(key) for key in ( + "track_source", "zoom_state", "zoom_rearm_epoch", "zoom_rearm_votes", "zoom_prev_cmd", + "visual_reacquire_votes", "identity_state", "alarm_gate_eligible", "last_bbox", + )} + return operations, state_evidence, [fields for _, _, fields in telemetry] + + +@pytest.mark.parametrize("scenario,outcomes", [ + ("hold_then_strict", ["geometry_trusted_area_rejected", "detector_reacquire"]), + ("wide_two_frames", ["loss_confirmation_pending", "detector_reacquire"]), + ("seed_failed", ["detector_fallback"]), + ("visual_recovers", ["geometry_no_match", "visual_recovered"]), + ("paired_hold", ["geometry_no_match", "validation_only"]), + ("geometry_two_frames", ["geometry_confirmation_pending", "geometry_reinitialized"]), + ("ordinary_track", []), +]) +def test_command_and_alarm_parity(versions, scenario, outcomes): + base, candidate = versions + previous, previous_state, _ = exercise(base, scenario) + actual, actual_state, rows = exercise(candidate, scenario) + assert (actual, actual_state) == (previous, previous_state) + assert [row["outcome"] for row in rows] == outcomes + if scenario == "hold_then_strict": + reject, recover = rows + assert reject["trusted_bbox_px"] == list(TRUSTED) + assert reject["association_reference_bbox_px"] == list(REJECTED) + assert reject["ostrack"]["bbox_px"] == list(REJECTED) + assert reject["yolo_match"]["bbox_px"] == WRONG and reject["yolo_selected"] is None + assert {tuple(box["bbox_px"]) for box in reject["yolo_reacquire"]} == {tuple(WRONG), tuple(GOOD)} + assert recover["yolo_selected"]["bbox_px"] == GOOD + assert recover["reinitialized_ostrack"]["bbox_px"] == GOOD + if scenario == "wide_two_frames": + assert [row["reacquire_votes"] for row in rows] == [1, 2] + assert rows[0]["yolo_selected"] is None + assert rows[1]["yolo_selected"]["bbox_px"] == MOVED + if scenario == "paired_hold": + paired = rows[-1] + assert paired["frame_seq"] == paired["ostrack"]["frame_seq"] == 42 + assert paired["observation_utc"] == pytest.approx(100.09) + assert paired["input_kind"] == "paired_detector" + assert paired["yolo_match"]["bbox_px"] == GOOD + if scenario == "geometry_two_frames": + assert [row["reacquire_votes"] for row in rows] == [1, 2] + assert rows[-1]["ostrack"]["ok"] is False + assert rows[-1]["reinitialized_ostrack"]["ok"] is True + assert rows[-1]["reinitialized_ostrack"]["bbox_px"] == GOOD + + +@pytest.mark.parametrize("cam,enabled", [(8, True), (6, False)]) +def test_scope_and_disable(versions, cam, enabled): + assert exercise(versions[1], "hold_then_strict", cam=cam, enabled=enabled)[2] == [] + + +def test_bounds_and_finite_json(versions): + module = versions[1] + valid = module.visual_tracker_manager.update.__globals__["VisualTrackResult"] + result = valid(False, (620, 350, 640, 364), math.nan, 0, .8, 40, "x" * 900, 17) + candidates = [([k, 4, k + 20, 17], math.inf if k == 0 else .8, 0) for k in range(33)] + selected = candidates[-1] + state = dict(mode="TRACK", tracking_active=True, track_started_at=90.0, ptz_generation=7) + sink = Mock() + with patch.object(module, "_episode_telemetry", sink): + module._record_ptz17_recovery( + 6, state, 100.0, 17, 1280, 720, result, input_kind="detector_control", + outcome="geometry_hold", trusted_bbox=TRUSTED, reference_bbox=result.bbox, + validation_targets=candidates, reacquire_targets=candidates, raw_box_count=33, selected=selected, + ) + assert sink.call_args.args[1:4] == (6, (7, 90.0), "recovery_frame") + row = sink.call_args.kwargs + assert len(row["yolo_validation"]) == len(row["yolo_reacquire"]) == 12 + assert row["yolo_validation_count"] == row["yolo_reacquire_count"] == 33 + assert row["yolo_selected"]["bbox_px"] == selected[0] + assert row["ostrack"]["score"] is None and row["yolo_validation"][0]["confidence"] is None + assert len(row["ostrack"]["reason"]) == 160 + json.dumps(row, allow_nan=False) + + +def test_full_queue_drops_telemetry_without_waiting(versions, tmp_path): + module = versions[1] + log_module = sys.modules[module.record_zoom_blocks.__module__] + with patch.object(log_module, "Thread"): + writer = log_module.EpisodeTelemetryLogger(tmp_path, capacity=1) + result_type = module.visual_tracker_manager.update.__globals__["VisualTrackResult"] + result = result_type(False, REJECTED, .29, 0, .8, 40, "area ratio 11.34", 17) + state = dict(mode="TRACK", tracking_active=True, track_started_at=90.0, ptz_generation=7) + with patch.object(module.config, "PREDICTIVE_ZOOM_TELEMETRY_DIR", str(tmp_path), create=True): + with patch.dict(log_module._telemetry_loggers, {str(tmp_path): writer}): + for _ in range(2): + module._record_ptz17_recovery( + 6, state, 100.0, 17, 1280, 720, result, input_kind="visual_control", + outcome="geometry_no_match", trusted_bbox=TRUSTED, reference_bbox=REJECTED, + validation_targets=[], reacquire_targets=[], raw_box_count=0, + ) + assert writer.queue.qsize() == 1 + assert writer.dropped == 1 -- 2.17.1