fix(eval): doc uoc luong SLAM tu TF thay vi /slam/pose

eval_ate.py mac dinh --est=/slam/pose. Do la topic cua slam_core, ma
slam_core bi TAT khi RTAB-Map so huu canh map->odom. Cong cu van chay
nhung ghep duoc 0 cap - do la ly do ATE chua bao gio duoc do.

Doi sang doc TF map -> base_footprint: nguon nay dung cho MOI backend
(RTAB-Map, slam_core, AMCL) nen doi thuat toan khong phai sua lai.
Them --map-frame, --base-frame, --tf-rate.

Do lan dau tren world house: ATE RMSE 0.0214 m tren quang duong 81.30 m
(7291/7291 cap ghep duoc, P95 0.053 m, lon nhat 0.072 m).
This commit is contained in:
trung09122002
2026-08-28 15:32:22 +07:00
parent cccc63587e
commit 0100d4c871

View File

@@ -16,12 +16,23 @@ trien thuat toan co the do ATE/RPE dung nghia - dieu se khong lam duoc sau nay.
luong nao (EKF, slam_core, move_base) subscribe no.
============ CACH DUNG ============
# Ghi lai trong luc chay
rosrun slam_eval eval_ate.py --out results/run1
# Chay o terminal RIENG, trong khi mapping.launch dang chay.
# Ctrl-C de dung -> in ket qua.
rosrun slam_eval eval_ate.py --out results/house1
# Ket qua: in ATE ra man hinh + xuat 2 file TUM cho evo
evo_ape tum results/run1_gt.tum results/run1_est.tum -va --plot
evo_rpe tum results/run1_gt.tum results/run1_est.tum -r trans_part --delta 1 --delta_unit m
evo_ape tum results/house1_gt.tum results/house1_est.tum -va --plot
evo_rpe tum results/house1_gt.tum results/house1_est.tum -r trans_part --delta 1 --delta_unit m
============ ⚠️ NGUON UOC LUONG ============
Mac dinh --est=tf, doc TF map -> base_footprint.
KHONG dung /slam/pose lam mac dinh nua: do la topic cua slam_core, ma slam_core
bi TAT khi RTAB-Map so huu canh map->odom (xem ghi chu dau rtabmap.launch).
Dat mac dinh do lam cong cu nay chay ma khong bao gio ghep duoc cap nao.
TF map->base_footprint la nguon dung cho MOI backend - RTAB-Map, slam_core,
AMCL - nen khong phai sua lai khi doi thuat toan.
"""
import argparse
@@ -30,6 +41,7 @@ import os
import sys
import rospy
import tf2_ros
from nav_msgs.msg import Odometry
from geometry_msgs.msg import PoseWithCovarianceStamped
@@ -47,18 +59,55 @@ def yaw_from_quat(q):
class Recorder(object):
def __init__(self, gt_topic, est_topic, out_prefix, max_dt):
def __init__(self, gt_topic, est_src, out_prefix, max_dt,
map_frame='map', base_frame='base_footprint', tf_rate=20.0):
self.gt = [] # (t, x, y, yaw)
self.est = []
self.out_prefix = out_prefix
self.max_dt = max_dt
rospy.Subscriber(gt_topic, Odometry, self.on_gt, queue_size=200)
rospy.Subscriber(est_topic, PoseWithCovarianceStamped, self.on_est, queue_size=200)
rospy.loginfo('eval_ate: gt=%s est=%s', gt_topic, est_topic)
if est_src == 'tf':
# ============ VI SAO MAC DINH LA TF ============
# Trong luong RTAB-Map, KHONG co node nao publish /slam/pose - do la
# topic cua slam_core, ma slam_core bi tat khi RTAB-Map so huu canh
# map->odom (xem ghi chu dau rtabmap.launch).
#
# Uoc luong cua SLAM nam o TF map -> base_footprint. Day la nguon
# dung cho MOI backend: RTAB-Map, slam_core, hay AMCL sau nay.
self.buf = tf2_ros.Buffer()
self.listener = tf2_ros.TransformListener(self.buf)
self.map_frame = map_frame
self.base_frame = base_frame
self.n_tf_fail = 0
self.timer = rospy.Timer(rospy.Duration(1.0 / tf_rate), self.on_tf)
rospy.loginfo('eval_ate: gt=%s est=TF %s -> %s @ %.0f Hz',
gt_topic, map_frame, base_frame, tf_rate)
else:
rospy.Subscriber(est_src, PoseWithCovarianceStamped,
self.on_est, queue_size=200)
rospy.loginfo('eval_ate: gt=%s est=%s', gt_topic, est_src)
rospy.loginfo('eval_ate: Ctrl-C de dung va tinh ket qua.')
def on_tf(self, _evt):
try:
tr = self.buf.lookup_transform(self.map_frame, self.base_frame,
rospy.Time(0), rospy.Duration(0.05))
except (tf2_ros.LookupException, tf2_ros.ExtrapolationException,
tf2_ros.ConnectivityException):
self.n_tf_fail += 1
if self.n_tf_fail in (20, 200):
rospy.logwarn('eval_ate: chua tra duoc TF %s -> %s (%d lan)',
self.map_frame, self.base_frame, self.n_tf_fail)
return
# Dung dung timestamp CUA TF, khong dung Time.now(), de ghep cap chuan.
self.est.append((tr.header.stamp.to_sec(),
tr.transform.translation.x,
tr.transform.translation.y,
yaw_from_quat(tr.transform.rotation)))
def on_gt(self, msg):
p = msg.pose.pose
self.gt.append((msg.header.stamp.to_sec(), p.position.x, p.position.y,
@@ -184,14 +233,21 @@ class Recorder(object):
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--gt', default='/ground_truth/odom')
parser.add_argument('--est', default='/slam/pose')
parser.add_argument('--est', default='tf',
help="'tf' (mac dinh, doc TF map->base_footprint - dung "
"cho RTAB-Map) hoac ten topic PoseWithCovarianceStamped")
parser.add_argument('--map-frame', default='map')
parser.add_argument('--base-frame', default='base_footprint')
parser.add_argument('--tf-rate', type=float, default=20.0)
parser.add_argument('--out', default='results/run')
parser.add_argument('--max-dt', type=float, default=0.05,
help='lech timestamp toi da khi ghep cap (s)')
args, _ = parser.parse_known_args()
rospy.init_node('eval_ate', anonymous=True)
rec = Recorder(args.gt, args.est, args.out, args.max_dt)
rec = Recorder(args.gt, args.est, args.out, args.max_dt,
map_frame=args.map_frame, base_frame=args.base_frame,
tf_rate=args.tf_rate)
rospy.on_shutdown(rec.report)
rospy.spin()