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 15:22:26 +00:00
|
|
|
|
arc_turn_around_hori_line(ctrl, msg, angle_deg=85, left=False, observe=observe)
|
|
|
|
|
|
2025-05-15 14:37:53 +00:00
|
|
|
|
print('😺 task 1 - 2')
|
2025-05-15 23:17:29 +08:00
|
|
|
|
# 使用内置的QR码扫描功能执行移动
|
|
|
|
|
move_success, qr_result = move_to_hori_line(
|
|
|
|
|
ctrl=ctrl,
|
|
|
|
|
msg=msg,
|
|
|
|
|
target_distance=1,
|
|
|
|
|
observe=observe,
|
|
|
|
|
scan_qrcode=True, # 启用QR码扫描
|
|
|
|
|
qr_check_interval=0.3 # 每0.3秒检查一次QR码结果
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if qr_result:
|
|
|
|
|
print(f"🎯 成功扫描到QR码: {qr_result}")
|
|
|
|
|
else:
|
|
|
|
|
print("⚠️ 未能扫描到任何QR码")
|
2025-05-12 08:06:08 +00:00
|
|
|
|
|
2025-05-15 14:37:53 +00:00
|
|
|
|
print('😺 task 1 - 3')
|
2025-05-15 15:22:26 +00:00
|
|
|
|
arc_turn_around_hori_line(ctrl, msg, angle_deg=180, target_distance=0.4, left=True, observe=observe)
|
|
|
|
|
|
|
|
|
|
return
|
2025-05-15 14:37:53 +00:00
|
|
|
|
|
|
|
|
|
print('😺 task 1 - 4')
|
2025-05-15 19:53:36 +08:00
|
|
|
|
move_to_hori_line(ctrl, msg, observe=observe)
|
2025-05-12 08:06:08 +00:00
|
|
|
|
|
|
|
|
|
|
2025-05-15 23:17:29 +08:00
|
|
|
|
# 保留move_with_qr_scan函数作为备份,如果需要特殊处理可以使用
|
|
|
|
|
def move_with_qr_scan(ctrl, msg, target_distance=0.5, observe=False):
|
|
|
|
|
"""
|
|
|
|
|
结合移动到指定位置和 QR 码扫描功能的函数,使用异步扫描
|
|
|
|
|
|
|
|
|
|
参数:
|
|
|
|
|
ctrl: Robot_Ctrl 对象
|
|
|
|
|
msg: 机器人控制消息对象
|
|
|
|
|
target_distance: 目标距离
|
|
|
|
|
observe: 是否打印调试信息
|
|
|
|
|
"""
|
|
|
|
|
# 直接使用内置的扫描功能
|
|
|
|
|
return move_to_hori_line(
|
|
|
|
|
ctrl=ctrl,
|
|
|
|
|
msg=msg,
|
|
|
|
|
target_distance=target_distance,
|
|
|
|
|
observe=observe,
|
|
|
|
|
scan_qrcode=True,
|
|
|
|
|
qr_check_interval=0.3
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2025-05-11 15:44:54 +00:00
|
|
|
|
|