update 更新表格处理,更新添加自由路径,更新了重连机制
This commit is contained in:
@ -34,6 +34,7 @@ class RobotClient(TCPClient):
|
||||
self.debug_speed = 10
|
||||
self.feed_speed = 10
|
||||
self.reset_speed = 10
|
||||
self.max_angle_interval = 0
|
||||
def add_sendQuene(self,command): #后面 命令分等级,紧急命令直接执行
|
||||
self.command_quene.put(command)
|
||||
|
||||
@ -42,13 +43,10 @@ class RobotClient(TCPClient):
|
||||
def send_Command(self):
|
||||
try:
|
||||
if self.command_quene.qsize()!=0:
|
||||
|
||||
command = self.command_quene.get()
|
||||
self.client_socket.send(command.encode())
|
||||
|
||||
if True:
|
||||
response = self.client_socket.recv(1024).decode('utf-8')
|
||||
|
||||
# response_message = json.loads(response)
|
||||
return True
|
||||
else:
|
||||
@ -98,7 +96,7 @@ class RobotClient(TCPClient):
|
||||
log.log_message(logging.WARNING,Constant.str_sys_json_error+response)
|
||||
return True
|
||||
except Exception as e:
|
||||
log.log_message(logging.ERROR,f'{e}')
|
||||
log.log_message(logging.ERROR,f'{e}{response}')
|
||||
raise
|
||||
|
||||
def send_emergency_sound(self):
|
||||
@ -127,7 +125,7 @@ class RobotClient(TCPClient):
|
||||
return False
|
||||
|
||||
def get_origin_position(self):
|
||||
return self.status_model.getRealPosition()
|
||||
return self.origin_position
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -14,9 +14,11 @@ class TCPClient:
|
||||
self.port = port
|
||||
self.thread_signal = True
|
||||
self.connected = False
|
||||
|
||||
self.client_socket = None
|
||||
|
||||
def CreatConnect(self):
|
||||
if self.client_socket:
|
||||
self.client_socket.close()
|
||||
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.client_socket.settimeout(5)
|
||||
self.client_socket.connect((self.IPAddress, self.port))
|
||||
|
||||
@ -46,6 +46,7 @@ class LineType(Enum):
|
||||
Straight = 0
|
||||
CureMid = 2
|
||||
CureEnd = 3
|
||||
WORLD = 4
|
||||
|
||||
|
||||
class FeedMidStatus(Enum):
|
||||
@ -649,6 +650,12 @@ class Feeding(QObject):
|
||||
start_pos1 = self.feedConfig.feedLine.get_next_start_position(reverse)
|
||||
self.feedStatus = FeedStatus(start_pos1.status) if self.feedStatus != FeedStatus.FNone else FeedStatus.FNone
|
||||
self.sendTargPosition(real_position=start_pos.get_position(),speed=self.robotClient.debug_speed, move_type=MoveType.Cure, real_position1=start_pos1.get_position())
|
||||
elif start_pos.lineType == LineType.WORLD.value:
|
||||
if self.robotClient.status_model.getAnglePosition().is_error_angel_move(start_pos.get_position(),self.robotClient.max_angle_interval):
|
||||
self.feedStatus = None
|
||||
log.log_message(logging.ERROR, Constant.str_feed_angle_error)
|
||||
else:
|
||||
self.sendTargPosition(real_position=start_pos.get_position(),speed=self.robotClient.debug_speed,move_type=MoveType.WORLD)
|
||||
else:
|
||||
self.sendTargPosition(real_position=start_pos.get_position(),speed=self.robotClient.debug_speed)
|
||||
pass
|
||||
|
||||
@ -60,6 +60,7 @@ str_feed_shake = '摇摆'
|
||||
str_feed_start_error = '请先复位到原点'
|
||||
str_feed_return_original_position_fail = '机械臂未按照实际路线点移动,未能寻找到适配路径点位'
|
||||
str_feed_reset_no_line_error = '未定义的线段'
|
||||
str_feed_angle_error = '角度差距过大,停止运行'
|
||||
str_sys_start = '进入系统'
|
||||
str_sys_exit = '退出系统'
|
||||
str_sys_switch_tool = '切换到工具坐标'
|
||||
@ -76,6 +77,7 @@ str_sys_set_error = '保存设置失败'
|
||||
str_sys_log_IO_error = 'IO更新失败'
|
||||
str_sys_log_alarm_error = '发生报警:'
|
||||
str_sys_log_move_error = '请填写全部坐标'
|
||||
str_sys_set_position_error = '未选中行'
|
||||
str_tcp_robot_connect_fail = '连接失败'
|
||||
str_tcp_robot_connect_success = '连接成功'
|
||||
str_tcp_robot_data_error = '数据解析错误'
|
||||
|
||||
@ -18,6 +18,18 @@ class Position:
|
||||
else:
|
||||
return False
|
||||
pass
|
||||
|
||||
def is_error_angel_move(self,position,interval):
|
||||
if self.X - position.X >= interval or \
|
||||
self.Y - position.Y >= interval or \
|
||||
self.Z - position.Z >= interval or \
|
||||
self.U - position.U >= interval or \
|
||||
self.V - position.V >= interval or \
|
||||
self.W - position.W >= interval:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
pass
|
||||
"""
|
||||
摄像头识别位置和角度
|
||||
"""
|
||||
|
||||
@ -77,6 +77,9 @@ class DataAddress:
|
||||
real_position = Real_Position().init_position(self.world_0,self.world_1,self.world_2,self.world_3,self.world_4,self.world_5)
|
||||
return real_position
|
||||
|
||||
def getAnglePosition(self):
|
||||
real_position = Real_Position().init_position(self.axis_0,self.axis_1,self.axis_2,self.axis_3,self.axis_4,self.axis_5)
|
||||
return real_position
|
||||
def get_IO_bits(self):
|
||||
io_bits_str = format(self.output_n, '032b')[::-1]
|
||||
io_bits_arry = [bit == '1' for bit in io_bits_str]
|
||||
|
||||
@ -54,6 +54,7 @@ io_shake_addr = 10
|
||||
takedelay = 0.2
|
||||
putdelay = 0.1
|
||||
shakedelay = 1.0
|
||||
max_angle_interval=20
|
||||
|
||||
[Speed]
|
||||
debug_speed = 50
|
||||
|
||||
@ -1,11 +1,25 @@
|
||||
import logging
|
||||
|
||||
import PySide6
|
||||
import cv2
|
||||
from PIL.ImageQt import QImage, QPixmap
|
||||
from PyQt5.QtGui import QImage, QPixmap
|
||||
|
||||
from Util.util_log import log
|
||||
|
||||
|
||||
def cv2_to_qpixmap(cv_img):
|
||||
"""将OpenCV图像转换为QPixmap"""
|
||||
cv_img = cv2.cvtColor(cv_img, cv2.COLOR_BGR2RGB)
|
||||
height, width, channel = cv_img.shape
|
||||
if cv_img.shape !=3:
|
||||
print("cv_img.shape !=3")
|
||||
return None
|
||||
try:
|
||||
img = cv_img.copy()
|
||||
height, width, channel = img.shape
|
||||
bytes_per_line = 3 * width
|
||||
q_img = QImage(cv_img.data, width, height, bytes_per_line, QImage.Format_RGB888)
|
||||
q_img = QImage(img.data, width, height, bytes_per_line, QImage.Format_RGB888)
|
||||
return QPixmap.fromImage(q_img)
|
||||
except Exception as e:
|
||||
log.log_message(logging.ERROR, e)
|
||||
return None
|
||||
|
||||
|
||||
|
||||
17
main.py
17
main.py
@ -415,7 +415,17 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.table_line_changed = True
|
||||
|
||||
def tabel_get_position(self,row_i):
|
||||
self.set_position_tabel(row_i,self.status_address.getRealPosition())
|
||||
if self.tableWidget_line_positions.currentRow()==-1:
|
||||
QMessageBox.information(self, "提示", Constant.str_sys_set_position_error)
|
||||
return
|
||||
|
||||
row_i = self.tableWidget_line_positions.currentRow()
|
||||
combox_line_type = self.tableWidget_line_positions.cellWidget(row_i, 7)
|
||||
lineType = combox_line_type.currentData()
|
||||
if lineType == 4:
|
||||
self.set_position_tabel(row_i, self.status_address.getAnglePosition())
|
||||
else:
|
||||
self.set_position_tabel(row_i, self.status_address.getRealPosition())
|
||||
self.table_line_changed = True
|
||||
|
||||
def tabel_delete_position(self,row_i):
|
||||
@ -429,6 +439,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
combox_lineType.addItem("直线",0)
|
||||
combox_lineType.addItem("曲线中间点",2)
|
||||
combox_lineType.addItem("曲线终点",3)
|
||||
combox_lineType.addItem("自由路径",4)
|
||||
combox_lineType.setCurrentIndex(combox_lineType.findData(position_model.lineType))
|
||||
combox_lineType.currentIndexChanged.connect(self.send_table_position_status_changed)
|
||||
self.tableWidget_line_positions.setCellWidget(row_i, 7, combox_lineType)
|
||||
@ -461,6 +472,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.table_position_changed = True
|
||||
|
||||
def set_position_tabel(self, row_i, position):
|
||||
|
||||
|
||||
self.tableWidget_line_positions.setItem(row_i, 1, QTableWidgetItem(str(position.X)))
|
||||
self.tableWidget_line_positions.setItem(row_i, 2, QTableWidgetItem(str(position.Y)))
|
||||
self.tableWidget_line_positions.setItem(row_i, 3, QTableWidgetItem(str(position.Z)))
|
||||
@ -615,12 +628,14 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
time_delay_take = float(self.configReader.get('Robot_Feed', 'takeDelay'))
|
||||
time_delay_put = float(self.configReader.get('Robot_Feed', 'putDelay'))
|
||||
time_delay_shake = float(self.configReader.get('Robot_Feed', 'shakeDelay'))
|
||||
max_angle_interval = float(self.configReader.get('Robot_Feed', 'max_angle_interval'))
|
||||
#TODO
|
||||
#dropDelay_time = int(self.configReader.get('Robot_Feed', 'dropDelay_time'))
|
||||
self.robotClient = RobotClient(ip, port, photo_locs, self.command_position_quene, self.status_address,[io_take_addr, io_zip_addr, io_shake_addr],time_delay_take,time_delay_put,time_delay_shake,origin_position)
|
||||
self.robotClient.debug_speed = debug_speed
|
||||
self.robotClient.feed_speed = feed_speed
|
||||
self.robotClient.reset_speed = reset_speed
|
||||
self.robotClient.max_angle_interval = max_angle_interval
|
||||
self.feeding = Feeding(self.robotClient, self.detection) # 临时
|
||||
self.feeding.need_origin_signal.connect(self.show_infomessage_box)
|
||||
self.feeding.take_no_photo_sigal.emit(self.show_no_photo_message_box)
|
||||
|
||||
44
test_ui.py
44
test_ui.py
@ -1,9 +1,39 @@
|
||||
from CU.Feeding import Feeding
|
||||
from Model.Position import Real_Position
|
||||
from Model.RobotModel import MoveType
|
||||
import sys
|
||||
import cv2
|
||||
from PyQt5.QtGui import QImage, QPixmap
|
||||
from PySide6.QtWidgets import QApplication, QLabel, QMainWindow
|
||||
|
||||
feeding = Feeding(None,None)
|
||||
p_mid = Real_Position().init_position(20,20,20,30,20,20)
|
||||
p_end = Real_Position().init_position(30,40,5,30,3,3)
|
||||
|
||||
feeding.sendTargPosition(p_mid,MoveType.Cure,5,p_end)
|
||||
def cv2_to_qimage(cv_img):
|
||||
"""Convert an OpenCV image to QImage."""
|
||||
height, width, channel = cv_img.shape
|
||||
bytes_per_line = 3 * width
|
||||
q_img = QImage(cv_img.data, width, height, bytes_per_line, QImage.Format_BGR888)
|
||||
return q_img
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setWindowTitle("Display Image with PySide6")
|
||||
self.resize(800, 600)
|
||||
|
||||
|
||||
# 使用 OpenCV 读取图像
|
||||
cv_img = cv2.imread("./Image/1.png") # 替换为实际路径
|
||||
img = cv_img.copy()
|
||||
# 转换为 QImage img = cv_img.copy()
|
||||
q_img = cv2_to_qimage(cv_img)
|
||||
|
||||
# 创建 QLabel 并设置图像
|
||||
label = QLabel(self)
|
||||
label.setPixmap(QPixmap.fromImage(q_img))
|
||||
label.setScaledContents(True)
|
||||
label.setGeometry(50, 50, 700, 500) # 调整位置和大小
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
window = MainWindow()
|
||||
window.show()
|
||||
sys.exit(app.exec())
|
||||
|
||||
Reference in New Issue
Block a user