This commit is contained in:
gcw_4spBpAfv
2026-02-10 17:52:55 +08:00
parent 573c0a3385
commit 592dc6ceb1
9 changed files with 626 additions and 136 deletions

54
main.py
View File

@@ -88,11 +88,13 @@ def cmd_str():
# 2. 初始化硬件对象UART、I2C、ADC
hardware_manager.init_uart4g()
hardware_manager.init_distance_serial()
hardware_manager.init_bus()
hardware_manager.init_adc()
hardware_manager.init_at_client()
# 3. 初始化激光模块(串口 + 开机关闭激光防误触发)
laser_manager.init()
# 3. 初始化 INA226 电量监测芯片
init_ina226()
@@ -109,6 +111,9 @@ def cmd_str():
logger_manager.init_logging(log_level=logging.DEBUG)
logger = logger_manager.logger
# 补充:因为初始化的时候,激光会亮,先关了它
# laser_manager.turn_off_laser()
# 2. 从4G模块同步系统时间需要 at_client 已初始化)
sync_system_time_from_4g()
@@ -334,7 +339,8 @@ def cmd_str():
# 检测靶心
result_img, center, radius, method, best_radius1, ellipse_params = detect_circle_v3(frame, laser_point)
camera_manager.show(result_img)
if config.SHOW_CAMERA_PHOTO_WHILE_SHOOTING:
camera_manager.show(result_img)
# 计算偏移与距离(如果检测到靶心)
if center and radius:
@@ -375,21 +381,7 @@ def cmd_str():
from shot_id_generator import shot_id_generator
shot_id = shot_id_generator.generate_id() # 不需要使用device_id
if logger:
logger.info(f"[MAIN] 射箭ID: {shot_id}")
# 保存图像(无论是否检测到靶心都保存):放入队列由 worker 异步保存,不阻塞主循环
enqueue_save_shot(
result_img,
center,
radius,
method,
ellipse_params,
(x, y),
distance_m,
shot_id=shot_id,
photo_dir=config.PHOTO_DIR if config.SAVE_IMAGE_ENABLED else None,
)
# 构造上报数据
inner_data = {
@@ -426,14 +418,30 @@ def cmd_str():
report_data = {"cmd": 1, "data": inner_data}
network_manager.safe_enqueue(report_data, msg_type=2, high=True)
if logger:
if center and radius:
logger.info(f"射箭事件已加入发送队列已检测到靶心ID: {shot_id}")
else:
logger.info(f"射箭事件已加入发送队列未检测到靶心已保存图像ID: {shot_id}")
# 闪一下激光(射箭反馈)
laser_manager.flash_laser(1000)
if config.FLASH_LASER_WHILE_SHOOTING:
laser_manager.flash_laser(config.FLASH_LASER_DURATION_MS)
# 保存图像(无论是否检测到靶心都保存):放入队列由 worker 异步保存,不阻塞主循环
enqueue_save_shot(
result_img,
center,
radius,
method,
ellipse_params,
(x, y),
distance_m,
shot_id=shot_id,
photo_dir=config.PHOTO_DIR if config.SAVE_IMAGE_ENABLED else None,
)
if center and radius:
logger.info(f"射箭事件已加入发送队列已检测到靶心ID: {shot_id}")
else:
logger.info(f"射箭事件已加入发送队列未检测到靶心已保存图像ID: {shot_id}")
time.sleep_ms(100)
except Exception as e: