更新界面+更新步进电机bug和达妙电机调试接口

This commit is contained in:
2026-02-27 17:24:03 +08:00
parent 8d2e91b8b3
commit 9b7ff4b98f
3 changed files with 119 additions and 161 deletions

View File

@ -242,6 +242,13 @@ 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()

View File

@ -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:

View File

@ -6,72 +6,33 @@
# @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
super().__init__(parent) from PySide6.QtCore import Qt
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形状 class Target3DWidget(QWidget):
self.draw_target_shape() """
# 添加标注 3D显示窗口支持类型A和类型B
self.add_annotations() """
# ========== 核心修改X/Y/Z轴统一为1cm单位 ========== VERTICES_A = [
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平面 # 底部截面Z=0平面
(0, 3, 0), (100, 3, 0), (0, 3, 0), (100, 3, 0),
(100, 3, 0), (100, 0, 0), (100, 3, 0), (100, 0, 0),
# 中间截面Z=0.5平面) # 中间截面Z=0.5平面)
(0, 0.5, 0.5), (0, 3, 0.5), (0, 0.5, 0.5), (0, 3, 0.5),
(0, 3, 0.5), (100, 3, 0.5), (0, 3, 0.5), (100, 3, 0.5),
(100, 3, 0.5), (100, 0.5, 0.5), (100, 3, 0.5), (100, 0.5, 0.5),
(100, 0.5, 0.5), (0, 0.5, 0.5), (100, 0.5, 0.5), (0, 0.5, 0.5),
# 顶部界面Z=2平面 # 顶部界面Z=2平面
(0, 0, 2), (0, 0.5, 2), (0, 0, 2), (0, 0.5, 2),
(0, 0.5, 2), (100, 0.5, 2), (0, 0.5, 2), (100, 0.5, 2),
(100, 0.5, 2), (100, 0, 2), (100, 0.5, 2), (100, 0, 2),
(100, 0, 2), (0, 0, 2), (100, 0, 2), (0, 0, 2),
# z方向的连线 # z方向的连线
(0, 3, 0.5), (0, 3, 0), (0, 3, 0.5), (0, 3, 0),
(100, 3, 0.5), (100, 3, 0), (100, 3, 0.5), (100, 3, 0),
@ -80,37 +41,70 @@ class Target3DWidgetA(QWidget):
(100, 0, 2), (100, 0, 0), (100, 0, 2), (100, 0, 0),
] ]
# 绘制所有棱边 VERTICES_B = [
for i in range(0, len(vertices), 2): # 底部截面Z=0平面
x = [vertices[i][0], vertices[i + 1][0]] (0, 3, 0), (100, 3, 0),
y = [vertices[i][1], vertices[i + 1][1]] (100, 3, 0), (100, 0, 0),
z = [vertices[i][2], vertices[i + 1][2]] # 中间截面Z=0.5平面)
self.ax.plot(x, y, z, color='black', linewidth=2) (0, 0.5, 0.5), (0, 2.5, 0.5),
(100, 2.5, 0.5), (100, 0.5, 0.5),
def add_annotations(self): (100, 0.5, 0.5), (0, 0.5, 0.5),
"""标注位置适配X轴1cm单位""" # 中间截面Z=1平面
annotations = [ (0, 2.5, 1), (0, 3, 1),
("a", 100, 0, 1, 'red'), (0, 3, 1), (100, 3, 1),
("b", 100, 1, 0, 'green'), (100, 3, 1), (100, 2.5, 1),
("c", 100, 3, 0.25, 'blue'), (100, 2.5, 1), (0, 2.5, 1),
("d", 50, 2, 0, 'magenta') # 顶部界面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 text, x, y, z, color in annotations:
self.ax.text(x, y, z, text, fontsize=14, color=color, weight='bold')
# 线条类型B ANNOTATIONS_A = [
class Target3DWidgetB(QWidget): ("a", 100, 0.25, 2, 'red'),
def __init__(self, parent=None): ("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()
@ -142,38 +136,7 @@ class Target3DWidgetB(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, 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): for i in range(0, len(vertices), 2):
x = [vertices[i][0], vertices[i + 1][0]] x = [vertices[i][0], vertices[i + 1][0]]
@ -183,44 +146,32 @@ class Target3DWidgetB(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.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: 窗口宽度
:param h: 窗口高度
:param index: 窗口索引0为A视图1为B视图
"""
if index not in (0, 1):
raise ValueError("index must be 0 or 1")
class MainWindowB(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("3D视图X/Y/Z单位1cm")
self.setGeometry(100, 100, 1200, 700) # 加宽窗口适配X轴1cm刻度
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视图窗口