把靶子类型判断拉到了最前面

This commit is contained in:
yrx
2026-05-22 11:02:49 +08:00
parent 46508e4b31
commit 575e690868

View File

@@ -466,6 +466,27 @@ def process_shot(adc_val):
if _timing_on and _t_sample is not None:
_t_sample_ms = (time_std.perf_counter() - _t_sample) * 1000.0
# 采样提前完成后,先确定靶型对应的物理半径,供后续距离/偏移/上报使用。
# 40cm_black 表示直径40cm半径20cm20cm 表示直径20cm半径10cm。
target_radius_cm = 20.0 if sample_target_type == "40cm_black" else (10.0 if sample_target_type == "20cm" else 20.0)
target_type_value = 40 if sample_target_type == "40cm_black" else (20 if sample_target_type == "20cm" else None)
# 圆心分支原算法默认按40cm靶半径20cm换算若采样判定为20cm靶在上报前修正距离和偏移。
# 三角分支使用 triangle_positions.json 的物方坐标,不在这里二次缩放,避免影响三角单应性结果。
if sample_target_type == "20cm" and center and radius and not tri_markers:
try:
distance_m = (target_radius_cm * config.FOCAL_LENGTH_PIX) / float(radius) / 100.0
_scale = target_radius_cm / 20.0
if dx is not None:
dx = float(dx) * _scale
if dy is not None:
dy = float(dy) * _scale
if logger:
logger.info(f"[采样] 20cm靶修正圆心测距/偏移: distance={distance_m:.2f}m scale={_scale:.2f}")
except Exception as _e_fix:
if logger:
logger.warning(f"[采样] 20cm靶修正失败: {_e_fix}")
# 三角形路径成功时 center/radius 为空是正常的;此时用 triangle 方法名用于保存文件名与上报字段 m
if (not method) and tri_markers:
method = "triangle_homography"
@@ -496,7 +517,7 @@ def process_shot(adc_val):
"shot_id": shot_id,
"x": srv_x,
"y": srv_y,
"r": 20.0, # 保留字段(服务端当前忽略,物理外环半径 cm
"r": target_radius_cm, # 物理靶半径 cm40cm靶=2020cm靶=10
"d": round((distance_m or 0.0) * 100),
"d_laser": round((laser_distance_m or 0.0) * 100),
"d_laser_quality": laser_signal_quality,
@@ -507,7 +528,7 @@ def process_shot(adc_val):
"target_y": float(y),
"offset_method": offset_method,
"distance_method": distance_method,
"target_type": 40 if sample_target_type == "40cm_black" else (20 if sample_target_type == "20cm" else None),
"target_type": target_type_value,
}
if ellipse_params: