界面优化,监控逻辑优化

This commit is contained in:
2025-03-30 12:27:57 +08:00
parent c325875dbb
commit a9a6db23fd
20 changed files with 574 additions and 594 deletions

View File

@ -8,27 +8,19 @@ from codes.common import clibs
class DoCurrentTest(QThread):
output = Signal(str, str)
def __init__(self, dir_path, tool, /):
super().__init__()
self.dir_path = dir_path
self.tool = tool
self.idx = 5
def logger(self, level, module, content, color="black", error="", flag="both"):
flag = "cursor" if level.upper() == "DEBUG" else "both"
clibs.logger(level, module, content, color, flag, signal=self.output)
if level.upper() == "ERROR":
raise Exception(f"{error} | {content}")
self.logger = clibs.logger
def initialization(self, data_dirs, data_files):
@clibs.handle_exception
def check_files():
msg = "初始路径下不允许有文件夹,初始路径下只能存在如下两个文件,且文件为关闭状态,确认后重新运行!<br>"
msg += "1. T_电机电流.xlsx<br>2. xxxx.zip"
if len(data_dirs) != 0 or len(data_files) != 2:
self.logger("ERROR", "do_current", msg, "red", "InitFileError")
self.logger("ERROR", "do_current", msg, "red")
prj_file, count = None, 0
for data_file in data_files:
@ -39,10 +31,10 @@ class DoCurrentTest(QThread):
count += 1
prj_file = data_file
else:
self.logger("ERROR", "do_current", msg, "red", "InitFileError")
self.logger("ERROR", "do_current", msg, "red")
if count != 2:
self.logger("ERROR", "do_current", msg, "red", "InitFileError")
self.logger("ERROR", "do_current", msg, "red")
if self.tool == "tool100":
os.mkdir(f"{self.dir_path}/single")
@ -52,11 +44,10 @@ class DoCurrentTest(QThread):
elif self.tool == "inertia":
os.mkdir(f"{self.dir_path}/inertia")
else:
self.logger("ERROR", "do_current", "负载选择错误,电机电流测试只能选择 tool100/inertia 规格!", "red", "LoadSelectError")
self.logger("ERROR", "do_current", "负载选择错误,电机电流测试只能选择 tool100/inertia 规格!", "red")
return prj_file
@clibs.handle_exception
def get_configs():
robot_type = None
msg_id = clibs.c_hr.execution("controller.get_params")
@ -74,7 +65,6 @@ class DoCurrentTest(QThread):
self.logger("INFO", "do_current", "数据目录合规性检查结束,未发现问题......", "green")
return _prj_file
@clibs.handle_exception
def single_axis_proc(self, records, number):
text = "single" if number < 6 else "hold"
number = number if number < 6 else number - 6
@ -100,7 +90,6 @@ class DoCurrentTest(QThread):
filename = f"{self.dir_path}/single/j{number + 1}_{text}_{time.time()}.data"
df.to_csv(filename, sep="\t", index=False)
@clibs.handle_exception
def scenario_proc(self, records, number, scenario_time):
d_vel, d_trq, d_sensor, d_trans = [[], [], [], [], [], []], [[], [], [], [], [], []], [[], [], [], [], [], []], [[], [], [], [], [], []]
for record in records:
@ -126,9 +115,7 @@ class DoCurrentTest(QThread):
filename = f"{self.dir_path}/s_{number-11}/j{axis+1}_s_{number-11}_{scenario_time}_{time.time()}.data"
df.to_csv(filename, sep="\t", index=False)
@clibs.handle_exception
def gen_result_file(self, number, start_time, end_time, scenario_time):
@clibs.handle_exception
def get_records():
s_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(start_time))
e_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(end_time+clibs.INTERVAL))
@ -152,14 +139,12 @@ class DoCurrentTest(QThread):
t.start()
@staticmethod
@clibs.handle_exception
def change_curve_state(stat):
curves = ["hw_joint_vel_feedback", "device_servo_trq_feedback", "hw_sensor_trq_feedback", "hw_estimate_trans_trq_res"]
display_pdo_params = [] if not stat else [{"name": curve, "channel": chl} for curve in curves for chl in range(6)]
clibs.c_hr.execution("diagnosis.open", open=stat, display_open=stat)
clibs.c_hr.execution("diagnosis.set_params", display_pdo_params=display_pdo_params)
@clibs.handle_exception
def run_rl(self, prj_file):
prj_name = ".".join(prj_file.split("/")[-1].split(".")[:-1])
c_regular = [
@ -235,7 +220,7 @@ class DoCurrentTest(QThread):
else:
time.sleep(1)
if (time.time() - t_start) > 15:
self.logger("ERROR", "do_current", "15s 内未收到机器人的运行信号需要确认RL程序和工具通信是否正常执行...", "red", "ReadySignalTimeoutError")
self.logger("ERROR", "do_current", "15s 内未收到机器人的运行信号需要确认RL程序和工具通信是否正常执行...", "red")
# 4. 执行采集
time.sleep(10) # 消除前 10s 的不稳定数据
@ -256,7 +241,7 @@ class DoCurrentTest(QThread):
else:
time.sleep(1)
if (time.time()-t_start) > 180:
self.logger("ERROR", "do_current", f"180s 内未收到场景{number - 11}的周期时间需要确认RL程序和工具通信交互是否正常执行...", "red", "GetScenarioTimeError")
self.logger("ERROR", "do_current", f"180s 内未收到场景{number - 11}的周期时间需要确认RL程序和工具通信交互是否正常执行...", "red")
time.sleep(20)
# 5.停止程序运行,保留数据并处理输出
@ -271,14 +256,13 @@ class DoCurrentTest(QThread):
elif self.tool == "inertia":
self.logger("INFO", "do_current", "惯量负载电机电流采集完毕,如需采集单轴/场景/保持电机电流,须切换负载类型,并更换偏置负载,重新执行", "green")
@clibs.handle_exception
def processing(self):
time_start = time.time()
clibs.running[self.idx] = 1
if clibs.status["hmi"] != 1 or clibs.status["md"] != 1:
self.logger("ERROR", "do_current", "processing: 需要在网络设置中连接HMI以及Modbus通信", "red", "NetworkError")
self.logger("ERROR", "do_current", "processing: 需要在网络设置中连接HMI以及Modbus通信", "red")
data_dirs, data_files = clibs.traversal_files(self.dir_path, self.output)
data_dirs, data_files = clibs.traversal_files(self.dir_path)
prj_file = self.initialization(data_dirs, data_files)
clibs.c_pd.push_prj_to_server(prj_file)
self.run_rl(prj_file)