Keep local reroutes bound to original edges within simplified guidance
This commit is contained in:
@@ -137,3 +137,38 @@ class ObservedRouteBlockage:
|
||||
}
|
||||
self.pending = None
|
||||
return receipt
|
||||
|
||||
|
||||
def blocked_route_piece(routing, segment, hazards, pose):
|
||||
"""Resolve simplified guidance back to its original graph components.
|
||||
|
||||
RDP is presentation/direction compression. It must not turn a local
|
||||
exclusion into closure of every source edge or a long return to the
|
||||
beginning of the compressed chain. This returns intent metadata only.
|
||||
"""
|
||||
from k1link.simulation.ai_polygon.route_graph import projection
|
||||
|
||||
nodes = {n['id']: n['xy'] for n in routing['map']['nodes']}
|
||||
edges = {e['id']: e for e in routing['map']['edges']}
|
||||
cursor = segment['start_xy']
|
||||
chain = []
|
||||
for identity in segment.get('edge_ids', [segment['edge_id']]):
|
||||
edge = edges[identity]
|
||||
if nodes[edge['start']] == cursor:
|
||||
start, end = edge['start'], edge['end']
|
||||
elif edge['bidirectional'] and nodes[edge['end']] == cursor:
|
||||
start, end = edge['end'], edge['start']
|
||||
else:
|
||||
raise ValueError('Route components are not an oriented graph chain')
|
||||
chain.append((edge, start, end))
|
||||
cursor = nodes[end]
|
||||
def nearest(point):
|
||||
return min(range(len(chain)), key=lambda i: (projection(
|
||||
point, nodes[chain[i][1]], nodes[chain[i][2]])[1], -i))
|
||||
blocked = {nearest(point[:2]) for point in hazards}
|
||||
# Rejoin at an original node on our side of the first blocked component.
|
||||
# If the blockage is farther ahead, do not jump across unseen components
|
||||
# to reach that node. Every actual approach still needs native admission.
|
||||
index = min(nearest(pose[:2]), min(blocked))
|
||||
edge, anchor, _ = chain[index]
|
||||
return edge, anchor, sorted(chain[i][0]['id'] for i in blocked)
|
||||
|
||||
@@ -6,7 +6,7 @@ import math
|
||||
import numpy as np
|
||||
|
||||
from k1link.simulation.ai_polygon.mission_policy import WaypointMission, inclination
|
||||
from k1link.simulation.ai_polygon.route_feedback import ObservedRouteBlockage
|
||||
from k1link.simulation.ai_polygon.route_feedback import ObservedRouteBlockage, blocked_route_piece
|
||||
from k1link.simulation.ai_polygon.route_graph import (
|
||||
build_route,
|
||||
disc_permitted,
|
||||
@@ -75,20 +75,25 @@ class RoutedMission(WaypointMission):
|
||||
)
|
||||
if receipt is None:
|
||||
return None
|
||||
self.unavailable_edges.update(segment.get("edge_ids", [segment["edge_id"]]))
|
||||
nodes = {n["id"]: n["xy"] for n in self.inputs["routing"]["map"]["nodes"]}
|
||||
if segment.get("guidance_only") and not segment.get("return_to_anchor"):
|
||||
edge, anchor, blocked_edges = blocked_route_piece(
|
||||
self.inputs["routing"], segment, receipt["hazards_xyz"], pose)
|
||||
else:
|
||||
edge = next(e for e in self.inputs["routing"]["map"]["edges"]
|
||||
if e["id"] == segment["edge_id"])
|
||||
anchor = edge["start"] if nodes[edge["start"]] == segment["start_xy"] else edge["end"]
|
||||
blocked_edges = segment.get("edge_ids", [segment["edge_id"]])
|
||||
self.unavailable_edges.update(blocked_edges)
|
||||
event = {
|
||||
"schema_version": "missioncore.route-revision/v1",
|
||||
"revision": self.route_revision + 1,
|
||||
"previous_route_sha256": self.active_route["sha256"],
|
||||
"blockage": receipt,
|
||||
"unavailable_edges": sorted(self.unavailable_edges),
|
||||
"anchor_node": anchor,
|
||||
"authority": "route-intent-only",
|
||||
}
|
||||
edge = next(
|
||||
e for e in self.inputs["routing"]["map"]["edges"] if e["id"] == segment["edge_id"]
|
||||
)
|
||||
nodes = {n["id"]: n["xy"] for n in self.inputs["routing"]["map"]["nodes"]}
|
||||
anchor = edge["start"] if nodes[edge["start"]] == segment["start_xy"] else edge["end"]
|
||||
failure = (
|
||||
"route-reroute-budget"
|
||||
if self.route_revision >= 3
|
||||
@@ -112,19 +117,23 @@ class RoutedMission(WaypointMission):
|
||||
self.route_failure, self.fault, self.state = failure, "stuck", "stuck"
|
||||
event.update(status="unreachable", failure=failure)
|
||||
else:
|
||||
# Rejoin at the declared start of this edge; never teleport to a
|
||||
# nearby branch. Only this prefix can use the excluded edge, in the
|
||||
# opposite direction away from the measured obstacle. Its ground,
|
||||
# full-body sweep and anchor arrival still require sensor admission.
|
||||
# Rejoin a real graph node; never teleport to another branch.
|
||||
# Simplified advisory segments retain their source edge identities:
|
||||
# the nearby component owns this return, not the complete chord.
|
||||
# Hard corridors keep their original enclosing return capsule.
|
||||
prefix = {
|
||||
**segment,
|
||||
"start_xy": list(segment["end_xy"]),
|
||||
"end_xy": list(segment["start_xy"]),
|
||||
"start_xy": list(pose[:2]) if segment.get("guidance_only") else list(segment["end_xy"]),
|
||||
"end_xy": list(nodes[anchor]),
|
||||
"edge_id": edge["id"],
|
||||
"edge_ids": [edge["id"]],
|
||||
"return_to_anchor": True,
|
||||
}
|
||||
leg = candidate["legs"][0]
|
||||
leg["segments"].insert(0, prefix)
|
||||
leg["length_m"] += math.dist(prefix["start_xy"], prefix["end_xy"])
|
||||
return_length = math.dist(prefix["start_xy"], prefix["end_xy"])
|
||||
if return_length > 1e-8:
|
||||
leg["segments"].insert(0, prefix)
|
||||
leg["length_m"] += return_length
|
||||
leg["start_xy"] = list(pose[:2])
|
||||
candidate["legs"] = (
|
||||
copy.deepcopy(self.active_route["legs"][: self.index]) + candidate["legs"]
|
||||
|
||||
Reference in New Issue
Block a user