- 移除 move_to_hori_line 函数中的 QR 码扫描相关参数,简化函数接口 - 在 arc_turn_around_hori_line 函数中添加 QR 码扫描功能,支持在旋转过程中异步扫描 QR 码 - 更新 task_1.py 中的任务执行逻辑,确保在旋转和移动过程中能够实时获取 QR 码扫描结果 - 增强调试信息输出,便于跟踪任务执行状态
64 lines
1.8 KiB
Python
64 lines
1.8 KiB
Python
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
|
||
|
||
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 秒检查一次扫描结果
|
||
)
|
||
|
||
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')
|
||
# 在第二次旋转操作中也启用 QR 码扫描
|
||
turn_success, qr_result = arc_turn_around_hori_line(
|
||
ctrl=ctrl,
|
||
msg=msg,
|
||
angle_deg=180,
|
||
target_distance=0.4,
|
||
left=True,
|
||
observe=observe,
|
||
scan_qrcode=True,
|
||
qr_check_interval=0.3
|
||
)
|
||
|
||
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)
|
||
|
||
|
||
|