reloc: --slam-reloc(-auto) tu dinh vi lai trong node (tu xoay/tu di, nguoi luon thang); web ve robot mo o vi tri doan; sieu am cho xoay; LocalMatch gioi han huong

This commit is contained in:
trung09122002
2026-09-29 11:16:04 +07:00
parent 399a46139e
commit 60853531aa
15 changed files with 883 additions and 27 deletions

View File

@@ -34,13 +34,15 @@ def ang(a, b):
return abs(math.degrees(math.atan2(math.sin(a - b), math.cos(a - b))))
def node_yaws(db):
"""Huong (rad) cua moi node theo pose DA TOI UU trong DB."""
def node_poses(db):
"""{id: (x, y, huong rad)} cua moi node theo pose DA TOI UU trong DB."""
c = sqlite3.connect(f"file:{db}?mode=ro", uri=True).cursor()
ids_b, poses_b = c.execute("select opt_ids, opt_poses from Admin").fetchone()
ids = np.frombuffer(zlib.decompress(ids_b[:-12]), dtype=np.int32)
P = np.frombuffer(zlib.decompress(poses_b[:-12]), dtype=np.float32).reshape(-1, 3, 4)
return {int(i): math.atan2(float(P[k][1, 0]), float(P[k][0, 0])) for k, i in enumerate(ids)}
return {int(i): (float(P[k][0, 3]), float(P[k][1, 3]),
math.atan2(float(P[k][1, 0]), float(P[k][0, 0])))
for k, i in enumerate(ids)}
def main():
@@ -54,7 +56,9 @@ def main():
ap.add_argument("--vpr-yaw-deg", type=float, default=45.0,
help="huong chot phai lech huong node anh VPR it hon ngan nay")
a = ap.parse_args()
yaw = node_yaws(a.db)
npose = node_poses(a.db)
yaw = {k: v[2] for k, v in npose.items()}
pos = {k: (v[0], v[1]) for k, v in npose.items()}
q = {}
cands = defaultdict(list)
@@ -70,7 +74,12 @@ def main():
rank=int(r["rank"]), node=int(r["vpr_node"]), sim=float(r["vpr_sim"]),
node_dist=float(r["vpr_node_dist_m"]),
score=float(r["loc_score"]),
l=(float(r["loc_x"]), float(r["loc_y"]), float(r["loc_th"]))))
l=(float(r["loc_x"]), float(r["loc_y"]), float(r["loc_th"])),
# Khop cuc bo GIOI HAN HUONG quanh huong node anh VPR (neu CSV co).
vscore=float(r.get("vloc_score", -1) or -1),
v=(float(r.get("vloc_x", 0) or 0), float(r.get("vloc_y", 0) or 0),
float(r.get("vloc_th", 0) or 0))))
q[qid]["s1"] = float(r["glob_s1"])
def correct(p, t):
return math.hypot(p[0] - t[0], p[1] - t[1]) < a.ok_m and ang(p[2], t[2]) < a.ok_deg
@@ -113,12 +122,15 @@ def main():
# --- Dong thuan CO dieu kien: VPR xac nhan ca HUONG, va du giong ---
def vpr_ok(c, pose, tau):
# Ca HUONG va VI TRI phai khop node anh VPR. Thieu dieu kien vi tri: ca
# VPR dung cho (0.09 m) ma LiDAR ca hai phia cung truot 3 m van lot.
return (c["score"] > 0 and c["sim"] >= tau and c["node"] in yaw
and ang(pose[2], yaw[c["node"]]) < a.vpr_yaw_deg)
and ang(pose[2], yaw[c["node"]]) < a.vpr_yaw_deg
and math.hypot(pose[0] - pos[c["node"]][0], pose[1] - pos[c["node"]][1]) < 2.0)
best = None
for K in (1, 3):
for tau in (0.6, 0.7, 0.8):
for tau in (0.5, 0.6, 0.7):
picks = {}
for k, v in q.items():
if v["glob_ok"] and any(agree(v["g"], c["l"]) and vpr_ok(c, v["g"], tau)
@@ -144,6 +156,45 @@ def main():
for name, acc, ok, bad in rows:
print(f" {name:44s} {acc:5d} {ok:5d} {bad:5d} {100.0 * ok / max(1, n):8.1f}%"
+ (" ⚠️" if bad > 0 else ""))
# --- VPR DAN: anh chon cho + huong, LiDAR xac minh; KHONG can LiDAR toan
# cuc dong y (cuu duoc ca ca LiDAR nhap nhang huong). ---
if not any(c["vscore"] > 0 for cs in cands.values() for c in cs):
print("\n(CSV khong co cot vloc_* -- chay lai bench ban moi de co luat 'VPR dan')")
return 0
lidar = {k: v["g"] for k, v in q.items() if v["glob_ok"] and v["verdict"] == "CHOT"}
print(f"\nVPR DAN: giong >= tau, khop cuc bo GIOI HAN huong (+-45 do quanh node anh) "
f"nam trong 2 m quanh node anh,\n diem LiDAR cua no >= alpha x diem LiDAR tot "
f"nhat TOAN ban do. Chot pose khop cuc bo do.")
print(f" {'luat':30s} {'chot':>5s} {'DUNG':>5s} {'SAI':>4s} | {'HOP cong LiDAR: DUNG':>21s} {'SAI':>4s} {'dung/tong':>9s}")
for K in (1, 3):
for tau in (0.5, 0.6, 0.7):
for alpha in (0.9, 0.95, 1.0):
picks = {}
for k, v in q.items():
best_c = None
for c in cands[k]:
if c["rank"] > K or c["vscore"] <= 0 or c["sim"] < tau:
continue
if c["vscore"] < alpha * v.get("s1", 0.0):
continue
# Pose khop phai o GAN node anh VPR (vi tri doc tu DB,
# khong dung dap an): anh giong nhau chup trong ~2 m.
nxy = pos.get(c["node"])
if nxy is None or math.hypot(c["v"][0] - nxy[0], c["v"][1] - nxy[1]) >= 2.0:
continue
if best_c is None or c["vscore"] > best_c["vscore"]:
best_c = c
if best_c is not None:
picks[k] = best_c["v"]
ok = sum(1 for k, p in picks.items() if correct(p, q[k]["t"]))
u = dict(picks)
u.update(lidar) # cong LiDAR da tin duoc -> uu tien
uok = sum(1 for k, p in u.items() if correct(p, q[k]["t"]))
bad, ubad = len(picks) - ok, len(u) - uok
print(f" top-{K} tau {tau:.1f} alpha {alpha:.2f} {len(picks):5d} {ok:5d} {bad:4d} | "
f"{uok:21d} {ubad:4d} {100.0 * uok / max(1, n):8.1f}%"
+ (" ⚠️" if ubad > 0 else ""))
return 0