This commit is contained in:
yrx
2026-09-01 11:48:26 +08:00
parent 179b30a944
commit ffeb82cf8f
17 changed files with 130 additions and 39 deletions
+19 -18
View File
@@ -171,8 +171,10 @@ def cmd_str():
and bool(getattr(config, "TARGET_CLASS_YOLO_PRELOAD_ON_BOOT", True))
)
_preload_yolo = _preload_yolo or _need_black_preload or _need_target_preload
if _preload_yolo:
if _preload_yolo and not os.path.exists(f"{config.APP_DIR}/ota_pending.json"):
preload_yolo_detector(logger)
elif _preload_yolo and logger:
logger.warning("[YOLO] ota_pending.json found; skip model preload until rollback check")
except Exception as e:
if logger:
logger.warning(f"[YOLO-ROI] 启动预加载异常(不影响后续射箭): {e}")
@@ -254,7 +256,11 @@ def cmd_str():
network_manager.read_device_id()
# 5. 创建照片存储目录(如果启用图像保存或检测失败时强制保存)
if config.SAVE_IMAGE_ENABLED or getattr(config, "SAVE_IMAGE_ON_FAILURE", False):
if (
config.SAVE_IMAGE_ENABLED
or getattr(config, "SAVE_IMAGE_ON_FAILURE", False)
or getattr(config, "SAVE_RAW_IMAGE_ENABLED", False)
):
photo_dir = config.PHOTO_DIR
if photo_dir not in os.listdir("/root"):
try:
@@ -286,12 +292,13 @@ def cmd_str():
logger.info("系统准备完成...")
last_adc_trigger = 0
trigger_adc_val = 0 # 触发时的气压值,气压需降回此值以下才能再次触发
enable_check = True
# 读取一次ADC初始值,防止开机时传感器已有压力导致误触发
try:
last_adc_val = hardware_manager.adc_obj.read()
except Exception:
last_adc_val = 0
peak_adc_val = 0 # 当前周期内的压力峰值
# 气压采样:减少日志频率(每 N 个点输出一条),避免 logger.debug 拖慢采样
PRESSURE_BATCH_SIZE = 100
@@ -381,22 +388,16 @@ def cmd_str():
pressure_max = adc_val
if len(pressure_buf) >= PRESSURE_BATCH_SIZE:
_flush_pressure_buf("batch")
# 峰值检测:压力从峰值下降时触发,确保捕获到最大冲击时刻
if adc_val > peak_adc_val:
peak_adc_val = adc_val # 更新峰值
if (peak_adc_val >= config.ADC_TRIGGER_THRESHOLD
and adc_val < peak_adc_val
and last_adc_val >= peak_adc_val):
# 封顶后下降沿触发:peak是最大值,当前值开始下降,且上次值还在peak位置
# 突变增量检测:压力增量大于500时触发。
# 触发后需等气压降回触发点以下,才重新允许下一次触发。
if adc_val < trigger_adc_val:
enable_check = True
if (adc_val - last_adc_val) > 500 and enable_check:
hardware_manager.start_idle_timer() # 重新计时
diff_ms = current_time - last_adc_trigger
if diff_ms < 3000:
peak_adc_val = 0 # 去抖期间重置峰值
time.sleep_ms(5)
continue
last_adc_trigger = current_time
peak_adc_val = 0 # 触发后重置峰值
# 触发前先把缓存刷出来,避免波形被长耗时处理截断
trigger_adc_val = adc_val # 记录触发点
last_adc_val = adc_val # 更新基准,防止连续增量重复触发
enable_check = False
_flush_pressure_buf("before_trigger")
try:
@@ -415,7 +416,7 @@ def cmd_str():
camera_manager.show(camera_manager.read_frame())
except Exception as e:
pass
time.sleep_ms(5)
time.sleep_ms(1)
last_adc_val = adc_val
except Exception as e: