update 加入并行拍照,加入平滑

This commit is contained in:
FrankCV2048
2024-12-16 20:58:14 +08:00
parent 2c6539ef51
commit ef34f25020
5 changed files with 81 additions and 23 deletions

View File

@ -34,8 +34,8 @@ class Catch:
if Constant.Debug or self.robotClient.check_outputQ(self.robotClient.con_ios[1]) and not self.robotClient.check_outputQ(self.robotClient.con_ios[0]):
self.catch_status = CatchStatus.COk
if self.catch_status == CatchStatus.CShake:
if not self.shake_continue.Q(True, 2000):
shakeQ = self.shakePulse.Q(True, 100, 100)
if not self.shake_continue.Q(True, 1500):
shakeQ = self.shakePulse.Q(True, 50, 50)
self.robotClient.sendIOControl(self.robotClient.con_ios[2], 1 if shakeQ else 0)
print("正在震动" if shakeQ else "震动结束")
else:

40
CU/Detect.py Normal file
View File

@ -0,0 +1,40 @@
from enum import Enum
import Constant
from Model.Position import Real_Position
from Trace.handeye_calibration import getPosition
from Util.util_time import CClockPulse, CTon
class DetectStatus(Enum):
DNone = 0
DDetect = 1
DOk = 2
class Detect:
def __init__(self,detection):
self.detection = detection
self.detect_status = DetectStatus.DNone
self.detect_position = None
def run(self):
if self.detect_status == DetectStatus.DNone:
return
if self.detect_status == DetectStatus.DDetect:
_, img, xyz, uvw, points = self.detection.get_position(Point_isVision=False, Box_isPoint=True,
First_Depth=True, Iter_Max_Pixel=30,
save_img_point=0, Height_reduce=30, width_reduce=30)
self.detection_image = img.copy()
if xyz == None or uvw == None or points == None:
self.detect_position = None
self.detect_status = DetectStatus.DOk
return
target_position, noraml_base = getPosition(*xyz, *uvw, None, points)
position = Real_Position().init_position(*target_position[:3], *noraml_base[:3])
position.Z = position.Z + 200
self.detect_position = position
self.detect_status = DetectStatus.DOk
if self.detect_status == DetectStatus.DOk:
return

View File

@ -1,5 +1,6 @@
import copy
import logging
import threading
import time
import cv2
@ -9,6 +10,7 @@ from PySide6.QtCore import Signal, QObject
import Constant
import Expection
from CU.Catch import Catch, CatchStatus
from CU.Detect import Detect, DetectStatus
from Model.FeedModel import PositionModel
from Model.Position import Real_Position, Detection_Position
from enum import Enum, IntEnum
@ -185,6 +187,9 @@ class Feeding(QObject):
self.pos_index = -1
self.pos_near_index = -1
self.catch = Catch(self.robotClient)
self.detect = Detect(self.detection)
self.detect_thread_img = threading.Thread(target=self.detect.run)
self.detect_thread_img.start()
pass
def init_detection_image(self):
@ -258,12 +263,11 @@ class Feeding(QObject):
return
self.feedConfig.feedLine.get_position_list()
self.detect.detect_status = DetectStatus.DNone
# = self.detection.get_position(Point_isVision=False, Box_isPoint=True, First_Depth=True, Iter_Max_Pixel=30,
# # save_img_point=0, Height_reduce=30, width_reduce=30)
if self.feedConfig.feedLine.get_take_position().get_position() != None:
self.feedConfig.feedLine.set_take_position(self.get_take_position())
# TODO 获取目标位置
#
self.feed_Mid_Status = FeedMidStatus.FMid_Start
@ -291,7 +295,17 @@ class Feeding(QObject):
if self.robotClient.type_detection == DetectType.EyeOutHand:
self.feed_Mid_Status = FeedMidStatus.FMid_Feed
self.next_position()
if self.detect.detect_status == DetectStatus.DNone:
self.detect.detect_status = DetectStatus.DDetect
elif self.detect.detect_status == DetectStatus.DOk:
if self.detect.detect_position != None:
log.log_message(logging.INFO, Constant.str_feed_takePhoto_success)
self.feedConfig.feedLine.set_take_position(self.detect.detect_position)
self.next_position()
self.detect.detect_status = DetectStatus.DNone
else:
log.log_message(logging.ERROR, Constant.str_feed_takePhoto_fail)
self.take_no_photo_sigal.emit()
return
detect_pos_list = []
if not Constant.Debug:
@ -386,10 +400,11 @@ class Feeding(QObject):
else:
log.log_message(logging.ERROR, Constant.str_feed_takePhoto_fail)
# self.take_no_photo = True
self.take_no_photo_sigal.emit()
# 继续获取图像
# TODO
self.feedConfig.feedLine.set_take_position(self.get_take_position())
# self.feedConfig.feedLine.set_take_position(self.get_take_position())
@ -437,7 +452,9 @@ class Feeding(QObject):
self.catch.catch_status = CatchStatus.CNone
time.sleep(self.robotClient.time_delay_put)
# self.detection.get_position(Point_isVision=False, Box_isPoint=True, First_Depth=True, Iter_Max_Pixel=30, save_img_point=0, Height_reduce=30, width_reduce=30)
self.feedConfig.feedLine.set_take_position(self.get_take_position())
# self.feedConfig.feedLine.set_take_position(self.get_take_position())
if self.detect.detect_status == DetectStatus.DNone:
self.detect.detect_status = DetectStatus.DDetect
self.feedConfig.num = self.feedConfig.num - 1
log.log_message(logging.INFO, f'{Constant.str_feed_feed_num}{self.feedConfig.num}')
self.next_position()
@ -607,6 +624,7 @@ class Feeding(QObject):
position_instruction.m3 = real_position.U
position_instruction.m4 = real_position.V
position_instruction.m5 = real_position.W
position_instruction.smooth = 4
position_instruction.action = move_type.value
if position_instruction.action == 17:
@ -636,18 +654,18 @@ class Feeding(QObject):
self.robotClient.add_sendQuene(request_command)
pass
def get_take_position(self):
if Constant.Debug:
return self.robotClient.status_model.getRealPosition()
_, img, xyz, uvw, points = self.detection.get_position(Point_isVision=False, Box_isPoint=True, First_Depth=True, Iter_Max_Pixel=30,save_img_point=0, Height_reduce=30, width_reduce=30)
self.detection_image = img.copy()
if xyz ==None or uvw==None or points==None:
return None
target_position,noraml_base = getPosition(*xyz,*uvw,None,points)
position = Real_Position().init_position(*target_position[:3],*noraml_base[:3])
position.Z = position.Z+200
return position
# def get_take_position(self):
# if Constant.Debug:
# return self.robotClient.status_model.getRealPosition()
# _, img, xyz, uvw, points = self.detection.get_position(Point_isVision=False, Box_isPoint=True, First_Depth=True, Iter_Max_Pixel=30,save_img_point=0, Height_reduce=30, width_reduce=30)
# self.detection_image = img.copy()
# if xyz ==None or uvw==None or points==None:
# return None
# target_position,noraml_base = getPosition(*xyz,*uvw,None,points)
#
# position = Real_Position().init_position(*target_position[:3],*noraml_base[:3])
# position.Z = position.Z+200
# return position
def next_start(self,reverse=False):
start_pos = self.feedConfig.feedLine.get_next_start_position(reverse)
self.feedStatus = FeedStatus(start_pos.status) if self.feedStatus != FeedStatus.FNone else FeedStatus.FNone