常见问题
Q: 如何判断导航是否成功?
A: 检查响应的 state.code:
response = navigation_to_location('point_A')
if response.state.code == StateCode.success:
print("成功")
else:
print(f"失败: {response.state.describe}")
Q: 阻塞和非阻塞模式的区别?
A: 阻塞模式 等待操作完成,非阻塞模式 立即返回:
# 阻塞 - 等待完成
response = navigation_to_location('A', block=True)
print("导航已完成")
# 非阻塞 - 立即返回
response = navigation_to_location('B', block=False)
print("导航已开始(后台运行)")
Q: 如何处理超时?
A: 增加超时时间或实现重试机制:
# 增加超时
response = navigation_to_location('far_point', timeout=300)
# 重试
for i in range(3):
response = navigation_to_location('point')
if response.state.code == StateCode.success:
break
Q: 虚拟打点和普通打点的区别?
A: - 普通打点: 需要机器人移动到目标位置,检查定位状态 - 虚拟打点: 直接设置坐标,无需机器人移动
# 普通打点 - 机器人当前位置
add_location('current_spot')
# 虚拟打点 - 任意坐标
pose = Pose()
pose.position.x = 1.0
pose.position.y = 2.0
add_location('virtual_spot', use_virtual_pose=True, virtual_pose=pose)