- 在 move_to_hori_line 函数中添加 scan_qrcode 和 qr_check_interval 参数,支持在移动过程中异步扫描 QR 码 - 实现异步 QR 码扫描机制,确保在移动时能够实时获取扫描结果 - 更新返回值,根据是否启用 QR 码扫描返回不同格式的结果 - 在 task_1.py 中调用 move_to_hori_line 函数时启用 QR 码扫描,并处理扫描结果 - 在 image_raw.py 中实现异步扫描的相关逻辑,确保图像处理器能够支持 QR 码扫描功能
69 lines
1.9 KiB
Python
69 lines
1.9 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(ctrl, msg, angle_deg=70, left=False, observe=observe)
|
||
|
||
print('😺 task 1 - 2')
|
||
# 使用内置的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码")
|
||
|
||
return
|
||
|
||
print('😺 task 1 - 3')
|
||
arc_turn_around_hori_line(ctrl, msg, angle_deg=160, left=True, observe=observe)
|
||
|
||
print('😺 task 1 - 4')
|
||
move_to_hori_line(ctrl, msg, observe=observe)
|
||
|
||
|
||
# 保留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
|
||
)
|
||
|
||
|
||
|