feat(base_move): add pass_align option to arc_turn_around_hori_line function
- Add pass_align parameter to arc_turn_around_hori_line function - Implement logic to skip alignment step if pass_align is True - Update task_1.py to use the new pass_align feature
This commit is contained in:
parent
214cc13c65
commit
790fe1fe0f
@ -324,7 +324,10 @@ def move_to_hori_line(ctrl, msg, target_distance=0.5, observe=False):
|
|||||||
# 如果没有提供图像处理器或图像验证失败,则使用里程计数据判断
|
# 如果没有提供图像处理器或图像验证失败,则使用里程计数据判断
|
||||||
return abs(distance_moved - abs(distance_to_move)) < 0.1 # 如果误差小于10厘米,则认为成功
|
return abs(distance_moved - abs(distance_to_move)) < 0.1 # 如果误差小于10厘米,则认为成功
|
||||||
|
|
||||||
def arc_turn_around_hori_line(ctrl, msg, angle_deg=90, left=True, target_distance=0.2, observe=False, scan_qrcode=False, qr_check_interval=0.3):
|
def arc_turn_around_hori_line(ctrl, msg, angle_deg=90, left=True, target_distance=0.2,
|
||||||
|
pass_align=False,
|
||||||
|
scan_qrcode=False, qr_check_interval=0.3,
|
||||||
|
observe=False,):
|
||||||
"""
|
"""
|
||||||
对准前方横线,然后以计算出来的距离为半径,做一个向左或向右的圆弧旋转。
|
对准前方横线,然后以计算出来的距离为半径,做一个向左或向右的圆弧旋转。
|
||||||
参数:
|
参数:
|
||||||
@ -333,6 +336,7 @@ def arc_turn_around_hori_line(ctrl, msg, angle_deg=90, left=True, target_distanc
|
|||||||
target_distance: 横线前目标保持距离,默认0.5米
|
target_distance: 横线前目标保持距离,默认0.5米
|
||||||
angle_deg: 旋转角度,支持90或180度
|
angle_deg: 旋转角度,支持90或180度
|
||||||
left: True为左转,False为右转
|
left: True为左转,False为右转
|
||||||
|
pass_align: 是否跳过对准步骤,默认为False
|
||||||
observe: 是否打印调试信息
|
observe: 是否打印调试信息
|
||||||
scan_qrcode: 是否在旋转过程中扫描QR码,默认为False
|
scan_qrcode: 是否在旋转过程中扫描QR码,默认为False
|
||||||
qr_check_interval: QR码检查间隔时间(秒),默认为0.3秒
|
qr_check_interval: QR码检查间隔时间(秒),默认为0.3秒
|
||||||
@ -357,14 +361,17 @@ def arc_turn_around_hori_line(ctrl, msg, angle_deg=90, left=True, target_distanc
|
|||||||
scan_qrcode = False
|
scan_qrcode = False
|
||||||
|
|
||||||
# 1. 对准横线
|
# 1. 对准横线
|
||||||
print("校准到横向线水平")
|
if not pass_align:
|
||||||
aligned = align_to_horizontal_line(ctrl, msg, observe=observe)
|
print("校准到横向线水平")
|
||||||
if not aligned:
|
aligned = align_to_horizontal_line(ctrl, msg, observe=observe)
|
||||||
print("无法校准到横向线水平,停止动作")
|
if not aligned:
|
||||||
if scan_qrcode:
|
print("无法校准到横向线水平,停止动作")
|
||||||
ctrl.image_processor.stop_async_scan()
|
if scan_qrcode:
|
||||||
return False, None
|
ctrl.image_processor.stop_async_scan()
|
||||||
return False
|
return False, None
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
print("跳过对准步骤")
|
||||||
|
|
||||||
# 校准后检查是否已经扫描到QR码
|
# 校准后检查是否已经扫描到QR码
|
||||||
if scan_qrcode:
|
if scan_qrcode:
|
||||||
|
@ -14,36 +14,38 @@ observe = True
|
|||||||
def run_task_1(ctrl, msg):
|
def run_task_1(ctrl, msg):
|
||||||
print('🐶 Running task 1...')
|
print('🐶 Running task 1...')
|
||||||
|
|
||||||
# v2
|
# # v2
|
||||||
print('😺 task 1 - 1')
|
# print('😺 task 1 - 1')
|
||||||
# 在 arc_turn_around_hori_line 中启用 QR 码扫描
|
# # 在 arc_turn_around_hori_line 中启用 QR 码扫描
|
||||||
turn_success, qr_result = arc_turn_around_hori_line(
|
# turn_success, qr_result = arc_turn_around_hori_line(
|
||||||
ctrl=ctrl,
|
# ctrl=ctrl,
|
||||||
msg=msg,
|
# msg=msg,
|
||||||
angle_deg=85,
|
# angle_deg=85,
|
||||||
left=False,
|
# left=False,
|
||||||
observe=observe,
|
# observe=observe,
|
||||||
scan_qrcode=True, # 启用 QR 码扫描
|
# scan_qrcode=True, # 启用 QR 码扫描
|
||||||
qr_check_interval=0.3 # 每 0.3 秒检查一次扫描结果
|
# qr_check_interval=0.3 # 每 0.3 秒检查一次扫描结果
|
||||||
)
|
# )
|
||||||
|
|
||||||
if qr_result:
|
# if qr_result:
|
||||||
print(f"🎯 在任务 1-1 中成功扫描到 QR 码: {qr_result}")
|
# print(f"🎯 在任务 1-1 中成功扫描到 QR 码: {qr_result}")
|
||||||
else:
|
# else:
|
||||||
print("⚠️ 任务 1-1 中未能扫描到任何 QR 码")
|
# print("⚠️ 任务 1-1 中未能扫描到任何 QR 码")
|
||||||
|
|
||||||
print('😺 task 1 - 2')
|
# print('😺 task 1 - 2')
|
||||||
# 执行常规的移动操作,不需要 QR 码扫描
|
# # 执行常规的移动操作,不需要 QR 码扫描
|
||||||
move_to_hori_line(ctrl, msg, target_distance=1, observe=observe)
|
# move_to_hori_line(ctrl, msg, target_distance=1, observe=observe)
|
||||||
|
|
||||||
print('😺 task 1 - 3')
|
print('😺 task 1 - 3')
|
||||||
direction = True if qr_result == 'A-2' else False
|
qr_result = "A-1"
|
||||||
|
direction = True if qr_result == 'A-1' else False
|
||||||
turn_success = arc_turn_around_hori_line(
|
turn_success = arc_turn_around_hori_line(
|
||||||
ctrl=ctrl,
|
ctrl=ctrl,
|
||||||
msg=msg,
|
msg=msg,
|
||||||
angle_deg=180,
|
angle_deg=180,
|
||||||
target_distance=0.5,
|
target_distance=0.5,
|
||||||
left=direction,
|
left=direction,
|
||||||
|
pass_align=True,
|
||||||
observe=observe,
|
observe=observe,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user