完善制动性能测试
This commit is contained in:
		| @@ -87,14 +87,17 @@ def initialization(path, sub, data_dirs, data_files, hr, w2t): | ||||
|     return _config_file, _prj_file, _result_dirs, _avs | ||||
|  | ||||
|  | ||||
| @clibs.db_lock | ||||
| def gen_result_file(path, axis, t_end, reach, load, speed, rounds): | ||||
|     d_vel, d_trq, d_stop = [], [], [] | ||||
| def gen_result_file(path, axis, t_end, reach, load, speed, speed_target, rounds, w2t): | ||||
|     d_vel, d_trq, d_stop, threshold = [], [], [], 0.95 | ||||
|  | ||||
|     start_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(t_end-12)) | ||||
|     end_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(t_end)) | ||||
|     clibs.cursor.execute(f"select content from logs where time between '{start_time}' and '{end_time}' and content like '%diagnosis.result%' order by id asc") | ||||
|     records = clibs.cursor.fetchall() | ||||
|     try: | ||||
|         clibs.lock.acquire(True) | ||||
|         clibs.cursor.execute(f"select content from logs where time between '{start_time}' and '{end_time}' and content like '%diagnosis.result%' order by id asc") | ||||
|         records = clibs.cursor.fetchall() | ||||
|     finally: | ||||
|         clibs.lock.release() | ||||
|  | ||||
|     for record in records:  # 保留最后12s的数据 | ||||
|         data = eval(record[0])["data"] | ||||
| @@ -107,12 +110,19 @@ def gen_result_file(path, axis, t_end, reach, load, speed, rounds): | ||||
|             elif item.get("channel", None) == 0 and item.get("name", None) == "device_safety_estop": | ||||
|                 d_stop.extend(d_item) | ||||
|  | ||||
|     idx = d_stop.index(0) | ||||
|     av_estop = sum(d_vel[idx - 20:idx])/20 * clibs.RADIAN | ||||
|     if av_estop / speed_target < threshold: | ||||
|         w2t(f"[av_estop: {av_estop:.2f} | shouldbe: {speed_target:.2f}] 本次触发 ESTOP 时未采集到指定百分比的最大速度,即将重试!\n", "#8A2BE2") | ||||
|         return False | ||||
|  | ||||
|     df1 = pandas.DataFrame.from_dict({"hw_joint_vel_feedback": d_vel}) | ||||
|     df2 = pandas.DataFrame.from_dict({"device_servo_trq_feedback": d_trq}) | ||||
|     df3 = pandas.DataFrame.from_dict({"device_safety_estop": d_stop}) | ||||
|     df = pandas.concat([df1, df2, df3], axis=1) | ||||
|     filename = f"{path}/j{axis}/reach{reach}_load{load}_speed{speed}/reach{reach}_load{load}_speed{speed}_{rounds}.data" | ||||
|     df.to_csv(filename, sep="\t", index=False) | ||||
|     return True | ||||
|  | ||||
|  | ||||
| def run_rl(path, sub, hr, md, config_file, prj_file, result_dirs, avs, w2t): | ||||
| @@ -244,7 +254,7 @@ def run_rl(path, sub, hr, md, config_file, prj_file, result_dirs, avs, w2t): | ||||
|                     speed_target = avs[axis-1] * float(speed) / 100 | ||||
|                     clibs.insert_logdb("INFO", "do_brake", f"axis = {axis}, direction = {pon}, max speed = {speed_max}") | ||||
|                     if speed_max < speed_target*0.95 or speed_max > speed_target*1.05: | ||||
|                         w2t(f"Axis: {axis}-{count} | Speed: {speed_max} | Shouldbe: {speed_target}", "indigo") | ||||
|                         w2t(f"Axis: {axis}-{count} | Speed: {speed_max} | Shouldbe: {speed_target}\n", "indigo") | ||||
|                         clibs.insert_logdb("WARNING", "do_brake", f"Axis: {axis}-{count} | Speed: {speed_max} | Shouldbe: {speed_target}") | ||||
|                     md.write_speed_max(speed_max) | ||||
|  | ||||
| @@ -255,53 +265,61 @@ def run_rl(path, sub, hr, md, config_file, prj_file, result_dirs, avs, w2t): | ||||
|                     else: | ||||
|                         break | ||||
|  | ||||
|                 # 5. 重新运行程序,发送继续运动信号,当速度达到最大值时,通过DO触发急停 | ||||
|                 hr.execution("rl_task.pp_to_main", tasks=["brake"]) | ||||
|                 hr.execution("state.switch_auto") | ||||
|                 hr.execution("state.switch_motor_on") | ||||
|                 hr.execution("rl_task.run", tasks=["brake"]) | ||||
|                 for i in range(3): | ||||
|                     if md.read_ready_to_go() == 1: | ||||
|                         md.write_act(1) | ||||
|                         break | ||||
|                 while 1: | ||||
|                     clibs.c_ec.setdo_value(io_name, "true") | ||||
|                     md.r_reset_estop() | ||||
|                     md.r_clear_alarm() | ||||
|                     md.write_act(0) | ||||
|                     # 5. 重新运行程序,发送继续运动信号,当速度达到最大值时,通过DO触发急停 | ||||
|                     hr.execution("rl_task.pp_to_main", tasks=["brake"]) | ||||
|                     hr.execution("state.switch_auto") | ||||
|                     hr.execution("state.switch_motor_on") | ||||
|                     hr.execution("rl_task.run", tasks=["brake"]) | ||||
|                     for i in range(3): | ||||
|                         if md.read_ready_to_go() == 1: | ||||
|                             md.write_act(1) | ||||
|                             break | ||||
|                         else: | ||||
|                             time.sleep(1) | ||||
|                     else: | ||||
|                         time.sleep(1) | ||||
|                 else: | ||||
|                     w2t("3s 内未收到机器人的运行信号,需要确认 RL 程序配置正确并正常执行...", "red", "ReadySignalTimeoutError") | ||||
|                         w2t("3s 内未收到机器人的运行信号,需要确认 RL 程序配置正确并正常执行...", "red", "ReadySignalTimeoutError") | ||||
|  | ||||
|                 time.sleep(10)  # 排除从其他位姿到零点位姿,再到轴极限位姿的时间 | ||||
|                     time.sleep(10)  # 排除从其他位姿到零点位姿,再到轴极限位姿的时间 | ||||
|  | ||||
|                 def exec_brake(): | ||||
|                     flag, start, data, record = True, time.time(), None, None | ||||
|                     while flag: | ||||
|                         time.sleep(0.2) | ||||
|                         if time.time() - start > 20: | ||||
|                             w2t("20s 内未触发急停,需排查......", "red", "BrakeTimeoutError") | ||||
|                     def exec_brake(): | ||||
|                         flag, start, data, record = True, time.time(), None, None | ||||
|                         while flag: | ||||
|                             time.sleep(0.1) | ||||
|                             if time.time() - start > 20: | ||||
|                                 w2t("20s 内未触发急停,需排查......", "red", "BrakeTimeoutError") | ||||
|  | ||||
|                         try: | ||||
|                             clibs.lock.acquire(True) | ||||
|                             clibs.cursor.execute(f"select content from logs where content like '%diagnosis.result%' order by id desc limit 1") | ||||
|                             record = clibs.cursor.fetchone() | ||||
|                             data = eval(record[0])["data"] | ||||
|                         finally: | ||||
|                             clibs.lock.release() | ||||
|                             try: | ||||
|                                 clibs.lock.acquire(True) | ||||
|                                 clibs.cursor.execute(f"select content from logs where content like '%diagnosis.result%' order by id desc limit 1") | ||||
|                                 record = clibs.cursor.fetchone() | ||||
|                                 data = eval(record[0])["data"] | ||||
|                             finally: | ||||
|                                 clibs.lock.release() | ||||
|  | ||||
|                         for item in data: | ||||
|                             if item.get("channel", None) != axis-1 or item.get("name", None) != "hw_joint_vel_feedback": | ||||
|                                 continue | ||||
|                             for item in data: | ||||
|                                 if item.get("channel", None) != axis-1 or item.get("name", None) != "hw_joint_vel_feedback": | ||||
|                                     continue | ||||
|  | ||||
|                             speed_moment = clibs.RADIAN * sum(item["value"]) / len(item["value"]) | ||||
|                             if (pon == "positive" and speed_moment > 0) or (pon == "negative" and speed_moment < 0): | ||||
|                                 if abs(speed_moment) > speed_target * 0.95: | ||||
|                                     clibs.c_ec.setdo_value(io_name, "false") | ||||
|                                     time.sleep(5) | ||||
|                                     flag = False | ||||
|                                     break | ||||
|                     return time.time() | ||||
|                                 speed_moment = clibs.RADIAN * sum(item["value"]) / len(item["value"]) | ||||
|                                 if (pon == "positive" and speed_moment > 0) or (pon == "negative" and speed_moment < 0): | ||||
|                                     if abs(speed_moment) > speed_target * 0.95: | ||||
|                                         clibs.c_ec.setdo_value(io_name, "false") | ||||
|                                         time.sleep(3) | ||||
|                                         flag = False | ||||
|                                         break | ||||
|                         return time.time() | ||||
|  | ||||
|                     t_end = exec_brake() | ||||
|                     # 6. 保留数据并处理输出 | ||||
|                     ret = gen_result_file(path, axis, t_end, reach, load, speed, speed_target, rounds, w2t) | ||||
|                     if ret: | ||||
|                         break | ||||
|  | ||||
|                 t_end = exec_brake() | ||||
|                 # 6. 保留数据并处理输出 | ||||
|                 gen_result_file(path, axis, t_end, reach, load, speed, rounds) | ||||
|     else: | ||||
|         w2t(f"\n{sub.removeprefix("tool")}%负载的制动性能测试执行完毕,如需采集其他负载,须切换负载类型,并更换其他负载,重新执行。\n", "green") | ||||
|         hr.execution("diagnosis.open", open=False, display_open=False, overrun=True, turn_area=True, delay_motion=False) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user