fixed 优化移动逻辑
This commit is contained in:
Binary file not shown.
@@ -304,7 +304,11 @@ class CoordinatePatrol:
|
||||
# 2. 距离判断
|
||||
dist = self.get_distance(current_pos, target_pos)
|
||||
if dist < threshold:
|
||||
self.stop_all()
|
||||
# 到点后保持平滑过渡:不松开 W,只松开左右修正键
|
||||
# 避免 patrol 连续多点时出现“刹一下再走”的抖动。
|
||||
pyautogui.keyUp("a")
|
||||
pyautogui.keyUp("d")
|
||||
self.reset_stuck()
|
||||
return True
|
||||
|
||||
# 3. 计算角度差
|
||||
@@ -325,26 +329,27 @@ class CoordinatePatrol:
|
||||
# 在死区内,确保转向键松开,直线前进
|
||||
pyautogui.keyUp("a")
|
||||
pyautogui.keyUp("d")
|
||||
else:
|
||||
# 在死区外,需要修正方向
|
||||
elif abs_diff > self.angle_threshold_deg:
|
||||
# 超出阈值:执行平滑脉冲转向
|
||||
turn_key = "d" if angle_diff > 0 else "a"
|
||||
other_key = "a" if angle_diff > 0 else "d"
|
||||
|
||||
# 松开反方向键
|
||||
pyautogui.keyUp(other_key)
|
||||
|
||||
# 计算本次修正的时长
|
||||
# 边走边转时,duration 应比原地转向更短,建议使用 0.05s - 0.1s 的短脉冲
|
||||
# 获取针对平滑移动优化的短脉冲时长
|
||||
duration = self._turn_duration_from_angle(abs_diff)
|
||||
|
||||
# 限制单次修正时间,防止转过头导致“画龙”
|
||||
safe_duration = min(duration, 0.15)
|
||||
|
||||
# 关键:执行短促转向脉冲
|
||||
pyautogui.keyDown(turn_key)
|
||||
time.sleep(safe_duration) # 短暂物理延迟确保按键生效
|
||||
# sleep 极短 (建议 < 0.1s),不会造成移动卡顿
|
||||
time.sleep(duration)
|
||||
pyautogui.keyUp(turn_key)
|
||||
|
||||
self.last_turn_end_time = time.time()
|
||||
else:
|
||||
# 在死区与阈值之间:为了平滑,不进行任何按键动作,仅靠 W 前进
|
||||
pyautogui.keyUp("a")
|
||||
pyautogui.keyUp("d")
|
||||
|
||||
return False
|
||||
|
||||
@@ -490,6 +495,10 @@ class CoordinatePatrol:
|
||||
if not path:
|
||||
self.stop_all()
|
||||
return True
|
||||
|
||||
# 阻塞模式下的状态轮询间隔:尽量贴近“每帧高频控制”,避免转向脉冲后等待过久导致抖动。
|
||||
poll_sleep_sec = 0.02
|
||||
|
||||
points = [(float(p[0]), float(p[1])) for p in path]
|
||||
if not forward:
|
||||
points = points[::-1]
|
||||
@@ -502,7 +511,7 @@ class CoordinatePatrol:
|
||||
return False
|
||||
if self._ensure_mounted(state):
|
||||
break
|
||||
time.sleep(0.05)
|
||||
time.sleep(poll_sleep_sec)
|
||||
|
||||
for i, target in enumerate(points):
|
||||
self.logger.info(f">>> 路径点 {i + 1}/{len(points)}: {target}")
|
||||
@@ -514,7 +523,7 @@ class CoordinatePatrol:
|
||||
arrived = self.navigate_to_point(state, target, arrival_threshold)
|
||||
if arrived:
|
||||
break
|
||||
time.sleep(0.05)
|
||||
time.sleep(poll_sleep_sec)
|
||||
self.stop_all()
|
||||
self.logger.info(">>> 路径走完")
|
||||
return True
|
||||
|
||||
@@ -50,3 +50,12 @@
|
||||
- **运行时透传**:`start_game_loop` → `GameLoopWorker` → `AutoBotMove` 全链路透传并生效。
|
||||
- **兼容性**:`AutoBotMove` 保留默认值,旧配置文件可直接运行。
|
||||
|
||||
### `navigate_to_point` 对齐 `navigate` 优化
|
||||
|
||||
- **到点处理**:`coordinate_patrol.py` 的 `navigate_to_point` 到达判定后不再调用 `stop_all()`,改为仅松开左右修正键并保持 `W` 前进,从而实现连续平滑过渡。
|
||||
- **转向触发逻辑**:`navigate_to_point` 转向决策按 `navigate` 的三档策略调整(死区直行、阈值外脉冲转向、死区与阈值之间不修正),降低航点附近左右抖动。
|
||||
|
||||
### `navigate_path` 对齐 `navigate` 优化
|
||||
|
||||
- **轮询间隔**:`coordinate_patrol.py` 的 `navigate_path` 阻塞等待轮询由固定 `time.sleep(0.05)` 调整为局部 `poll_sleep_sec = 0.02`,让阻塞模式控制频率更接近 `navigate`,减少航点/转向后的抖动。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user