1. [aio.py] 取消了在本文件中开启openapi线程的做法,并修改如下: - 通过包的方式导入其他模块 - 使用current_path来规避文件路径问题 - 声名了 self.hr 变量,用来接收openapi的实例化 - 修改了对于segment button的错误调用 - 设定progress bar的长度是10 - 完善了segmented_button_callback函数 - 在detect_network函数中增加heartbeat初始化 - tabview_click函数中新增textbox清屏功能,以及实例化openapi,并做检测 2. [openapi.py] 取消了初始化中无限循环检测,因为阻塞了aio主界面进程!!!socket也无法多次连接!!!浪费了好多时间!!!很生气!!!! - 通过tabview切换来实现重新连接,并保留了异常处理部分 - 将所有的 __xxxx 函数都替换成 xxxx 函数,去掉了 __ - 使用current_path来规避文件路径问题 3. [do_brake.py] 初步完成了机器状态收集的功能,还需要完善 - 使用current_path来规避文件路径问题 - 新增validate_resp函数,校验数据 - 完善了调用接口
77 lines
2.3 KiB
Python
77 lines
2.3 KiB
Python
import json
|
|
from os.path import dirname
|
|
from sys import argv
|
|
|
|
current_path = dirname(__file__)
|
|
|
|
|
|
def validate_resp(_id, response, w2t):
|
|
match _id:
|
|
case 'DATA ERR':
|
|
w2t(f"数据处理错误,需要确认", 0, 4, 'red')
|
|
case 'DATA READ ERR':
|
|
w2t(f"无法读取数据,需要确认", 0, 3, 'red')
|
|
case 'NOT SUPPORT':
|
|
w2t(f"不支持的功能,需要确认", 0, 2, 'red')
|
|
if not response:
|
|
w2t(f"无法获取{id}请求的响应信息", 0, 1, 'red')
|
|
|
|
|
|
def get_state(hr, w2t):
|
|
# 获取机器状态
|
|
_id = hr.excution('state.get_state')
|
|
_msg = hr.get_from_id(_id)
|
|
if not _msg:
|
|
w2t(f"无法获取{_id}请求的响应信息", 0, 6, 'red')
|
|
else:
|
|
_response = json.loads(_msg)['data']
|
|
validate_resp(_id, _response, w2t)
|
|
|
|
stat_desc = {'engine': '上电状态', 'operate': '操作模式', 'rc_state': '控制器状态', 'robot_action': '机器人动作', 'safety_mode': '安全模式', 'servo_mode': '伺服工作模式', 'task_space': '工作任务空间'}
|
|
for component, state in _response.items():
|
|
w2t(f"{stat_desc[component]}: {state}")
|
|
|
|
_id = hr.excution('device.get_params')
|
|
_msg = hr.get_from_id(_id)
|
|
if not _msg:
|
|
w2t(f"无法获取{_id}请求的响应信息", 0, 6, 'red')
|
|
else:
|
|
_response = json.loads(_msg)['data']['devices']
|
|
validate_resp(_id, _response, w2t)
|
|
dev_desc = {0: '伺服版本', 1: '伺服参数', 2: '安全板固件', 3: '控制器', 4: '通讯总线', 5: '解释器', 6: '运动控制', 8: '力控版本', 9: '末端固件', 10: '机型文件', 11: '环境包'}
|
|
dev_vers = {}
|
|
for device in _response:
|
|
dev_vers[device['type']] = device['version']
|
|
for i in sorted(dev_desc.keys()):
|
|
w2t(f"{dev_desc[i]}: {dev_vers[i]}")
|
|
|
|
|
|
def main(hr, func, w2t):
|
|
# func: get_state/
|
|
match func:
|
|
case 'get_state':
|
|
get_state(hr, w2t)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main(*argv[1:])
|
|
|
|
|
|
# 一、设置/检测机器人状态:
|
|
# 1. 上电
|
|
# 2. 软限位打开
|
|
# 3. 示教器断开
|
|
# 4. 操作模式/机器人类型
|
|
# 5. 控制器状态/工作任务控件/机器人动态
|
|
|
|
# 二、加载RL程序开始运行
|
|
# 1. 怎么触发急停
|
|
# 2. 怎么恢复急停
|
|
# 3. 怎么采集曲线
|
|
# 4.
|
|
|
|
# 三、运行过程中,收集数据,并处理出结果
|
|
|
|
# 四
|
|
|