refactor(task): 优化任务执行流程和代码结构
- 在 move_base_hori_line.py 中添加了返回中间状态的逻辑,提高了代码的可扩展性 - 优化了 QR 码扫描的处理流程,增强了代码的鲁棒性 - 在 task_1.py 中调整了任务 1 的执行流程,缩短了模拟装货的等待时间
This commit is contained in:
parent
18248d7ad9
commit
97dd5a22dc
@ -347,6 +347,10 @@ def arc_turn_around_hori_line(ctrl, msg, angle_deg=90, left=True, target_distanc
|
|||||||
bool或元组: 如果scan_qrcode为False,返回bool表示是否成功完成操作;
|
bool或元组: 如果scan_qrcode为False,返回bool表示是否成功完成操作;
|
||||||
如果scan_qrcode为True,返回(bool, str)元组,表示(是否成功完成操作, QR码扫描结果)
|
如果scan_qrcode为True,返回(bool, str)元组,表示(是否成功完成操作, QR码扫描结果)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# 返回此任务的中间状态
|
||||||
|
res = {}
|
||||||
|
|
||||||
# 启动异步QR码扫描(如果需要)
|
# 启动异步QR码扫描(如果需要)
|
||||||
qr_result = None
|
qr_result = None
|
||||||
if scan_qrcode:
|
if scan_qrcode:
|
||||||
@ -388,10 +392,6 @@ def arc_turn_around_hori_line(ctrl, msg, angle_deg=90, left=True, target_distanc
|
|||||||
|
|
||||||
camera_height = 0.355 # 单位: 米
|
camera_height = 0.355 # 单位: 米
|
||||||
r = calculate_distance_to_line(edge_info, camera_height, observe=observe)
|
r = calculate_distance_to_line(edge_info, camera_height, observe=observe)
|
||||||
|
|
||||||
# 减去目标距离
|
|
||||||
r -= target_distance
|
|
||||||
|
|
||||||
if r is None:
|
if r is None:
|
||||||
print("无法计算到横向线的距离,停止动作")
|
print("无法计算到横向线的距离,停止动作")
|
||||||
if scan_qrcode:
|
if scan_qrcode:
|
||||||
@ -399,6 +399,9 @@ def arc_turn_around_hori_line(ctrl, msg, angle_deg=90, left=True, target_distanc
|
|||||||
return False, qr_result
|
return False, qr_result
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# 减去目标距离
|
||||||
|
r -= target_distance
|
||||||
|
|
||||||
if observe:
|
if observe:
|
||||||
print(f"当前距离: {r:.3f}米")
|
print(f"当前距离: {r:.3f}米")
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ def run_task_1(ctrl, msg):
|
|||||||
# move_to_hori_line(ctrl, msg, target_distance=0.6, observe=observe)
|
# move_to_hori_line(ctrl, msg, target_distance=0.6, observe=observe)
|
||||||
|
|
||||||
print('😺 task 1 - 5 休眠,模拟装货')
|
print('😺 task 1 - 5 休眠,模拟装货')
|
||||||
ctrl.base_msg.lie_down(wait_time=5000)
|
ctrl.base_msg.lie_down(wait_time=3000) # TODO 比赛时改成 5s
|
||||||
|
|
||||||
# 站起来
|
# 站起来
|
||||||
ctrl.base_msg.stand_up()
|
ctrl.base_msg.stand_up()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user