v0.2.0.3(2024/07/27)

1. [APIs: do_brake.py]: 精简程序,解决 OOM 问题
2. [APIs: do_current.py]: 精简程序,解决 OOM 问题
3. [APIs: factory_test.py]: 精简程序,解决 OOM 问题
4. [APIsL openapi.py]
   - 心跳修改为 1 s,因为 OOM 问题的解决依赖于长久的打开曲线开关,此时对于 hr.c_msg 的定时清理是个挑战,将心跳缩短,有利于清理日志后,避免丢失心跳
   - 新增 diagnosis.save 命令,但是执行时,有问题,待解决
This commit is contained in:
2024-07-27 21:31:09 +08:00
parent d2794b2de7
commit b01f8dc19c
12 changed files with 101 additions and 113 deletions

View File

@ -90,9 +90,8 @@ def prj_to_xcore(prj_file):
print(stdout.read().decode()) # 必须得输出一下stdout才能正确执行sudo
print(stderr.read().decode()) # 顺便也执行以下stderr
# _prj_name = prj_file.split('\\')[-1].removesuffix('.zip')
cmd = 'cd /home/luoshi/bin/controller/; '
cmd += f'sudo mv projects/target/_build/*.prj projects/target/_build/target.prj'
cmd += 'sudo mv projects/target/_build/*.prj projects/target/_build/target.prj'
stdin, stdout, stderr = ssh.exec_command(cmd, get_pty=True)
stdin.write('luoshi2019' + '\n')
stdin.flush()
@ -120,13 +119,18 @@ def gen_result_file(path, curve_data, axis, _reach, _load, _speed, count):
for data in curve_data:
dict_results = data['data']
for item in dict_results:
item['value'].reverse()
try:
item['value'].reverse()
except KeyError:
continue
if item.get('channel', None) == axis-1 and item.get('name', None) == 'hw_joint_vel_feedback':
_d2d_vel['hw_joint_vel_feedback'].extend(item['value'])
elif item.get('channel', None) == axis-1 and item.get('name', None) == 'device_servo_trq_feedback':
_d2d_trq['device_servo_trq_feedback'].extend(item['value'])
elif item.get('channel', None) == 0 and item.get('name', None) == 'device_safety_estop':
_d2d_stop['device_safety_estop'].extend(item['value'])
if len(_d2d_trq['device_servo_trq_feedback']) / 1000 > 10:
break
df1 = pandas.DataFrame.from_dict(_d2d_vel)
df2 = pandas.DataFrame.from_dict(_d2d_trq)
@ -164,6 +168,8 @@ def run_rl(path, loadsel, hr, md, config_file, result_dirs, w2t):
else:
w2t("configs.xlsx中Target页面A1单元格填写不正确检查后重新运行...", 0, 111, 'red', tab_name)
_response = execution('diagnosis.open', hr, w2t, open=True, display_open=True)
_response = execution('diagnosis.set_params', hr, w2t, display_pdo_params=display_pdo_params)
for condition in result_dirs:
_reach = condition.split('_')[0].removeprefix('reach')
_load = condition.split('_')[1].removeprefix('load')
@ -189,9 +195,7 @@ def run_rl(path, loadsel, hr, md, config_file, result_dirs, w2t):
md.reset_estop()
md.clear_alarm()
md.write_act(0)
_response = execution('diagnosis.open', hr, w2t, open=True, display_open=True)
sleep(write_diagnosis) # 软急停超差后等待写诊断时间可通过configs.xlsx配置
_response = execution('diagnosis.open', hr, w2t, open=False, display_open=False)
while count == 1:
# 2. 修改未要执行的场景
@ -236,16 +240,12 @@ def run_rl(path, loadsel, hr, md, config_file, result_dirs, w2t):
else:
sleep(1)
# 4. 打开诊断曲线并执行采集之后触发软急停关闭曲线采集找出最大速度传递给RL程序最后清除相关记录
_response = execution('diagnosis.open', hr, w2t, open=True, display_open=True)
_response = execution('diagnosis.set_params', hr, w2t, display_pdo_params=display_pdo_params)
sleep(get_init_speed) # 获取实际最大速度可通过configs.xlsx配置
_response = execution('rl_task.stop', hr, w2t, tasks=['brake'])
sleep(1)
_response = execution('state.switch_motor_off', hr, w2t)
_response = execution('state.switch_manual', hr, w2t)
_response = execution('diagnosis.open', hr, w2t, open=False, display_open=False)
# sleep(1)
# 找出最大速度
for _msg in hr.c_msg:
_c_msg = hr.c_msg.copy()
for _msg in _c_msg:
if 'diagnosis.result' in _msg:
dict_results = loads(_msg)['data']
for item in dict_results:
@ -262,14 +262,10 @@ def run_rl(path, loadsel, hr, md, config_file, result_dirs, w2t):
w2t(f"Axis: {axis}-{count} | Speed: {speed_max} | Shouldbe: {speed_target}", 0, 0, 'indigo', tab_name)
md.write_speed_max(speed_max)
sleep(1)
for _msg in hr.c_msg:
if 'diagnosis.result' in _msg:
_index = hr.c_msg.index(_msg)
del hr.c_msg[_index:]
hr.c_msg_xs.clear()
break
hr.c_msg_xs.clear()
if len(hr.c_msg) > 240:
del hr.c_msg[240:]
if speed_max < 10:
md.clear_alarm()
@ -296,8 +292,6 @@ def run_rl(path, loadsel, hr, md, config_file, result_dirs, w2t):
else:
w2t("未收到机器人的运行信号需要确认RL程序编写正确并正常执行...", 0, 111, 'red', tab_name)
_response = execution('diagnosis.open', hr, w2t, open=True, display_open=True)
_response = execution('diagnosis.set_params', hr, w2t, display_pdo_params=display_pdo_params)
sleep(10) # 排除从其他位姿到零点位姿,再到轴极限位姿的时间
md.write_probe(1)
_t_start = time()
@ -305,29 +299,25 @@ def run_rl(path, loadsel, hr, md, config_file, result_dirs, w2t):
if md.read_brake_done() == 1:
sleep(1) # 保证速度归零
md.write_probe(0)
_response = execution('diagnosis.open', hr, w2t, open=False, display_open=False)
break
else:
if (time() - _t_start) > 30:
w2t(f"30s内未触发急停该条数据无效需要确认RL/Python程序编写正确并正常执行或者判别是否是机器本体问题比如正负方向速度是否一致...", 0, 0, 'red', tab_name)
md.write_probe(0)
_response = execution('diagnosis.open', hr, w2t, open=False, display_open=False)
break
else:
sleep(1)
# 6. 保留数据并处理输出
curve_data = []
for _msg in hr.c_msg:
_c_msg = hr.c_msg.copy()
for _msg in _c_msg:
if 'diagnosis.result' in _msg:
curve_data.insert(0, loads(_msg))
else:
for _msg in hr.c_msg:
if 'diagnosis.result' in _msg:
_index = hr.c_msg.index(_msg)
del hr.c_msg[_index:]
hr.c_msg_xs.clear()
break
hr.c_msg_xs.clear()
if len(hr.c_msg) > 240:
del hr.c_msg[240:]
gen_result_file(path, curve_data, axis, _reach, _load, _speed, count)
else:
w2t(f"\n{loadsel.removeprefix('tool')}%负载的制动性能测试执行完毕,如需采集其他负载,须切换负载类型,并更换其他负载,重新执行。", 0, 0, 'green', tab_name)