Bound retries for unreachable path recovery
This commit is contained in:
1 parent
d4eae5ee5f
commit
7ab354800b
4 files changed
+70
-5
No files matched your search
+26
-4
@@ -123,6 +123,7 @@ def missing_movement_chunks(g):
|
|||||||
|
|
||||||
PATH_VALIDATION_INTERVAL = 0.25
|
PATH_VALIDATION_INTERVAL = 0.25
|
||||||
PATH_RECOVERY_RETRY_INTERVAL = 1.0
|
PATH_RECOVERY_RETRY_INTERVAL = 1.0
|
||||||
|
PATH_RECOVERY_MAX_ATTEMPTS = 3
|
||||||
|
|
||||||
|
|
||||||
def _recover_invalid_path(g, now=None):
|
def _recover_invalid_path(g, now=None):
|
||||||
@@ -135,6 +136,8 @@ def _recover_invalid_path(g, now=None):
|
|||||||
if g.get('navigation_recovery_target') is not None:
|
if g.get('navigation_recovery_target') is not None:
|
||||||
g.navigation_recovery_target = None
|
g.navigation_recovery_target = None
|
||||||
g.navigation_retry_at = 0.0
|
g.navigation_retry_at = 0.0
|
||||||
|
g.navigation_recovery_attempts = 0
|
||||||
|
g.navigation_failed_target = None
|
||||||
if now >= g.get('path_validation_at', 0.0):
|
if now >= g.get('path_validation_at', 0.0):
|
||||||
g.path_validation_at = now + PATH_VALIDATION_INTERVAL
|
g.path_validation_at = now + PATH_VALIDATION_INTERVAL
|
||||||
try:
|
try:
|
||||||
@@ -149,6 +152,8 @@ def _recover_invalid_path(g, now=None):
|
|||||||
g.path = []
|
g.path = []
|
||||||
g.navigation_recovery_target = target
|
g.navigation_recovery_target = target
|
||||||
g.navigation_retry_at = 0.0
|
g.navigation_retry_at = 0.0
|
||||||
|
g.navigation_recovery_attempts = 0
|
||||||
|
g.navigation_failed_target = None
|
||||||
|
|
||||||
target = g.get('navigation_recovery_target')
|
target = g.get('navigation_recovery_target')
|
||||||
if target is None or now < g.get('navigation_retry_at', 0.0):
|
if target is None or now < g.get('navigation_retry_at', 0.0):
|
||||||
@@ -158,6 +163,7 @@ def _recover_invalid_path(g, now=None):
|
|||||||
if position == tuple(target):
|
if position == tuple(target):
|
||||||
g.navigation_recovery_target = None
|
g.navigation_recovery_target = None
|
||||||
g.navigation_retry_at = 0.0
|
g.navigation_retry_at = 0.0
|
||||||
|
g.navigation_recovery_attempts = 0
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -168,14 +174,24 @@ def _recover_invalid_path(g, now=None):
|
|||||||
g.path = navpath
|
g.path = navpath
|
||||||
g.navigation_recovery_target = None
|
g.navigation_recovery_target = None
|
||||||
g.navigation_retry_at = 0.0
|
g.navigation_retry_at = 0.0
|
||||||
|
g.navigation_recovery_attempts = 0
|
||||||
|
g.navigation_failed_target = None
|
||||||
print('[movement] rerouted to {}'.format(target), flush=True)
|
print('[movement] rerouted to {}'.format(target), flush=True)
|
||||||
else:
|
else:
|
||||||
g.path = []
|
g.path = []
|
||||||
|
attempts = g.get('navigation_recovery_attempts', 0) + 1
|
||||||
|
g.navigation_recovery_attempts = attempts
|
||||||
|
if attempts >= PATH_RECOVERY_MAX_ATTEMPTS:
|
||||||
|
print('[movement] giving up on unreachable path target {} '
|
||||||
|
'after {} attempts'.format(target, attempts), flush=True)
|
||||||
|
g.navigation_recovery_target = None
|
||||||
|
g.navigation_retry_at = 0.0
|
||||||
|
g.navigation_recovery_attempts = 0
|
||||||
|
g.navigation_failed_target = tuple(target)
|
||||||
|
else:
|
||||||
g.navigation_retry_at = now + PATH_RECOVERY_RETRY_INTERVAL
|
g.navigation_retry_at = now + PATH_RECOVERY_RETRY_INTERVAL
|
||||||
if now >= g.get('navigation_retry_log_at', 0.0):
|
print('[movement] no route to {}; retry {}/{}'.format(
|
||||||
print('[movement] no route to {}; will retry'.format(target),
|
target, attempts, PATH_RECOVERY_MAX_ATTEMPTS), flush=True)
|
||||||
flush=True)
|
|
||||||
g.navigation_retry_log_at = now + 5.0
|
|
||||||
|
|
||||||
|
|
||||||
def tick(global_state):
|
def tick(global_state):
|
||||||
@@ -505,6 +521,8 @@ def start_automation(global_state, initialize=True):
|
|||||||
g.path = []
|
g.path = []
|
||||||
g.navigation_recovery_target = None
|
g.navigation_recovery_target = None
|
||||||
g.navigation_retry_at = 0.0
|
g.navigation_retry_at = 0.0
|
||||||
|
g.navigation_recovery_attempts = 0
|
||||||
|
g.navigation_failed_target = None
|
||||||
g.path_validation_at = 0.0
|
g.path_validation_at = 0.0
|
||||||
g.look_at = None
|
g.look_at = None
|
||||||
g.y_v = 0.0
|
g.y_v = 0.0
|
||||||
@@ -571,6 +589,10 @@ def start_automation(global_state, initialize=True):
|
|||||||
g.setdefault('holding_slot', 0)
|
g.setdefault('holding_slot', 0)
|
||||||
g.setdefault('holding_hand', 0)
|
g.setdefault('holding_hand', 0)
|
||||||
g.setdefault('time', 0.0)
|
g.setdefault('time', 0.0)
|
||||||
|
g.setdefault('navigation_recovery_target', None)
|
||||||
|
g.setdefault('navigation_retry_at', 0.0)
|
||||||
|
g.setdefault('navigation_recovery_attempts', 0)
|
||||||
|
g.setdefault('navigation_failed_target', None)
|
||||||
|
|
||||||
old_stop = g.get('movement_stop_event')
|
old_stop = g.get('movement_stop_event')
|
||||||
old_worker = g.get('movement_thread')
|
old_worker = g.get('movement_thread')
|
||||||
|
|||||||
@@ -369,6 +369,8 @@ class JobStates(LegacyJobStates):
|
|||||||
self.g.path = []
|
self.g.path = []
|
||||||
self.g.navigation_recovery_target = None
|
self.g.navigation_recovery_target = None
|
||||||
self.g.navigation_retry_at = 0.0
|
self.g.navigation_retry_at = 0.0
|
||||||
|
self.g.navigation_recovery_attempts = 0
|
||||||
|
self.g.navigation_failed_target = None
|
||||||
self.g.look_at = None
|
self.g.look_at = None
|
||||||
self.g.yaw_target_override = None
|
self.g.yaw_target_override = None
|
||||||
if self.sleep_with_bed_states.state == self.sleep_with_bed_states.sleep_bed:
|
if self.sleep_with_bed_states.state == self.sleep_with_bed_states.sleep_bed:
|
||||||
|
|||||||
@@ -352,6 +352,23 @@ class GrabSuppliesStates(WorkBoundaryReturnMixin):
|
|||||||
self.state = self.check_supplies
|
self.state = self.check_supplies
|
||||||
|
|
||||||
def going_to_ground_item(self):
|
def going_to_ground_item(self):
|
||||||
|
failed_target = self.g.get('navigation_failed_target')
|
||||||
|
if (failed_target is not None and self.ground_position is not None and
|
||||||
|
tuple(failed_target) == tuple(self.ground_position)):
|
||||||
|
obj = self.g.objects.get(self.ground_entity_id)
|
||||||
|
label = (self._item_label(obj.item_id) if obj is not None
|
||||||
|
else 'item')
|
||||||
|
print('No reachable path to ground {} at {}; skipping'.format(
|
||||||
|
label, self.ground_position), flush=True)
|
||||||
|
if self.ground_entity_id is not None:
|
||||||
|
self.checked_ground_items.add(self.ground_entity_id)
|
||||||
|
self.g.navigation_failed_target = None
|
||||||
|
self.g.path = []
|
||||||
|
self.ground_entity_id = None
|
||||||
|
self.ground_position = None
|
||||||
|
self.state = self.find_ground_items
|
||||||
|
return
|
||||||
|
|
||||||
obj = self.g.objects.get(self.ground_entity_id)
|
obj = self.g.objects.get(self.ground_entity_id)
|
||||||
have_enough = (self.g.game.count_items(self.target_items) >=
|
have_enough = (self.g.game.count_items(self.target_items) >=
|
||||||
self.ground_required_count)
|
self.ground_required_count)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import unittest
|
|||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
from munch import Munch
|
from munch import Munch
|
||||||
|
|
||||||
from mosfet.bot import _recover_invalid_path
|
from mosfet.bot import PATH_RECOVERY_MAX_ATTEMPTS, _recover_invalid_path
|
||||||
from mosfet.game import Game
|
from mosfet.game import Game
|
||||||
from mosfet.info import blocks
|
from mosfet.info import blocks
|
||||||
from mosfet.path import AStarTimeout, Pathfinder
|
from mosfet.path import AStarTimeout, Pathfinder
|
||||||
@@ -214,6 +214,30 @@ class DoorNavigationTests(unittest.TestCase):
|
|||||||
self.assertEqual(g.path, [start, (0, 64, -1), (1, 64, 0), route[-1]])
|
self.assertEqual(g.path, [start, (0, 64, -1), (1, 64, 0), route[-1]])
|
||||||
self.assertIsNone(g.navigation_recovery_target)
|
self.assertIsNone(g.navigation_recovery_target)
|
||||||
|
|
||||||
|
def test_unreachable_recovery_target_is_abandoned_after_bounded_retries(self):
|
||||||
|
class NoRouteWorld:
|
||||||
|
def __init__(self):
|
||||||
|
self.calls = []
|
||||||
|
|
||||||
|
def path_to_place(self, start, target):
|
||||||
|
self.calls.append((start, target))
|
||||||
|
return None
|
||||||
|
|
||||||
|
goal = (5, 64, 0)
|
||||||
|
world = NoRouteWorld()
|
||||||
|
g = Munch(
|
||||||
|
path=[], pos=(0.5, 64, 0.5), world=world,
|
||||||
|
navigation_recovery_target=goal, navigation_retry_at=0.0,
|
||||||
|
navigation_recovery_attempts=0, navigation_failed_target=None)
|
||||||
|
|
||||||
|
for now in range(1, PATH_RECOVERY_MAX_ATTEMPTS + 1):
|
||||||
|
_recover_invalid_path(g, now=float(now))
|
||||||
|
|
||||||
|
self.assertEqual(len(world.calls), PATH_RECOVERY_MAX_ATTEMPTS)
|
||||||
|
self.assertIsNone(g.navigation_recovery_target)
|
||||||
|
self.assertEqual(g.navigation_failed_target, goal)
|
||||||
|
self.assertEqual(g.navigation_recovery_attempts, 0)
|
||||||
|
|
||||||
def test_invalid_path_is_replanned_to_its_original_destination(self):
|
def test_invalid_path_is_replanned_to_its_original_destination(self):
|
||||||
class FakePathfinder:
|
class FakePathfinder:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
Reference in new issue
Block a user