From 790fe1fe0f257a0cd6b568e562a99800cd7324cb Mon Sep 17 00:00:00 2001 From: havoc420ubuntu <2993167370@qq.com> Date: Thu, 15 May 2025 16:49:27 +0000 Subject: [PATCH] feat(base_move): add pass_align option to arc_turn_around_hori_line function - Add pass_align parameter to arc_turn_around_hori_line function - Implement logic to skip alignment step if pass_align is True - Update task_1.py to use the new pass_align feature --- base_move/move_base_hori_line.py | 25 ++++++++++++------- task_1/task_1.py | 42 +++++++++++++++++--------------- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/base_move/move_base_hori_line.py b/base_move/move_base_hori_line.py index 46a67b8..13e0d6a 100644 --- a/base_move/move_base_hori_line.py +++ b/base_move/move_base_hori_line.py @@ -324,7 +324,10 @@ def move_to_hori_line(ctrl, msg, target_distance=0.5, observe=False): # 如果没有提供图像处理器或图像验证失败,则使用里程计数据判断 return abs(distance_moved - abs(distance_to_move)) < 0.1 # 如果误差小于10厘米,则认为成功 -def arc_turn_around_hori_line(ctrl, msg, angle_deg=90, left=True, target_distance=0.2, observe=False, scan_qrcode=False, qr_check_interval=0.3): +def arc_turn_around_hori_line(ctrl, msg, angle_deg=90, left=True, target_distance=0.2, + pass_align=False, + scan_qrcode=False, qr_check_interval=0.3, + observe=False,): """ 对准前方横线,然后以计算出来的距离为半径,做一个向左或向右的圆弧旋转。 参数: @@ -333,6 +336,7 @@ def arc_turn_around_hori_line(ctrl, msg, angle_deg=90, left=True, target_distanc target_distance: 横线前目标保持距离,默认0.5米 angle_deg: 旋转角度,支持90或180度 left: True为左转,False为右转 + pass_align: 是否跳过对准步骤,默认为False observe: 是否打印调试信息 scan_qrcode: 是否在旋转过程中扫描QR码,默认为False qr_check_interval: QR码检查间隔时间(秒),默认为0.3秒 @@ -357,14 +361,17 @@ def arc_turn_around_hori_line(ctrl, msg, angle_deg=90, left=True, target_distanc scan_qrcode = False # 1. 对准横线 - print("校准到横向线水平") - aligned = align_to_horizontal_line(ctrl, msg, observe=observe) - if not aligned: - print("无法校准到横向线水平,停止动作") - if scan_qrcode: - ctrl.image_processor.stop_async_scan() - return False, None - return False + if not pass_align: + print("校准到横向线水平") + aligned = align_to_horizontal_line(ctrl, msg, observe=observe) + if not aligned: + print("无法校准到横向线水平,停止动作") + if scan_qrcode: + ctrl.image_processor.stop_async_scan() + return False, None + return False + else: + print("跳过对准步骤") # 校准后检查是否已经扫描到QR码 if scan_qrcode: diff --git a/task_1/task_1.py b/task_1/task_1.py index f3765ba..1c4069e 100644 --- a/task_1/task_1.py +++ b/task_1/task_1.py @@ -14,36 +14,38 @@ observe = True def run_task_1(ctrl, msg): print('🐶 Running task 1...') - # v2 - print('😺 task 1 - 1') - # 在 arc_turn_around_hori_line 中启用 QR 码扫描 - turn_success, qr_result = arc_turn_around_hori_line( - ctrl=ctrl, - msg=msg, - angle_deg=85, - left=False, - observe=observe, - scan_qrcode=True, # 启用 QR 码扫描 - qr_check_interval=0.3 # 每 0.3 秒检查一次扫描结果 - ) + # # v2 + # print('😺 task 1 - 1') + # # 在 arc_turn_around_hori_line 中启用 QR 码扫描 + # turn_success, qr_result = arc_turn_around_hori_line( + # ctrl=ctrl, + # msg=msg, + # angle_deg=85, + # left=False, + # observe=observe, + # scan_qrcode=True, # 启用 QR 码扫描 + # qr_check_interval=0.3 # 每 0.3 秒检查一次扫描结果 + # ) - if qr_result: - print(f"🎯 在任务 1-1 中成功扫描到 QR 码: {qr_result}") - else: - print("⚠️ 任务 1-1 中未能扫描到任何 QR 码") + # if qr_result: + # print(f"🎯 在任务 1-1 中成功扫描到 QR 码: {qr_result}") + # else: + # print("⚠️ 任务 1-1 中未能扫描到任何 QR 码") - print('😺 task 1 - 2') - # 执行常规的移动操作,不需要 QR 码扫描 - move_to_hori_line(ctrl, msg, target_distance=1, observe=observe) + # print('😺 task 1 - 2') + # # 执行常规的移动操作,不需要 QR 码扫描 + # move_to_hori_line(ctrl, msg, target_distance=1, observe=observe) print('😺 task 1 - 3') - direction = True if qr_result == 'A-2' else False + qr_result = "A-1" + direction = True if qr_result == 'A-1' else False turn_success = arc_turn_around_hori_line( ctrl=ctrl, msg=msg, angle_deg=180, target_distance=0.5, left=direction, + pass_align=True, observe=observe, )