Wait for the detection to converge instead of judging it once

The gate used to fire at settle_delay + sample_window and abort, throwing away
whatever remained of the timeout. Four field runs failed there with spreads
between 1.3 m and 3.2 m while the detector reported the pallet to within a
millimetre, and a retry seconds later at the same spot succeeded - the
detection needed longer to settle than the window allowed, and the handler was
not willing to wait.

samples_ is now a sliding window of sample_window seconds: each tick adds the
new sample and drops the expired ones. Once the window is full the spread is
evaluated every tick, and a spread over the limit only means "not yet" - the
handler keeps sampling until it converges or the timeout runs out. The timeout
becomes the real deadline instead of the window.

hold_time requires the spread to stay under the limit for that long before the
result is published, so a momentarily quiet window cannot be mistaken for a
settled one. 0 keeps the previous behaviour of publishing on the first good
window.

Convergence is logged once a second, not per tick, so it is possible to see
whether the sample set is tightening without drowning a 30 Hz loop. median and
robustSpread now take their buffer by reference and sort it in place, since
they run on every tick rather than once per detection.
This commit is contained in:
2026-08-13 22:46:19 +07:00
parent 643f63f906
commit 5d878a78e1
3 changed files with 498 additions and 151 deletions

View File

@@ -71,6 +71,21 @@ actions_detect:
handlers:
- {name: detect, type: FrameSamplerActionHandler}
detect:
action_types: [DetectCharger]
output_frame: dock_target
settle_delay: 0.2 # [s]
sample_window: 1.0 # [s] độ dài cửa sổ trượt
min_samples: 10 # số mẫu tối thiểu TRONG cửa sổ
max_spread_xy: 0.03 # [m]
max_spread_yaw: 0.05 # [rad]
timeout: 5.0 # [s] hết giờ mà chưa cửa sổ nào đạt -> kFailed
# hold_time > 0: cửa sổ phải giữ trạng thái đạt liên tục mới được chốt. Chặn cửa sổ tình cờ chụm
# giữa lúc dò đang dao động.
actions_detect_hold:
handlers:
- {name: detect, type: FrameSamplerActionHandler}
detect:
action_types: [DetectCharger]
output_frame: dock_target
@@ -79,6 +94,7 @@ actions_detect:
min_samples: 10
max_spread_xy: 0.03 # [m]
max_spread_yaw: 0.05 # [rad]
hold_time: 0.5 # [s]
timeout: 5.0 # [s]
# output_frame trùng input_frame -> configure() phải từ chối.