From 65bd6f2bce4af43b3460e8b516086faddd2a9f9f Mon Sep 17 00:00:00 2001 From: gitea Date: Wed, 25 Sep 2024 11:30:12 +0800 Subject: [PATCH] improvment --- assets/json/collision.set_params.json | 9 +- code/common.py | 11 +- code/openapi.py | 157 ++++++++++---------------- 3 files changed, 73 insertions(+), 104 deletions(-) diff --git a/assets/json/collision.set_params.json b/assets/json/collision.set_params.json index 3f8b101..813f7ca 100644 --- a/assets/json/collision.set_params.json +++ b/assets/json/collision.set_params.json @@ -2,12 +2,5 @@ "id": "xxxxxxxxxxx", "module": "safety", "command": "collision.set_params", - "data": { - "enable": false, - "mode": 0, - "coeff": [0,0,0,0,0,0,0], - "coeff_level": 0, - "action": 1, - "percent": 1 - } + "data": null } \ No newline at end of file diff --git a/code/common.py b/code/common.py index 3c726d5..6e70abe 100644 --- a/code/common.py +++ b/code/common.py @@ -8,6 +8,7 @@ def initialization(): hr = openapi.HmiRequest() pd = openapi.PreDos() # 推送配置文件 + clibs.logger.info("推送配置文件 fieldbus_device.json/registers.json/registers.xml 到控制器,并配置 IO 设备,设备号为 5...") robot_params = hr.get_robot_params robot_type = robot_params["robot_type"] security_type = robot_params["security_type"] @@ -55,33 +56,41 @@ def initialization(): md.r_soft_estop(1) # 断开示教器连接 + clibs.logger.info("断开示教器连接...") hr.switch_tp_mode("without") # 清空 system IO 配置 + clibs.logger.info("清空所有的 System IO 功能配置...") hr.update_system_io_configuration([], [], [], [], []) # 关闭缩减模式 md.r_reduced_mode(0) # 关闭安全区域 + clibs.logger.info("正在关闭所有的安全区,并关闭总使能开关...") hr.set_safety_area_overall(False) hr.set_safety_area_signal(False) for i in range(10): hr.set_safety_area_enable(i, False) # 打开外部通信 + clibs.logger.info("配置并打开外部通信,默认服务器,8080端口,后缀为 \"\\r\"...") hr.set_socket_params(True, "", "name", "8080", "\r", 1, True, True, 0, 10) # 关闭拖动 + clibs.logger.info("关闭拖动模式...") hr.set_drag_params(False, 1, 2) # 关闭碰撞检测 + clibs.logger.info("关闭碰撞检测...") hr.set_collision_params(False, 0, 1, 100) - # 清除所有错误码 + # 清除所有过滤错误码 + clibs.logger.info("清除所有过滤错误码设定...") hr.set_filtered_error_code("clear", []) # 回拖动位姿 + clibs.logger.info("正在回拖动位姿...") hr.switch_operation_mode("manual") hr.switch_motor_state("on") hr.set_quickturn_pos(enable_drag=True) diff --git a/code/openapi.py b/code/openapi.py index 8e7d449..049ee46 100644 --- a/code/openapi.py +++ b/code/openapi.py @@ -37,10 +37,9 @@ class ModbusRequest(object): self.__reg_high_pulse(40001) clibs.logger.info("40001-010 执行复位急停状态(非软急停)") - def r_reset_estop_clear_alarm(self): # NG - clibs.logger.critical("[NG]-40002-010 该指令暂时有问题,运行会导致后台 xCore 崩溃,待修复...") - # self.__reg_high_pulse(40002) - # clibs.logger.info("[NG]-40002-010 执行复位急停状态(非软急停),并清除告警信息") + def r_reset_estop_clear_alarm(self): # OK + self.__reg_high_pulse(40002) + clibs.logger.info("40002-010 执行复位急停状态(非软急停),并清除告警信息") def r_motor_off(self): # OK self.__reg_high_pulse(40003) @@ -296,7 +295,7 @@ class HmiRequest(object): self.__t_is_alive = Thread(target=self.__is_alive) self.__t_is_alive.daemon = False self.__t_is_alive.start() - sleep(1) # 很重要,必须有,因为涉及到建联成功与否 + sleep(2) # 很重要,必须有,因为涉及到建联成功与否 def __is_alive(self): first_time = True @@ -649,7 +648,7 @@ class HmiRequest(object): def log_reqs(request): with open(clibs.log_data_reqs, mode="a", encoding="utf-8") as f_log: log_time = strftime("%Y-%m-%d %H:%M:%S", localtime(time())) - f_log.write(" ".join([log_time, dumps(req), "\n"])) + f_log.write(" ".join([log_time, dumps(request), "\n"])) if protocol_flag == 0: # for old protocols req = None @@ -712,11 +711,7 @@ class HmiRequest(object): req["data"]["enable_home"] = kwargs["enable_home"] req["data"]["enable_drag"] = kwargs["enable_drag"] req["data"]["enable_transport"] = kwargs["enable_transport"] - req["data"]["joint_home"] = kwargs["joint_home"] - req["data"]["joint_drag"] = kwargs["joint_drag"] - req["data"]["joint_transport"] = kwargs["joint_transport"] req["data"]["end_posture"] = kwargs["end_posture"] - req["data"]["home_error_range"] = kwargs["home_error_range"] case "move.quick_turn": req["data"]["name"] = kwargs["name"] case "move.stop": @@ -745,27 +740,11 @@ class HmiRequest(object): case "move.set_monitor_cfg": req["data"]["ref_coordinate"] = kwargs["ref_coordinate"] case "move.set_params": - req["data"]["JOINT_MAX_SPEED"] = kwargs["JOINT_MAX_SPEED"] - req["data"]["JOINT_MAX_ACC"] = kwargs["JOINT_MAX_ACC"] - req["data"]["JOINT_MAX_JERK"] = kwargs["JOINT_MAX_JERK"] - req["data"]["TCP_MAX_SPEED"] = kwargs["TCP_MAX_SPEED"] - req["data"]["DEFAULT_ACC_PARAMS"] = kwargs["DEFAULT_ACC_PARAMS"] - req["data"]["VEL_SMOOTH_FACTOR"] = kwargs["VEL_SMOOTH_FACTOR"] - req["data"]["ACC_RAMPTIME_JOG"] = kwargs["ACC_RAMPTIME_JOG"] + req["data"] = kwargs["data"] case "move.set_quickstop_distance": req["data"]["distance"] = kwargs["distance"] case "collision.set_params": - req["data"]["enable"] = kwargs["enable"] - req["data"]["mode"] = kwargs["mode"] - req["data"]["action"] = kwargs["action"] - req["data"]["percent"] = kwargs["percent"] - req["data"]["coeff"] = kwargs["coeff"] - req["data"]["coeff_level"] = kwargs["coeff_level"] - req["data"]["percent_axis"] = kwargs["percent_axis"] - req["data"]["fallback_distance"] = kwargs["fallback_distance"] - req["data"]["compliance"] = kwargs["compliance"] - req["data"]["reduced_percent"] = kwargs["reduced_percent"] - req["data"]["reduced_percent_axis"] = kwargs["reduced_percent_axis"] + req["data"] = kwargs["data"] case "collision.set_state": req["data"]["collision_state"] = kwargs["collision_state"] case "controller.set_params": @@ -947,35 +926,28 @@ class HmiRequest(object): 6 工具坐标系Z轴与地面垂直,正向朝上 :return: as below { - "enable_home": false, - "enable_drag": false, - "enable_transport": false, - "joint_home": [0.0,0.0,0.0,0.0,0.0,0.0,0.0], - "joint_drag": [0.0,0.0,0.0,0.0,0.0,0.0,0.0], - "joint_transport": [0.0,0.0,0.0,0.0,0.0,0.0,0.0], - "end_posture":0, - "home_error_range":[0.0,0.0,0.0,0.0,0.0,0.0,0.0] + "enable_home": false, // 是否开启 home 点快速调整 + "enable_drag": false, // 是否开启拖动位姿点快速调整 + "enable_transport": false, // 是否开启发货位姿点快速调整 + "joint_home": [0.0,0.0,0.0,0.0,0.0,0.0,0.0], // home 位姿的关节角度 + "joint_drag": [0.0,0.0,0.0,0.0,0.0,0.0,0.0], // 拖动位姿的关节角度 + "joint_transport": [0.0,0.0,0.0,0.0,0.0,0.0,0.0], // 发货位姿的关节角度 + "end_posture":0, // 末端姿态的调整方式,取值 0-6 + "home_error_range":[0.0,0.0,0.0,0.0,0.0,0.0,0.0] // home点误差范围 } """ return self.__get_data(currentframe().f_code.co_name, "move.get_quickturn_pos") - def set_quickturn_pos(self, enable_home: bool=False, enable_drag: bool=False, enable_transport: bool=False, - joint_home: list=[0.0,0.0,0.0,0.0,0.0,0.0,0.0], joint_drag: list=[0.0,0.0,0.0,0.0,0.0,0.0,0.0], - joint_transport: list=[0.0,0.0,0.0,0.0,0.0,0.0,0.0], end_posture: int=0, - home_error_range: list=[0.0,0.0,0.0,0.0,0.0,0.0,0.0]): + def set_quickturn_pos(self, enable_home: bool = False, enable_drag: bool = False, enable_transport: bool = False, end_posture: int = 0): """ 设置机器人的home位姿、拖动位姿、发货位姿,轴关节角度,Home点误差范围,详见上一个 get_quickturn_pos 功能实现 :param enable_home: 是否开启 home 点快速调整 :param enable_drag: 是否开启拖动位姿点快速调整 :param enable_transport:是否开启发货位姿点快速调整 - :param joint_home: home 位姿的关节角度 - :param joint_drag: 拖动位姿的关节角度 - :param joint_transport: 发货位姿的关节角度 :param end_posture: 末端姿态的调整方式,取值 0-6,详见 get_quickturn_pos 注释 - :param home_error_range: home点误差范围 :return: None """ - self.execution("move.set_quickturn_pos", enable_home=enable_home, enable_drag=enable_drag, enable_transport=enable_transport, joint_home=joint_home, joint_drag=joint_drag, joint_transport=joint_transport, end_posture=end_posture, home_error_range=home_error_range) + self.execution("move.set_quickturn_pos", enable_home=enable_home, enable_drag=enable_drag, enable_transport=enable_transport, end_posture=end_posture) def move2quickturn(self, name: str): """ @@ -1023,7 +995,7 @@ class HmiRequest(object): """ self.execution("jog.set_params", step=step, override=override, space=space) - def start_jog(self, index: int, direction: bool=False, is_ext: bool=False): + def start_jog(self, index: int, direction: bool = False, is_ext: bool = False): """ 开始 JOG 运动 :param index: 0-6,若选轴空间,则 0-6 对应 1-7 轴,若选笛卡尔空间,则 0-6 对应 xyzabc elb @@ -1416,43 +1388,42 @@ class HmiRequest(object): 获取机器人的运动参数:包括减速比、耦合比、最大速度、加速度、加加速度、acc ramp time、规划步长等信息 :return: { - "MOTION":{ - "JOINT_MAX_SPEED": [90, 90, 120, 120, 120, 120, 120], - "JOINT_MAX_ACC": [200, 200, 200, 200, 200, 200, 200], - "JOINT_MAX_JERK": [2000, 2000, 2000, 2000, 2000, 2000, 2000], - "TCP_MAX_SPEED": 500, + "MOTION": { + "ACC_RAMPTIME_JOG": 0.5, + "ACC_RAMPTIME_STOP": 0.5, + "DEFAULT_ACC_PARAMS": [1.0, 0.5], + "JERK_LIMIT_CART": 0, + "JERK_LIMIT_JOINT": 0, + "JERK_LIMIT_ROT": 0, + "JOINT_MAX_ACC": [500, 500, 1000, 1000, 1000], + "JOINT_MAX_JERK": [2000, 2000, 2000, 4000, 4000, 4000], + "JOINT_MAX_SPEED": [120.0, 120.0, 180.0, 180.0, 180.0, 180.0], + "MAX_ACC_PARAMS": [1.0, 1], + "MIN_ACC_PARAMS": [0.3, 0.05], "TCP_MAX_ACC": 5000, "TCP_MAX_JERK": 10000, - "TCP_ROTATE_MAX_SPEED": 180, + "TCP_MAX_SPEED": 1000, "TCP_ROTATE_MAX_ACC": 1800, "TCP_ROTATE_MAX_JERK": 3600, - "JERK_LIMIT_CART": 0, - "JERK_LIMIT_ROT": 0, - "JERK_LIMIT_JOINT": 0, - "MAX_ACC_PARAMS": [1.0, 0.1], - "MIN_ACC_PARAMS": [0.3, 0.5], - "DEFAULT_ACC_PARAMS": [1.0, 0.35], - "VEL_SMOOTH_FACTOR": 3.33, - "VEL_SMOOTH_FACTOR_RANGE": [1.0, 10.0], - "ACC_RAMPTIME_JOG": 0.01 - } + "TCP_ROTATE_MAX_SPEED": 180, + "VEL_SMOOTH_FACTOR": 1.0, + "VEL_SMOOTH_FACTOR_RANGE": [1.0, 10.0] + } } """ return self.__get_data(currentframe().f_code.co_name, "move.get_params") - def set_move_params(self, JOINT_MAX_SPEED, JOINT_MAX_ACC, JOINT_MAX_JERK, TCP_MAX_SPEED, DEFAULT_ACC_PARAMS, VEL_SMOOTH_FACTOR, ACC_RAMPTIME_JOG): + def set_move_params(self, **kwargs): """ 设置机器人的运动参数:轴最大速度、轴最大加加速度、速度、加加速度、加速度、加加速度、acc ramp time、规划步长等信息 - :param JOINT_MAX_SPEED: - :param JOINT_MAX_ACC: - :param JOINT_MAX_JERK: - :param TCP_MAX_SPEED: - :param DEFAULT_ACC_PARAMS: - :param VEL_SMOOTH_FACTOR: - :param ACC_RAMPTIME_JOG: :return: """ - self.execution("move.set_params", JOINT_MAX_SPEED=JOINT_MAX_SPEED, JOINT_MAX_ACC=JOINT_MAX_ACC, JOINT_MAX_JERK=JOINT_MAX_JERK, TCP_MAX_SPEED=TCP_MAX_SPEED, DEFAULT_ACC_PARAMS=DEFAULT_ACC_PARAMS, VEL_SMOOTH_FACTOR=VEL_SMOOTH_FACTOR, ACC_RAMPTIME_JOG=ACC_RAMPTIME_JOG) + res = self.get_move_params + keys = res.keys() + for _ in keys: + if _ in kwargs.keys(): + res[_] = kwargs[_] + self.execution("move.set_params", data=res) @property def get_quick_stop_distance(self): @@ -1479,40 +1450,37 @@ class HmiRequest(object): 获取碰撞检测相关参数 :return: { - "action": 1, // 触发行为 - 1 安全停止 2 暂停停止 3 柔顺停止 - "coeff": [100, 100, 100, 100, 100, 100], - "coeff_level": 0, - "compliance": 0, - "enable": true, - "fallback_distance": 3, - "mode": 0, - "percent": 100, - "percent_axis": [100, 100, 100, 100, 100, 100], - "reduced_percent": 100, - "reduced_percent_axis": [100, 100, 100, 100, 100, 100] + "action": 1, // 触发行为:1-安全停止;2-触发暂停;3-柔顺停止 + "coeff": [100, 100, 100, 100, 100, 100], // 0-整机灵敏度百分比,1-单轴灵敏度百分比,2-单轴和整机灵敏度百分比 + "coeff_level": 0, // 灵敏度等级:0-低,1-中,2-高 + "compliance": 0, // 柔顺功能比例系数,[0-1] + "enable": true, // 功能使能开关 + "fallback_distance": 3, // 回退距离 + "mode": 0, // 力传感器系数,0 整机 1 单轴 + "percent": 100, // 0-200,整机灵敏度百分比 + "percent_axis": [100, 100, 100, 100, 100, 100], // 0-200,单轴灵敏度百分比 + "reduced_percent": 100, // 0-200,整机缩减模式灵敏度百分比 + "reduced_percent_axis": [100, 100, 100, 100, 100, 100] // 0-200,单轴缩减模式灵敏度百分比 } """ return self.__get_data(currentframe().f_code.co_name, "collision.get_params") - def set_collision_params(self, enable, mode, action, percent, coeff=0, coeff_level=0, - percent_axis=[100, 100, 100, 100, 100, 100], fallback_distance=5, compliance=0, - reduced_percent=100, reduced_percent_axis=[100, 100, 100, 100, 100, 100]): + def set_collision_params(self, enable, mode, action, percent, **kwargs): """ 设置碰撞检测相关参数 :param enable: 功能使能开关 :param mode: 力传感器系数,0 整机 1 单轴 - :param coeff: 0-整机灵敏度百分比,1-使用单轴灵敏度百分比,2-使用单轴和整机灵敏度百分比 - :param coeff_level: 灵敏度等级:0-低,1-中,2-高 - :param action: 触发行为:1-安全停止;2-触发暂停;3-柔顺停止; + :param action: 触发行为:1-安全停止;2-触发暂停;3-柔顺停止 :param percent: 0-200,整机灵敏度百分比 - :param percent_axis: 0-200,单轴灵敏度百分比 - :param fallback_distance: 回退距离 - :param compliance: 柔顺功能比例系数,[0-1] - :param reduced_percent: 0-200,整机缩减模式灵敏度百分比 - :param reduced_percent_axis: 0-200,单轴缩减模式灵敏度百分比 :return: """ - self.execution("collision.set_params", enable=enable, mode=mode, action=action, percent=percent, coeff=coeff, coeff_level=coeff_level, percent_axis=percent_axis, fallback_distance=fallback_distance, compliance=compliance, reduced_percent=reduced_percent, reduced_percent_axis=reduced_percent_axis) + res = self.get_collision_params + keys = res.keys() + kwargs.update({"enable": enable, "mode": mode, "action": action, "percent": percent}) + for _ in keys: + if _ in kwargs.keys(): + res[_] = kwargs[_] + self.execution("collision.set_params", data=res) def set_collision_state(self, collision_state: bool): """ @@ -2000,7 +1968,6 @@ class ExternalCommunication(object): def reduced_mode_state(self): return self.__exec_cmd("reduced_mode_state", "获取缩减模式状态") - @property def get_io_state(self, io_list: str): # DO0_0,DI1_3,DO2_5,不能有空格 return self.__exec_cmd(f"io_state:{io_list}", "获取 IO 状态值")