else: place_img = _capture_for_vlm( "place", frames_dir, log_record, dry_run, run_stem=run_stem) _observe_capture_push(log_record) _OBSERVE_STATE["cap_place"] = (str(place_img) if place_img else None) # 観測: 同じ画像に赤ブロック HSV 検出を脇でかける(既存判定/分岐は不変) _OBSERVE_STATE["block_place_xz"] = _detect_block_in_place_img(place_img) # DAY274: 同じ画像に白箱検出も脇でかける (stage2 と同一検出器 06f). # 撮影・送角・グリッパー・sleep は追加しない (画像は既に手元にある). # 検出失敗 (None) は _append_ledger 側で box_shift 3 列を空欄にする. _OBSERVE_STATE["box_xz_last"] = _detect_white_box_in_place_img(place_img) # DAY274 層2: box_shift_dist を計算し, 高さ補正記憶をラチェット更新. # box_xz (stage2 検出) と box_xz_last (退避後) 両方揃った時のみ. # 検出失敗 (None) や box_xz 欠損時は更新スキップ (現状維持). # PLACE 補正 (XZ) と独立記憶 (別 json). USE_CORRECTION=False で完全停止. _bxl = _OBSERVE_STATE.get("box_xz_last") _box_shift_dist_mm = None if (USE_CORRECTION and isinstance(box_xz, (list, tuple)) and len(box_xz) == 2 and isinstance(box_xz[0], (int, float)) and isinstance(box_xz[1], (int, float)) and isinstance(_bxl, (list, tuple)) and len(_bxl) == 2 and isinstance(_bxl[0], (int, float)) and isinstance(_bxl[1], (int, float))): _dx = (float(_bxl[0]) - float(box_xz[0])) * 1000.0 _dz = (float(_bxl[1]) - float(box_xz[1])) * 1000.0 _box_shift_dist_mm = (_dx * _dx + _dz * _dz) ** 0.5 # 2026-10-16: --record-demo 中は高さ補正記憶を読むだけで更新しない. # 箱検出の測り違い (box_shift≈200mm) で成功のたびに +5mm 積み上がり, # j4 が J4_SAFE 外になって stage8 で止まったため. 置く高さをそろえる目的も兼ねる. if _box_shift_dist_mm is not None and _DEMO_TAP_INSTALLED: print("[HGT ] record-demo: 高さ補正の更新を停止中 (dist={:.1f}mm, 記憶は不変)" .format(_box_shift_dist_mm)) elif _box_shift_dist_mm is not None: try: _hmem = _height_load() _hkey = _height_key(float(box_xz[0]), float(box_xz[1])) _new_entry = _height_update_ratchet( _hmem, _hkey, _box_shift_dist_mm) if _height_save(_hmem): print("[HGT ] update {} dist={:.1f}mm → dee_y={:.1f}mm " "(n={})".format( _hkey, _box_shift_dist_mm, _new_entry.get("dee_y_mm", 0.0), _new_entry.get("n", 0))) except Exception as e: print("[HGT ] [WARN] ratchet update 例外: {}: {}".format( type(e).__name__, e)) place_vlm = _judge_image( place_img, "place", dry_run, dummy_place_verdict) place_vlm_verdict = place_vlm["verdict"] place_human_verdict = None if human_judge and not dry_run: place_human_verdict = _ask_human_verdict( place_img, place_vlm, kind="place") place_adopted = place_vlm_verdict # 分岐は常に VLM。記録のみ人 _observe_verdict("place", place_adopted, place_vlm["confidence"], place_vlm["reason"]) # 非移動 stage の通知 emit(stage9b 成功ブランチ→画面に verdict 行) _observe_emit_now()