2025-05-11 15:44:54 +00:00
|
|
|
|
import time
|
2025-05-14 11:25:44 +00:00
|
|
|
|
import sys
|
|
|
|
|
import os
|
2025-05-15 23:17:29 +08:00
|
|
|
|
import math
|
2025-05-11 15:44:54 +00:00
|
|
|
|
|
2025-05-14 11:25:44 +00:00
|
|
|
|
# 添加父目录到路径,以便能够导入utils
|
|
|
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
2025-05-15 23:17:29 +08:00
|
|
|
|
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
|
2025-05-12 08:06:08 +00:00
|
|
|
|
|
2025-05-15 12:44:48 +00:00
|
|
|
|
observe = True
|
2025-05-14 12:12:57 +00:00
|
|
|
|
|
2025-05-14 19:35:29 +08:00
|
|
|
|
def run_task_1(ctrl, msg):
|
2025-05-15 14:37:53 +00:00
|
|
|
|
print('🐶 Running task 1...')
|
2025-05-12 08:06:08 +00:00
|
|
|
|
|
2025-05-14 11:25:44 +00:00
|
|
|
|
# v2
|
2025-05-15 14:37:53 +00:00
|
|
|
|
print('😺 task 1 - 1')
|
2025-05-15 23:42:09 +08:00
|
|
|
|
# 在 arc_turn_around_hori_line 中启用 QR 码扫描
|
|
|
|
|
turn_success, qr_result = arc_turn_around_hori_line(
|
2025-05-15 23:17:29 +08:00
|
|
|
|
ctrl=ctrl,
|
|
|
|
|
msg=msg,
|
2025-05-15 23:42:09 +08:00
|
|
|
|
angle_deg=85,
|
|
|
|
|
left=False,
|
2025-05-15 23:17:29 +08:00
|
|
|
|
observe=observe,
|
2025-05-15 23:42:09 +08:00
|
|
|
|
scan_qrcode=True, # 启用 QR 码扫描
|
|
|
|
|
qr_check_interval=0.3 # 每 0.3 秒检查一次扫描结果
|
2025-05-15 23:17:29 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if qr_result:
|
2025-05-15 23:42:09 +08:00
|
|
|
|
print(f"🎯 在任务 1-1 中成功扫描到 QR 码: {qr_result}")
|
2025-05-15 23:17:29 +08:00
|
|
|
|
else:
|
2025-05-15 23:42:09 +08:00
|
|
|
|
print("⚠️ 任务 1-1 中未能扫描到任何 QR 码")
|
2025-05-12 08:06:08 +00:00
|
|
|
|
|
2025-05-15 23:42:09 +08:00
|
|
|
|
print('😺 task 1 - 2')
|
|
|
|
|
# 执行常规的移动操作,不需要 QR 码扫描
|
|
|
|
|
move_to_hori_line(ctrl, msg, target_distance=1, observe=observe)
|
2025-05-12 08:06:08 +00:00
|
|
|
|
|
2025-05-15 23:42:09 +08:00
|
|
|
|
print('😺 task 1 - 3')
|
|
|
|
|
# 在第二次旋转操作中也启用 QR 码扫描
|
|
|
|
|
turn_success, qr_result = arc_turn_around_hori_line(
|
2025-05-15 23:17:29 +08:00
|
|
|
|
ctrl=ctrl,
|
2025-05-15 23:42:09 +08:00
|
|
|
|
msg=msg,
|
|
|
|
|
angle_deg=180,
|
|
|
|
|
target_distance=0.4,
|
|
|
|
|
left=True,
|
2025-05-15 23:17:29 +08:00
|
|
|
|
observe=observe,
|
|
|
|
|
scan_qrcode=True,
|
|
|
|
|
qr_check_interval=0.3
|
|
|
|
|
)
|
2025-05-15 23:42:09 +08:00
|
|
|
|
|
|
|
|
|
if qr_result:
|
|
|
|
|
print(f"🎯 在任务 1-3 中成功扫描到 QR 码: {qr_result}")
|
|
|
|
|
else:
|
|
|
|
|
print("⚠️ 任务 1-3 中未能扫描到任何 QR 码")
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
print('😺 task 1 - 4')
|
|
|
|
|
move_to_hori_line(ctrl, msg, observe=observe)
|
2025-05-15 23:17:29 +08:00
|
|
|
|
|
|
|
|
|
|
2025-05-11 15:44:54 +00:00
|
|
|
|
|