完成了电流->转矩的转变,基本完成
This commit is contained in:
@@ -10,7 +10,7 @@ from common import clibs, openapi
|
||||
|
||||
def initialization(path, sub, data_dirs, data_files, hr, w2t):
|
||||
def check_files():
|
||||
msg = "初始路径下不允许有文件夹,且初始路径下只能存在如下五个文件,确认后重新运行!\n"
|
||||
msg = "初始路径下不允许有文件夹,初始路径下只能存在如下五个文件,且文件为关闭状态,确认后重新运行!\n"
|
||||
msg += "1. configs.xlsx\n2. reach33/reach66/reach100_xxxx.xlsx\n3. xxxx.zip\n"
|
||||
if len(data_dirs) != 0 or len(data_files) != 5:
|
||||
w2t(msg, "red", "InitFileError")
|
||||
@@ -130,16 +130,19 @@ def gen_result_file(path, axis, t_end, reach, load, speed, speed_target, rounds,
|
||||
df.to_csv(filename, sep="\t", index=False)
|
||||
|
||||
|
||||
def change_curve_state(hr, stat_1, stat_2):
|
||||
display_pdo_params = [{"name": name, "channel": chl} for name in ["hw_joint_vel_feedback", "device_servo_trq_feedback"] for chl in range(6)]
|
||||
display_pdo_params.append({"name": "device_safety_estop", "channel": 0})
|
||||
hr.execution("diagnosis.open", open=stat_1, display_open=stat_2, overrun=True, turn_area=True, delay_motion=False)
|
||||
def change_curve_state(hr, stat):
|
||||
if not stat:
|
||||
display_pdo_params = []
|
||||
else:
|
||||
display_pdo_params = [{"name": name, "channel": chl} for name in ["hw_joint_vel_feedback", "device_servo_trq_feedback"] for chl in range(6)]
|
||||
display_pdo_params.append({"name": "device_safety_estop", "channel": 0})
|
||||
hr.execution("diagnosis.open", open=stat, display_open=stat, overrun=True, turn_area=True, delay_motion=False)
|
||||
hr.execution("diagnosis.set_params", display_pdo_params=display_pdo_params, frequency=50, version="1.4.1")
|
||||
|
||||
|
||||
def run_rl(path, sub, hr, md, config_file, prj_file, result_dirs, avs, w2t):
|
||||
count, total, speed_target = 0, 63, 0
|
||||
prj_name = prj_file.split("/")[-1].split(".")[0]
|
||||
prj_name = ".".join(prj_file.split("/")[-1].split(".")[:-1])
|
||||
wb = openpyxl.load_workbook(config_file, read_only=True)
|
||||
ws = wb["Target"]
|
||||
write_diagnosis = float(ws.cell(row=2, column=2).value)
|
||||
@@ -171,6 +174,10 @@ def run_rl(path, sub, hr, md, config_file, prj_file, result_dirs, avs, w2t):
|
||||
continue
|
||||
|
||||
for axis in range(1, 4):
|
||||
if not clibs.running:
|
||||
w2t("后台数据清零完成,现在可以重新运行之前停止的程序。", "red")
|
||||
exit()
|
||||
|
||||
# for single condition test
|
||||
if (single_axis != -1 and single_axis != axis) or (axis == 3 and reach != "100"):
|
||||
continue
|
||||
@@ -231,16 +238,16 @@ def run_rl(path, sub, hr, md, config_file, prj_file, result_dirs, avs, w2t):
|
||||
break
|
||||
else:
|
||||
time.sleep(1)
|
||||
if (time.time() - t_start) > 20:
|
||||
w2t("20s 内未收到机器人的运行信号,需要确认 RL 程序编写正确并正常执行...", "red", "ReadySignalTimeoutError")
|
||||
if (time.time() - t_start) > 3:
|
||||
w2t("3s 内未收到机器人的运行信号,需要确认 RL 程序编写正确并正常执行...", "red", "ReadySignalTimeoutError")
|
||||
# 4. 找出最大速度,传递给RL程序,最后清除相关记录
|
||||
time.sleep(5) # 消除前 5s 的不稳定数据
|
||||
change_curve_state(hr, True, True)
|
||||
change_curve_state(hr, True)
|
||||
start_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
|
||||
time.sleep(get_init_speed) # 指定时间后获取实际【正|负】方向的最大速度,可通过configs.xlsx配置
|
||||
end_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
|
||||
hr.execution("rl_task.stop", tasks=["brake"])
|
||||
change_curve_state(hr, False, False)
|
||||
change_curve_state(hr, False)
|
||||
|
||||
# 找出最大速度
|
||||
@clibs.db_lock
|
||||
@@ -297,7 +304,7 @@ def run_rl(path, sub, hr, md, config_file, prj_file, result_dirs, avs, w2t):
|
||||
|
||||
def exec_brake():
|
||||
flag, start, data, record = True, time.time(), None, None
|
||||
change_curve_state(hr, True, True)
|
||||
change_curve_state(hr, True)
|
||||
while flag:
|
||||
time.sleep(0.05)
|
||||
if time.time() - start > 20:
|
||||
@@ -320,7 +327,7 @@ def run_rl(path, sub, hr, md, config_file, prj_file, result_dirs, avs, w2t):
|
||||
if (pon == "positive" and speed_moment > 0) or (pon == "negative" and speed_moment < 0):
|
||||
clibs.c_ec.setdo_value(io_name, "false")
|
||||
time.sleep(2)
|
||||
change_curve_state(hr, False, False)
|
||||
change_curve_state(hr, False)
|
||||
flag = False
|
||||
return time.time()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user