mi-task/task_1/task_1.py

60 lines
1.7 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
2025-05-16 11:35:53 +00:00
observe = False
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 码扫描
2025-05-16 11:35:53 +00:00
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 秒检查一次扫描结果
)
2025-05-16 11:35:53 +00:00
if qr_result:
print(f"🎯 在任务 1-1 中成功扫描到 QR 码: {qr_result}")
else:
print("⚠️ 任务 1-1 中未能扫描到任何 QR 码")
2025-05-16 11:35:53 +00:00
print('😺 task 1 - 2')
# 执行常规的移动操作,不需要 QR 码扫描
move_to_hori_line(ctrl, msg, target_distance=1, observe=observe)
print('😺 task 1 - 3')
2025-05-16 11:35:53 +00:00
# direction = True if qr_result == 'A-1' else False
# TODO
turn_success = arc_turn_around_hori_line(
ctrl=ctrl,
msg=msg,
2025-05-16 11:35:53 +00:00
angle_deg=170,
target_distance=0.4, # TODO 优化这里的参数
left=False, # direction,
pass_align=True,
observe=observe,
2025-05-16 11:35:53 +00:00
# TODO clear
bad_big_angle_corret=True
)
print('😺 task 1 - 4')
2025-05-16 11:35:53 +00:00
# move_to_hori_line(ctrl, msg, target_distance=0.6, observe=observe)
2025-05-16 11:35:53 +00:00
print('😺 task 1 - 5 休眠,模拟装货')
2025-05-11 15:44:54 +00:00