fix ghost target
This commit is contained in:
1 parent
31c9d332ba
commit
bf0efba9dc
3 files changed
+90
-32
No files matched your search
Binary file not shown.
@@ -135,21 +135,39 @@ class RadarState:
|
||||
self.target_count = frame.get("target_count", 0)
|
||||
now = time.time()
|
||||
|
||||
# Belt-and-suspenders physical-limits filter. The ESP32 side
|
||||
# should already have gated these, but in case old firmware is
|
||||
# still running or an ACK frame leaks through, we re-apply the
|
||||
# same sanity rules on the Orange Pi side:
|
||||
# Y in front of radar (y >= 1 mm), <= 6000 mm rated range
|
||||
# |X| <= 6000 mm (±60° cone + safety margin)
|
||||
PHYS_Y_MIN = 1
|
||||
PHYS_Y_MAX = 6000
|
||||
PHYS_X_ABS = 6000
|
||||
valid_targets_this_frame = 0
|
||||
|
||||
targets_data = frame.get("targets", [])
|
||||
for t_data in targets_data:
|
||||
slot = t_data.get("id", 0)
|
||||
if 1 <= slot <= 3:
|
||||
t = self.targets[slot - 1]
|
||||
t.slot = slot
|
||||
t.valid = t_data.get("valid", False)
|
||||
t.x_mm = t_data.get("x", 0)
|
||||
t.y_mm = t_data.get("y", 0)
|
||||
t.speed_cm_s = t_data.get("speed", 0)
|
||||
t.valid = bool(t_data.get("valid", False))
|
||||
t.x_mm = int(t_data.get("x", 0))
|
||||
t.y_mm = int(t_data.get("y", 0))
|
||||
t.speed_cm_s = int(t_data.get("speed", 0))
|
||||
|
||||
# If ESP32 parser already gives distance/angle, use them
|
||||
t.distance_mm = float(t_data.get("distance", 0.0))
|
||||
t.angle_deg = float(t_data.get("angle", 0.0))
|
||||
|
||||
# Sanity overrides: strip validity if coordinates lie
|
||||
# outside the radar's measurable physical envelope.
|
||||
y_ok = PHYS_Y_MIN <= t.y_mm <= PHYS_Y_MAX
|
||||
x_ok = -PHYS_X_ABS <= t.x_mm <= PHYS_X_ABS
|
||||
if not (y_ok and x_ok):
|
||||
t.valid = False
|
||||
|
||||
# Derive distance / angle if missing, for convenience
|
||||
if t.valid and (t.distance_mm == 0 or t.angle_deg == 0):
|
||||
t.distance_mm = math.hypot(t.x_mm, t.y_mm)
|
||||
@@ -158,7 +176,11 @@ class RadarState:
|
||||
|
||||
if t.valid:
|
||||
t.last_seen = now
|
||||
valid_targets_this_frame += 1
|
||||
|
||||
# Keep the browser-side counters honest even if the ESP32 told
|
||||
# us a target_count that included the now-filtered ACK ghost.
|
||||
self.target_count = valid_targets_this_frame
|
||||
self.frames_received += 1
|
||||
self.last_update = now
|
||||
|
||||
|
||||
Reference in new issue
Block a user