fix: 压力改为增量触发
This commit is contained in:
@@ -287,7 +287,6 @@ def cmd_str():
|
||||
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
|
||||
|
||||
@@ -377,22 +376,14 @@ 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位置
|
||||
# 突变增量检测:压力增量大于300时触发
|
||||
if (adc_val - last_adc_val) > 300:
|
||||
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 # 触发后重置峰值
|
||||
# 触发前先把缓存刷出来,避免波形被长耗时处理截断
|
||||
_flush_pressure_buf("before_trigger")
|
||||
|
||||
try:
|
||||
@@ -411,7 +402,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:
|
||||
|
||||
Reference in New Issue
Block a user