更新界面+更新步进电机bug和达妙电机调试接口
This commit is contained in:
@ -241,7 +241,14 @@ def reset_motor():
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# 首先在吸附位置处进行 设置零点位置
|
# 首先在吸附位置处进行 设置零点位置
|
||||||
set_zero_position()
|
set_zero_position()
|
||||||
|
|
||||||
|
reset_motor()
|
||||||
|
|
||||||
set_dm_motor_speed(30)
|
set_dm_motor_speed(30)
|
||||||
set_ori_position(282.6)
|
set_drop_position(282.6)
|
||||||
|
set_ori_position(-282.6)
|
||||||
|
|
||||||
|
# 起始位置:吸附位置
|
||||||
|
move_to_drop_position()
|
||||||
move_to_ori_position()
|
move_to_ori_position()
|
||||||
|
|
||||||
|
|||||||
@ -195,7 +195,7 @@ def align_wire(speed: int, cycle: float):
|
|||||||
GLOBAL_MOTOR.rotate(pulse_frequency=speed, rounds=cycle, direction=0)
|
GLOBAL_MOTOR.rotate(pulse_frequency=speed, rounds=cycle, direction=0)
|
||||||
time.sleep(5) # 暂停5秒
|
time.sleep(5) # 暂停5秒
|
||||||
# 远离电机方向 顺时针
|
# 远离电机方向 顺时针
|
||||||
GLOBAL_MOTOR.rotate(pulse_frequency=speed,rounds=10.0, direction=1)
|
GLOBAL_MOTOR.rotate(pulse_frequency=speed,rounds=cycle, direction=1)
|
||||||
time.sleep(5) # 暂停5秒
|
time.sleep(5) # 暂停5秒
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|||||||
269
UI/ui_3d.py
269
UI/ui_3d.py
@ -6,24 +6,105 @@
|
|||||||
# @File : 3D.py
|
# @File : 3D.py
|
||||||
# @Desc : 界面上的线条3D显示
|
# @Desc : 界面上的线条3D显示
|
||||||
'''
|
'''
|
||||||
from PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout
|
|
||||||
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg as FigureCanvas
|
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# 线条类型A
|
from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout
|
||||||
class Target3DWidgetA(QWidget):
|
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg as FigureCanvas
|
||||||
def __init__(self, parent=None):
|
import matplotlib.pyplot as plt
|
||||||
|
from PySide6.QtCore import Qt
|
||||||
|
|
||||||
|
|
||||||
|
class Target3DWidget(QWidget):
|
||||||
|
"""
|
||||||
|
3D显示窗口,支持类型A和类型B
|
||||||
|
"""
|
||||||
|
|
||||||
|
VERTICES_A = [
|
||||||
|
# 底部截面(Z=0平面)
|
||||||
|
(0, 3, 0), (100, 3, 0),
|
||||||
|
(100, 3, 0), (100, 0, 0),
|
||||||
|
# 中间截面(Z=0.5平面)
|
||||||
|
(0, 0.5, 0.5), (0, 3, 0.5),
|
||||||
|
(0, 3, 0.5), (100, 3, 0.5),
|
||||||
|
(100, 3, 0.5), (100, 0.5, 0.5),
|
||||||
|
(100, 0.5, 0.5), (0, 0.5, 0.5),
|
||||||
|
# 顶部界面(Z=2平面)
|
||||||
|
(0, 0, 2), (0, 0.5, 2),
|
||||||
|
(0, 0.5, 2), (100, 0.5, 2),
|
||||||
|
(100, 0.5, 2), (100, 0, 2),
|
||||||
|
(100, 0, 2), (0, 0, 2),
|
||||||
|
# z方向的连线
|
||||||
|
(0, 3, 0.5), (0, 3, 0),
|
||||||
|
(100, 3, 0.5), (100, 3, 0),
|
||||||
|
(0, 0.5, 2), (0, 0.5, 0.5),
|
||||||
|
(100, 0.5, 2), (100, 0.5, 0.5),
|
||||||
|
(100, 0, 2), (100, 0, 0),
|
||||||
|
]
|
||||||
|
|
||||||
|
VERTICES_B = [
|
||||||
|
# 底部截面(Z=0平面)
|
||||||
|
(0, 3, 0), (100, 3, 0),
|
||||||
|
(100, 3, 0), (100, 0, 0),
|
||||||
|
# 中间截面(Z=0.5平面)
|
||||||
|
(0, 0.5, 0.5), (0, 2.5, 0.5),
|
||||||
|
(100, 2.5, 0.5), (100, 0.5, 0.5),
|
||||||
|
(100, 0.5, 0.5), (0, 0.5, 0.5),
|
||||||
|
# 中间截面(Z=1平面)
|
||||||
|
(0, 2.5, 1), (0, 3, 1),
|
||||||
|
(0, 3, 1), (100, 3, 1),
|
||||||
|
(100, 3, 1), (100, 2.5, 1),
|
||||||
|
(100, 2.5, 1), (0, 2.5, 1),
|
||||||
|
# 顶部界面(Z=2平面)
|
||||||
|
(0, 0, 2), (0, 0.5, 2),
|
||||||
|
(0, 0.5, 2), (100, 0.5, 2),
|
||||||
|
(100, 0.5, 2), (100, 0, 2),
|
||||||
|
(100, 0, 2), (0, 0, 2),
|
||||||
|
# z方向的连线
|
||||||
|
(0, 3, 1), (0, 3, 0),
|
||||||
|
(100, 3, 1), (100, 3, 0),
|
||||||
|
(0, 0.5, 2), (0, 0.5, 0.5),
|
||||||
|
(100, 0.5, 2), (100, 0.5, 0.5),
|
||||||
|
(100, 0, 2), (100, 0, 0),
|
||||||
|
(0, 2.5, 1), (0, 2.5, 0.5),
|
||||||
|
(100, 2.5, 1), (100, 2.5, 0.5)
|
||||||
|
]
|
||||||
|
|
||||||
|
ANNOTATIONS_A = [
|
||||||
|
("a", 100, 0.25, 2, 'red'),
|
||||||
|
("b", 100, 0.5, 1.25, 'magenta'),
|
||||||
|
("c", 100, 1, 0, 'green'),
|
||||||
|
("d", 100, 3, 0.25, 'blue'),
|
||||||
|
]
|
||||||
|
|
||||||
|
ANNOTATIONS_B = [
|
||||||
|
("a", 100, 0.25, 2, 'red'),
|
||||||
|
("b", 100, 0.5, 1.25, 'magenta'),
|
||||||
|
("c", 100, 1, 0, 'green'),
|
||||||
|
("d", 100, 3, 0.5, 'blue'),
|
||||||
|
("e", 100, 2.5, 0.6, 'orange'),
|
||||||
|
("f", 100, 2.75, 1, 'purple')
|
||||||
|
]
|
||||||
|
|
||||||
|
def __init__(self, index: int = 0, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
self._index = index
|
||||||
|
|
||||||
|
self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint) # 无边框窗口
|
||||||
|
self.setAttribute(Qt.WA_TranslucentBackground) # 设置背景为透明
|
||||||
|
self.setStyleSheet("background: transparent;")
|
||||||
|
|
||||||
self.init_3d_plot()
|
self.init_3d_plot()
|
||||||
self.setLayout(QVBoxLayout())
|
self.setLayout(QVBoxLayout())
|
||||||
|
self.layout().setContentsMargins(0, 0, 0, 0) # 移除布局的内边距
|
||||||
self.layout().addWidget(self.canvas)
|
self.layout().addWidget(self.canvas)
|
||||||
|
|
||||||
def init_3d_plot(self):
|
def init_3d_plot(self):
|
||||||
# 3D画布
|
# 3D画布
|
||||||
self.fig = plt.figure(figsize=(15, 6))
|
self.fig = plt.figure()
|
||||||
|
self.fig.patch.set_facecolor('none') # 设置figure背景透明
|
||||||
self.canvas = FigureCanvas(self.fig)
|
self.canvas = FigureCanvas(self.fig)
|
||||||
self.ax = self.fig.add_subplot(111, projection='3d')
|
self.ax = self.fig.add_subplot(111, projection='3d')
|
||||||
|
self.ax.set_facecolor('none') # 设置axes背景透明
|
||||||
|
|
||||||
# 绘制3D形状
|
# 绘制3D形状
|
||||||
self.draw_target_shape()
|
self.draw_target_shape()
|
||||||
@ -41,9 +122,9 @@ class Target3DWidgetA(QWidget):
|
|||||||
self.ax.set_zticklabels([])
|
self.ax.set_zticklabels([])
|
||||||
|
|
||||||
# 2. 隐藏刻度线(针对3D轴的特殊设置)
|
# 2. 隐藏刻度线(针对3D轴的特殊设置)
|
||||||
self.ax.tick_params(axis='x', which='both', length=0) # X轴刻度线长度设为0
|
self.ax.tick_params(axis='x', which='both', length=0) # X轴刻度线长度设为0
|
||||||
self.ax.tick_params(axis='y', which='both', length=0) # Y轴刻度线长度设为0
|
self.ax.tick_params(axis='y', which='both', length=0) # Y轴刻度线长度设为0
|
||||||
self.ax.tick_params(axis='z', which='both', length=0) # Z轴刻度线长度设为0
|
self.ax.tick_params(axis='z', which='both', length=0) # Z轴刻度线长度设为0
|
||||||
|
|
||||||
# 轴范围保留(保证3D图形显示范围正确)
|
# 轴范围保留(保证3D图形显示范围正确)
|
||||||
self.ax.set_xlim(0, 120)
|
self.ax.set_xlim(0, 120)
|
||||||
@ -55,31 +136,7 @@ class Target3DWidgetA(QWidget):
|
|||||||
|
|
||||||
def draw_target_shape(self):
|
def draw_target_shape(self):
|
||||||
"""绘制3D结构"""
|
"""绘制3D结构"""
|
||||||
vertices = [
|
vertices = self.VERTICES_A if self._index == 0 else self.VERTICES_B
|
||||||
# 底部截面(Z=0平面)
|
|
||||||
(0, 3, 0), (100, 3, 0),
|
|
||||||
(100, 3, 0), (100, 0, 0),
|
|
||||||
|
|
||||||
# 中间截面(Z=0.5平面)
|
|
||||||
(0, 0.5, 0.5), (0, 3, 0.5),
|
|
||||||
(0, 3, 0.5), (100, 3, 0.5),
|
|
||||||
(100, 3, 0.5), (100, 0.5, 0.5),
|
|
||||||
(100, 0.5, 0.5), (0, 0.5, 0.5),
|
|
||||||
|
|
||||||
# 顶部界面(Z=2平面)
|
|
||||||
(0, 0, 2), (0, 0.5, 2),
|
|
||||||
(0, 0.5, 2), (100, 0.5, 2),
|
|
||||||
(100, 0.5, 2), (100, 0, 2),
|
|
||||||
(100, 0, 2), (0, 0, 2),
|
|
||||||
|
|
||||||
# z方向的连线
|
|
||||||
(0, 3, 0.5), (0, 3, 0),
|
|
||||||
(100, 3, 0.5), (100, 3, 0),
|
|
||||||
(0, 0.5, 2), (0, 0.5, 0.5),
|
|
||||||
(100, 0.5, 2), (100, 0.5, 0.5),
|
|
||||||
(100, 0, 2), (100, 0, 0),
|
|
||||||
]
|
|
||||||
|
|
||||||
# 绘制所有棱边
|
# 绘制所有棱边
|
||||||
for i in range(0, len(vertices), 2):
|
for i in range(0, len(vertices), 2):
|
||||||
x = [vertices[i][0], vertices[i + 1][0]]
|
x = [vertices[i][0], vertices[i + 1][0]]
|
||||||
@ -89,138 +146,32 @@ class Target3DWidgetA(QWidget):
|
|||||||
|
|
||||||
def add_annotations(self):
|
def add_annotations(self):
|
||||||
"""标注位置(适配X轴1cm单位)"""
|
"""标注位置(适配X轴1cm单位)"""
|
||||||
annotations = [
|
annotations = self.ANNOTATIONS_A if self._index == 0 else self.ANNOTATIONS_B
|
||||||
("a", 100, 0, 1, 'red'),
|
|
||||||
("b", 100, 1, 0, 'green'),
|
|
||||||
("c", 100, 3, 0.25, 'blue'),
|
|
||||||
("d", 50, 2, 0, 'magenta')
|
|
||||||
]
|
|
||||||
for text, x, y, z, color in annotations:
|
|
||||||
self.ax.text(x, y, z, text, fontsize=14, color=color, weight='bold')
|
|
||||||
|
|
||||||
# 线条类型B
|
|
||||||
class Target3DWidgetB(QWidget):
|
|
||||||
def __init__(self, parent=None):
|
|
||||||
super().__init__(parent)
|
|
||||||
self.init_3d_plot()
|
|
||||||
self.setLayout(QVBoxLayout())
|
|
||||||
self.layout().addWidget(self.canvas)
|
|
||||||
|
|
||||||
def init_3d_plot(self):
|
|
||||||
# 3D画布
|
|
||||||
self.fig = plt.figure(figsize=(15, 6))
|
|
||||||
self.canvas = FigureCanvas(self.fig)
|
|
||||||
self.ax = self.fig.add_subplot(111, projection='3d')
|
|
||||||
|
|
||||||
# 绘制3D形状
|
|
||||||
self.draw_target_shape()
|
|
||||||
# 添加标注
|
|
||||||
self.add_annotations()
|
|
||||||
|
|
||||||
# ========== 核心修改:X/Y/Z轴统一为1cm单位 ==========
|
|
||||||
self.ax.set_xlabel('X')
|
|
||||||
self.ax.set_ylabel('Y')
|
|
||||||
self.ax.set_zlabel('Z')
|
|
||||||
|
|
||||||
# 1. 清空刻度数值(隐藏刻度数字)
|
|
||||||
self.ax.set_xticklabels([])
|
|
||||||
self.ax.set_yticklabels([])
|
|
||||||
self.ax.set_zticklabels([])
|
|
||||||
|
|
||||||
# 2. 隐藏刻度线(针对3D轴的特殊设置)
|
|
||||||
self.ax.tick_params(axis='x', which='both', length=0) # X轴刻度线长度设为0
|
|
||||||
self.ax.tick_params(axis='y', which='both', length=0) # Y轴刻度线长度设为0
|
|
||||||
self.ax.tick_params(axis='z', which='both', length=0) # Z轴刻度线长度设为0
|
|
||||||
|
|
||||||
# 轴范围保留(保证3D图形显示范围正确)
|
|
||||||
self.ax.set_xlim(0, 120)
|
|
||||||
self.ax.set_ylim(0, 5)
|
|
||||||
self.ax.set_zlim(0, 5)
|
|
||||||
|
|
||||||
# 调整视角(适配X轴1cm刻度)
|
|
||||||
self.ax.view_init(elev=20, azim=60)
|
|
||||||
|
|
||||||
def draw_target_shape(self):
|
|
||||||
"""绘制3D结构"""
|
|
||||||
vertices = [
|
|
||||||
# 底部截面(Z=0平面)
|
|
||||||
(0, 3, 0), (100, 3, 0),
|
|
||||||
(100, 3, 0), (100, 0, 0),
|
|
||||||
|
|
||||||
# 中间截面(Z=0.5平面)
|
|
||||||
(0, 0.5, 0.5), (0, 2.5, 0.5),
|
|
||||||
(100, 2.5, 0.5), (100, 0.5, 0.5),
|
|
||||||
(100, 0.5, 0.5), (0, 0.5, 0.5),
|
|
||||||
|
|
||||||
# 中间截面(Z=1平面)
|
|
||||||
(0, 2.5, 1),(0, 3, 1),
|
|
||||||
(0, 3, 1), (100, 3, 1),
|
|
||||||
(100, 3, 1), (100, 2.5, 1),
|
|
||||||
(100, 2.5, 1), (0, 2.5, 1),
|
|
||||||
|
|
||||||
# 顶部界面(Z=2平面)
|
|
||||||
(0, 0, 2), (0, 0.5, 2),
|
|
||||||
(0, 0.5, 2), (100, 0.5, 2),
|
|
||||||
(100, 0.5, 2), (100, 0, 2),
|
|
||||||
(100, 0, 2), (0, 0, 2),
|
|
||||||
|
|
||||||
# z方向的连线
|
|
||||||
(0, 3, 1), (0, 3, 0),
|
|
||||||
(100, 3, 1), (100, 3, 0),
|
|
||||||
(0, 0.5, 2), (0, 0.5, 0.5),
|
|
||||||
(100, 0.5, 2), (100, 0.5, 0.5),
|
|
||||||
(100, 0, 2), (100, 0, 0),
|
|
||||||
(0, 2.5, 1),(0, 2.5, 0.5),
|
|
||||||
(100, 2.5, 1),(100, 2.5, 0.5)
|
|
||||||
]
|
|
||||||
|
|
||||||
# 绘制所有棱边
|
|
||||||
for i in range(0, len(vertices), 2):
|
|
||||||
x = [vertices[i][0], vertices[i + 1][0]]
|
|
||||||
y = [vertices[i][1], vertices[i + 1][1]]
|
|
||||||
z = [vertices[i][2], vertices[i + 1][2]]
|
|
||||||
self.ax.plot(x, y, z, color='black', linewidth=2)
|
|
||||||
|
|
||||||
def add_annotations(self):
|
|
||||||
"""标注位置(适配X轴1cm单位)"""
|
|
||||||
annotations = [
|
|
||||||
("a", 100, 0, 1, 'red'),
|
|
||||||
("b", 100, 1, 0, 'green'),
|
|
||||||
("c", 100, 3, 0.5, 'blue'),
|
|
||||||
("d", 50, 2, 0, 'magenta')
|
|
||||||
]
|
|
||||||
for text, x, y, z, color in annotations:
|
for text, x, y, z, color in annotations:
|
||||||
self.ax.text(x, y, z, text, fontsize=14, color=color, weight='bold')
|
self.ax.text(x, y, z, text, fontsize=14, color=color, weight='bold')
|
||||||
|
|
||||||
|
|
||||||
class MainWindowA(QMainWindow):
|
# ----------对外接口----------
|
||||||
def __init__(self):
|
def show(x: int, y: int, w: int, h: int, index: int):
|
||||||
super().__init__()
|
"""
|
||||||
self.setWindowTitle("3D视图(X/Y/Z单位:1cm)")
|
显示3D视图窗口
|
||||||
self.setGeometry(100, 100, 1200, 700) # 加宽窗口,适配X轴1cm刻度
|
:param x: 窗口横坐标
|
||||||
self.setCentralWidget(Target3DWidgetA())
|
:param y: 窗口纵坐标
|
||||||
|
:param w: 窗口宽度
|
||||||
class MainWindowB(QMainWindow):
|
:param h: 窗口高度
|
||||||
def __init__(self):
|
:param index: 窗口索引,0为A视图,1为B视图
|
||||||
super().__init__()
|
"""
|
||||||
self.setWindowTitle("3D视图(X/Y/Z单位:1cm)")
|
if index not in (0, 1):
|
||||||
self.setGeometry(100, 100, 1200, 700) # 加宽窗口,适配X轴1cm刻度
|
raise ValueError("index must be 0 or 1")
|
||||||
self.setCentralWidget(Target3DWidgetB())
|
|
||||||
|
|
||||||
def ui_3d_a():
|
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
window = MainWindowA()
|
window = Target3DWidget(index)
|
||||||
|
window.setGeometry(x, y, w, h)
|
||||||
window.show()
|
window.show()
|
||||||
sys.exit(app.exec())
|
sys.exit(app.exec())
|
||||||
|
|
||||||
def ui_3d_b():
|
|
||||||
app = QApplication(sys.argv)
|
|
||||||
window = MainWindowB()
|
|
||||||
window.show()
|
|
||||||
sys.exit(app.exec())
|
|
||||||
|
|
||||||
# ----------测试接口----------
|
# ----------测试接口----------
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# ui_3d_a()
|
show(100, 100, 700, 700, 0) # 显示A视图窗口
|
||||||
ui_3d_b()
|
# show(100, 100, 700, 700, 1) # 显示B视图窗口
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user