Files
wire_controlsystem/main_control.py

62 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
# @Time : 2025/12/12 11:05
# @Author : reenrr
# @File : main_control.py
# @Desc : 主控程序
'''
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
# ------------全局事件-------------
manger = multiprocessing.Manager()
conveyor_start_event = manger.Event()
def quality_testing():
print("线条开始质量检测:")
# 执行质量检测
result = flaw_detection({"line_id": "L001", "straightness": 0.95, "noise_ratio": 0.08})
if result == "qualified":
result = "合格"
print("该线条是否合格:", result)
print("等待线条落到传送带(双压传感器触发)...")
# 等待时间触发超时时间设为10秒避免无限等待
if sensor_triggered.wait(timeout=10):
print("线条已落到传送带,控制两个传送带向前移动")
# 触发传送带启动事件
conveyor_start_event.set()
else:
print("超时警告:线条未落到传送带,请检查")
elif result == "unqualified":
result = "不合格"
print("该线条是否合格:", result)
print("进入NG动作")
control_solenoid() # 执行NG动作,控制电磁阀
print("NG动作结束")
# print("判断NG线条是否落入肥料区")
# -----------对外接口-------------
def main_control():
print("开始摆放线条")
# 质量检测
quality_testing()
while True: # 防止跳出循环
time.sleep(1)
# ------------测试接口-------------
if __name__ == '__main__':
main_control()