mi-task/task_1/task_1.py
havoc420ubuntu 214cc13c65 refactor(base_move): adjust moving strategy and update task execution
- Set msg.duration to 0 in move_to_hori_line to wait for next command
- Update task_1 execution flow based on QR code result
- Modify BaseMsg.stop() to use gait_id 27 for stopping
- Comment out smooth stop and use normal stop in move_to_hori_line
2025-05-15 16:41:00 +00:00

57 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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')
direction = True if qr_result == 'A-2' else False
turn_success = arc_turn_around_hori_line(
ctrl=ctrl,
msg=msg,
angle_deg=180,
target_distance=0.5,
left=direction,
observe=observe,
)
return
print('😺 task 1 - 4')
move_to_hori_line(ctrl, msg, observe=observe)