From 8fd81b6f2aab29d7abaa2e8663d345c506e01f88 Mon Sep 17 00:00:00 2001 From: Tanner Date: Sat, 28 Nov 2026 20:25:50 +0000 Subject: [PATCH] Find return points at nearby terrain elevations --- mosfet/jobs/work_boundary.py | 38 +++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/mosfet/jobs/work_boundary.py b/mosfet/jobs/work_boundary.py index ae3c72d..0075fe2 100644 --- a/mosfet/jobs/work_boundary.py +++ b/mosfet/jobs/work_boundary.py @@ -30,6 +30,12 @@ class WorkBoundaryReturnMixin: if self.work_policies and self.work_boundary_start_position is not None else 0.0) self.work_boundary_return_retry_at = 0.0 + if (self.work_policies and + self.work_boundary_return_point is None and + self.work_boundary_start_position is not None): + print('[work boundary] start {} is outside the active policy; ' + 'will find an in-bound return point after this task'.format( + self.work_boundary_start_position)) def _inside_work_policies(self, position): return bool(self.work_policies) and all( @@ -90,10 +96,14 @@ class WorkBoundaryReturnMixin: base_x = anchor[0] + dx * scale base_z = anchor[2] + dz * scale base = (int(round(base_x)), anchor[1], int(round(base_z))) - for dy in (0, -1, 1): + # Signs are commonly placed several blocks above the floor. + # Search elevations around both the sign and the bot instead + # of assuming a standable return point is at sign_y +/- 1. + lower_y = min(int(from_position[1]), anchor[1]) - 8 + upper_y = max(int(from_position[1]), anchor[1]) + 8 + for y in range(lower_y, upper_y + 1): for ox, oz in offsets: - point = (base[0] + ox, base[1] + dy, - base[2] + oz) + point = (base[0] + ox, y, base[2] + oz) if (point not in candidates and self._inside_work_policies(point) and standable(point)): @@ -104,11 +114,29 @@ class WorkBoundaryReturnMixin: def _find_work_boundary_return_plan(self, world, from_position, preferred_points=()): - for point in self._work_boundary_return_candidates( - world, from_position, preferred_points): + candidates = self._work_boundary_return_candidates( + world, from_position, preferred_points) + verbose = getattr(self, 'work_boundary_return_retry_at', 0.0) == 0.0 + if verbose: + print('[work boundary] planning return from {} with {} ' + 'in-bound candidate(s)'.format(from_position, len(candidates))) + failed = [] + for point in candidates: navpath = world.path_to_place(from_position, point) if navpath is not None: + if verbose: + print('[work boundary] return route to {} has {} ' + 'waypoint(s)'.format(point, len(navpath))) return point, navpath + failed.append(point) + if verbose: + if failed: + print('[work boundary] no route to return candidates; tried {} ' + '(first failures: {})'.format( + len(failed), failed[:8])) + else: + print('[work boundary] no standable in-bound return candidates ' + 'near the active boundary') return None, None def _maybe_return_to_work_boundary(self, resume_state):