Introduce a content-bound scene route provider, advisory runtime graph and plan-preview-launch workflow. Preserve live sensing authority and retire blocked intermediate goals without discarding final-arrival evidence. Bound native visual context losslessly and provide verified cache relocation. Full Maroseyka route qualification remains open.
67 lines
2.7 KiB
Python
67 lines
2.7 KiB
Python
"""Small synthetic geometry: no scene names, memorized turns or manual paths."""
|
|
import importlib.util
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
import numpy as np
|
|
import pytest
|
|
|
|
pytest.importorskip('scipy')
|
|
ADAPTER=Path(__file__).parents[1]/'simulation/ai-polygon'
|
|
sys.path.insert(0,str(ADAPTER))
|
|
from scene_route_field import ground_envelope, route_graph
|
|
from k1link.simulation.ai_polygon.route_graph import build_route
|
|
|
|
|
|
def street(*,car=False,gap=False):
|
|
x,y=np.meshgrid(np.arange(0,24.01,.25),np.arange(-4,4.01,.25),indexing='ij')
|
|
vertices=np.column_stack([x.ravel(),y.ravel(),np.zeros(x.size)])
|
|
n=y.shape[1]
|
|
faces=[]
|
|
for i in range(x.shape[0]-1):
|
|
for j in range(n-1):
|
|
a=i*n+j;b=a+n
|
|
if (car and 9<=x[i,j]<13 and -1<=y[i,j]<1) or (gap and 9<=x[i,j]<13):
|
|
continue
|
|
faces.extend([[a,b,a+1],[a+1,b,b+1]])
|
|
if car:
|
|
roof=vertices.copy();roof[:,2]=1.5
|
|
rows=np.argwhere((x>=9)&(x<13)&(y>=-1)&(y<1))
|
|
roof_faces=[]
|
|
for i,j in rows:
|
|
a=i*n+j;b=a+n
|
|
roof_faces.extend([[a,b,a+1],[a+1,b,b+1]])
|
|
faces+= (np.asarray(roof_faces)+len(vertices)).tolist()
|
|
vertices=np.concatenate([vertices,roof])
|
|
return vertices,np.array(faces)
|
|
|
|
|
|
def test_small_enclosed_occlusion_does_not_sculpt_global_directions():
|
|
base=ground_envelope(*street(),[1,0,0])
|
|
occupied=ground_envelope(*street(car=True),[1,0,0])
|
|
assert np.array_equal(base[2],occupied[2])
|
|
assert not base[3].any() and occupied[3].any()
|
|
source=dict(provider='synthetic',provider_sha256='a'*64,collider_sha256='b'*64)
|
|
positions=[[1.,0.,0.],[22.,0.,0.]]
|
|
def route(field):
|
|
graph=route_graph(*field,positions,source,'c'*64)
|
|
return build_route(dict(routing=graph,mission={'route_xy':[[22.,0.]]},robot={'geometry':{'length_m':1.,'width_m':1.}},sha256='d'*64))['legs']
|
|
assert route(base)==route(occupied)
|
|
|
|
|
|
def test_open_gap_is_not_filled_to_make_a_successful_route():
|
|
field=ground_envelope(*street(gap=True),[1,0,0])
|
|
origin,height,envelope,unknown=field
|
|
far=np.floor((np.array([20,0])-origin)/.5).astype(int)
|
|
assert not envelope[tuple(far)] and not unknown[tuple(far)]
|
|
with pytest.raises(ValueError,match='Endpoint'):
|
|
route_graph(*field,[[1.,0.,0.],[22.,0.,0.]],
|
|
dict(provider='synthetic',provider_sha256='a'*64,collider_sha256='b'*64),'c'*64)
|
|
|
|
|
|
def test_goal_on_another_height_layer_does_not_attach_to_street():
|
|
field=ground_envelope(*street(),[1,0,0])
|
|
with pytest.raises(ValueError,match='Endpoint'):
|
|
route_graph(*field,[[1.,0.,0.],[22.,0.,2.]],
|
|
dict(provider='synthetic',provider_sha256='a'*64,collider_sha256='b'*64),'c'*64)
|