写NG流程:添加光纤传感器线程和双压传感器线程

This commit is contained in:
2026-01-08 18:09:22 +08:00
parent 2de3857d1c
commit 8821b30689
5 changed files with 437 additions and 23 deletions

View File

@ -10,41 +10,72 @@ import multiprocessing # 多进程模块
import threading
from threading import Event
import time
from EMV import sensor_triggered, global_relay, control_solenoid
from visual_algorithm import flaw_detection
from EMV.EMV_test import press_sensors_triggered, control_solenoid, global_relay
from visual_algorithm.visual_algorithm import flaw_detection
import logging
import os
# ------------ 日志+参数配置 ------------
script_dir = os.path.dirname(os.path.abspath(__file__))
log_file_path = os.path.join(script_dir, "main_control.log")
logging.basicConfig(
level=logging.INFO,
format='[%(asctime)s.%(msecs)03d] [%(levelname)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
handlers=[
logging.StreamHandler(),
logging.FileHandler(log_file_path, encoding='utf-8')
]
)
# ------------全局事件-------------
manger = multiprocessing.Manager()
conveyor_start_event = manger.Event()
def start_thread():
"""开启各种线程"""
global_relay.start_press_sensors_monitor() # 双压传感器监听线程
def stop_thread():
"""关闭各种线程"""
global_relay.stop_press_sensors_monitor() # 双压传感器监听线程
def quality_testing():
print("线条开始质量检测:")
logging.info("线条开始质量检测:")
# 执行质量检测
result = flaw_detection({"line_id": "L001", "straightness": 0.95, "noise_ratio": 0.08})
if result == "qualified":
result = "合格"
print("该线条是否合格:", result)
print("等待线条落到传送带(双压传感器触发)...")
logging.info("该线条是否合格:", result)
logging.info("等待线条落到传送带(双压传感器触发)...")
# 等待时间触发超时时间设为10秒避免无限等待
if sensor_triggered.wait(timeout=10):
print("线条已落到传送带,控制两个传送带向前移动")
if press_sensors_triggered.wait(timeout=10):
logging.info("线条已落到传送带,控制两个传送带向前移动")
# 触发传送带启动事件
conveyor_start_event.set()
else:
print("超时警告:线条未落到传送带,请检查")
logging.info("超时警告:线条未落到传送带,请检查")
elif result == "unqualified":
result = "不合格"
print("该线条是否合格:", result)
print("进入NG动作")
logging.info("该线条是否合格:", result)
logging.info("等待线条落到传送带上")
# 等待时间触发超时时间设为10秒避免无限等待
if press_sensors_triggered.wait(timeout=10):
logging.info("线条已落到传送带")
logging.info("进入NG动作")
control_solenoid() # 执行NG动作,控制电磁阀
print("NG动作结束")
# print("判断NG线条是否落入肥料区")
logging.info("NG动作结束")
# logging.info("判断NG线条是否落入肥料区")
# -----------对外接口-------------
def main_control():
print("始摆放线条")
logging.info("启各种线程")
start_thread()
logging.info("开始摆放线条")
# 质量检测
quality_testing()