From 21fb5835c7733a83a315d388d6d161ce01d3cf39 Mon Sep 17 00:00:00 2001 From: kyz Date: Wed, 31 Dec 2025 17:15:03 +0800 Subject: [PATCH] debug tools v1.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 修改调试工具时间轴数据 --- QiDong/debug_tools/main.py | 48 +++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/QiDong/debug_tools/main.py b/QiDong/debug_tools/main.py index 826a6a6..946e935 100644 --- a/QiDong/debug_tools/main.py +++ b/QiDong/debug_tools/main.py @@ -145,11 +145,18 @@ class page_devst( QWidget, ui_devst.Ui_Form): mouse_point = self.p_curr.vb.mapSceneToView(pos) x = mouse_point.x() y = mouse_point.y() - + # 找到最接近的x坐标数据点 num_points = len(self.y_press) # 使用实际数据点数量 + num_points = len(self.x_time) if num_points > 0: - index = int(round(x)) + + #从x_time中找到最接近的x坐标数据点,index为该点的索引 + #使用enumerate(nums)获取每个元素的索引和值, min函数通过key参数定义排序规则 + #abs(j[1] - target)计算元素值与目标值的绝对差值 + #-j[0]确保当差值相同时,索引较大的元素被优先选择(因为-j[0]更小) + index = min(enumerate(self.x_time), key=lambda j: (abs(j[1] - x), -j[0]))[0] + if 0 <= index < num_points: # 获取所有曲线在该点的值 target_val = self.y_target[index] if index < len(self.y_target) else 0 @@ -159,7 +166,7 @@ class page_devst( QWidget, ui_devst.Ui_Form): thresold_val = self.y_thresold[index] if index < len(self.y_thresold) else 0 # 显示信息 - info_str = f"点: {index}\n" + info_str = f"时间: {self.x_time[index]:.3f}\n" info_str += f"目标压力: {target_val:.3f}\n" info_str += f"实时压力: {press_val:.3f}\n" info_str += f"输出压力: {output_val:.3f}\n" @@ -193,6 +200,7 @@ class page_devst( QWidget, ui_devst.Ui_Form): self.y_press = [] self.y_output = [] self.y_step = [] + self.x_start_time = time.time() else: self.ser.write_pkt( 0xF1, struct.pack( 'LB', data[:5] ) target, thresold, curr_press, output_press = struct.unpack( '