import time import sys import os import math # 添加父目录到路径,以便能够导入utils sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from base_move.move_base_hori_line import move_to_hori_line, arc_turn_around_hori_line, align_to_horizontal_line from utils.detect_track import detect_horizontal_track_edge from base_move.move_base_hori_line import calculate_distance_to_line from base_move.go_straight import go_straight observe = False 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 秒检查一次扫描结果 ) 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 - 3') # direction = True if qr_result == 'A-1' else False # TODO turn_success = arc_turn_around_hori_line( ctrl=ctrl, msg=msg, angle_deg=170, target_distance=0.4, # TODO 优化这里的参数 left=False, # direction, pass_align=True, observe=observe, # TODO clear bad_big_angle_corret=True ) print('😺 task 1 - 4') move_distance = 0.4 go_straight(ctrl, msg, distance=move_distance, speed=0.5, observe=observe) # move_to_hori_line(ctrl, msg, target_distance=0.6, observe=observe) print('😺 task 1 - 5 休眠,模拟装货') ctrl.base_msg.lie_down(wait_time=3000) # TODO 比赛时改成 5s # 站起来 ctrl.base_msg.stand_up() print('😺 task 1 - 6 back') go_straight(ctrl, msg, distance=-move_distance + 0.1, speed=0.5, observe=observe)