mi-task/task_1/task_1.py

59 lines
1.6 KiB
Python
Raw Normal View History

2025-05-11 15:44:54 +00:00
import time
2025-05-14 11:25:44 +00:00
import sys
import os
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__))))
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
2025-05-14 12:12:57 +00:00
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_result = "A-1"
direction = True if qr_result == 'A-1' else False
turn_success = arc_turn_around_hori_line(
ctrl=ctrl,
msg=msg,
angle_deg=180,
target_distance=0.5,
left=direction,
pass_align=True,
observe=observe,
)
return
print('😺 task 1 - 4')
move_to_hori_line(ctrl, msg, observe=observe)
2025-05-11 15:44:54 +00:00