Add vector infrastructure maps and persistent location experience
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import type { UrbanMap, UrbanMapFeature } from "./urbanMap";
|
||||
export interface PlaceAttempt {
|
||||
id:string;xyz:number[];origin:number[];reason:string;status:"unresolved"|"revisited-successfully";
|
||||
first_seen:number;last_seen:number;count:number;run_id:string;observation_id:string;
|
||||
}
|
||||
export interface SpatialExperience {
|
||||
schema_version:"missioncore.spatial-experience/v1";
|
||||
source:{world_sha256:string;collider_sha256:string;robot_sha256:string};
|
||||
visits:{id:string;xyz:number[];count:number;last_seen:number}[];
|
||||
attempts:PlaceAttempt[];
|
||||
}
|
||||
const REASONS:Record<string,string>={"no-path":"Путь не найден","no-permitted-goal":"Не найдена разрешённая поверхность","footprint":"Недостаточно места для корпуса",
|
||||
"observed-unsafe-support":"Ненадёжная опора","forbidden-surface-sweep":"Запрещённая поверхность",
|
||||
"detected-object-sweep":"Препятствие на пути"};
|
||||
export function attemptLabel(a:PlaceAttempt) {
|
||||
return `${a.status==="revisited-successfully"?"Позже проехал":"Попытка проезда"} · ${REASONS[a.reason]??a.reason} · ${a.count} · ${new Date(a.last_seen*1000).toLocaleString("ru")}`;
|
||||
}
|
||||
/** Cell marks and attempted direction; no invented connections between visits. */
|
||||
export function experienceMap(memory:SpatialExperience):UrbanMap {
|
||||
const feature=(id:string,cls:string,points:number[][]):UrbanMapFeature=>({id,
|
||||
properties:{class:cls,authority:"observation-only",route_permission:"unassigned"},geometry:{type:"LineString",coordinates:points}});
|
||||
return {schema_version:"missioncore.urban-map/v2",source:memory.source,coverage:{cell_m:.5,accepted_cells:memory.visits.length},features:[
|
||||
...memory.visits.map(v=>feature(v.id,"visited",[[v.xyz[0]-.12,v.xyz[1],v.xyz[2]],[v.xyz[0]+.12,v.xyz[1],v.xyz[2]]])),
|
||||
...memory.attempts.map(a=>feature(a.id,a.status==="unresolved"?"attempt":"revisited",[a.origin,a.xyz])),
|
||||
]};
|
||||
}
|
||||
export async function loadExperience(worldId:string,worldSha:string,signal:AbortSignal):Promise<SpatialExperience|null> {
|
||||
const response=await fetch(`/api/v1/ai-polygon/worlds/${encodeURIComponent(worldId)}/spatial-experience`,{signal,cache:"no-store"});
|
||||
if(response.status===404)return null;
|
||||
if(!response.ok)throw new Error("Не удалось загрузить память локации.");
|
||||
const data=await response.json() as SpatialExperience;
|
||||
if(data.schema_version!=="missioncore.spatial-experience/v1"||data.source.world_sha256!==worldSha)throw new Error("Память относится к другой локации.");
|
||||
return data;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
export interface UrbanMapFeature {
|
||||
id: string;
|
||||
properties: { class: string; authority: "observation-only"; route_permission: "unassigned"; confidence?: number; review_status?: "unreviewed"|"accepted"|"rejected" };
|
||||
geometry: { type: "Polygon"; coordinates: number[][][] } | { type: "LineString"; coordinates: number[][] };
|
||||
}
|
||||
export interface UrbanMap {
|
||||
schema_version: "missioncore.urban-map/v1"|"missioncore.urban-map/v2";
|
||||
source: { world_sha256: string; collider_sha256: string };
|
||||
features: UrbanMapFeature[];
|
||||
coverage: { accepted_cells: number; cell_m: number; kind?: "objects-only" };
|
||||
}
|
||||
export const URBAN_COLORS: Record<string, [number, number, number]> = {
|
||||
visited: [60,220,200], attempt: [245,130,48], revisited: [245,245,245],
|
||||
curb: [245,130,48], curb_cut: [255,150,80], sidewalk: [60,220,200], pedestrian_area: [60,220,200],
|
||||
carriageway: [90,130,200], service_lane: [110,150,210], bike_lane: [150,110,220], parking: [140,140,150],
|
||||
crosswalk_area: [255,225,35], crosswalk_marking: [255,225,35], road_marking: [245,245,245],
|
||||
};
|
||||
export const URBAN_LABELS: Record<string, string> = {
|
||||
curb: "Бордюр", curb_cut: "Съезд", sidewalk: "Тротуар", pedestrian_area: "Пешеходная зона",
|
||||
carriageway: "Проезжая часть", service_lane: "Служебный проезд", bike_lane: "Велополоса", parking: "Парковка",
|
||||
crosswalk_area: "Переход", crosswalk_marking: "Зебра", road_marking: "Разметка",
|
||||
};
|
||||
export async function loadUrbanMap(worldId: string, worldSha: string, signal: AbortSignal): Promise<UrbanMap|null> {
|
||||
const response = await fetch(`/api/v1/ai-polygon/worlds/${encodeURIComponent(worldId)}/urban-map`, { signal, cache: "no-store" });
|
||||
if (response.status === 404) return null;
|
||||
if (!response.ok) throw new Error("Не удалось загрузить карту инфраструктуры.");
|
||||
const result = await response.json() as UrbanMap;
|
||||
if (!["missioncore.urban-map/v1","missioncore.urban-map/v2"].includes(result.schema_version) || result.source.world_sha256 !== worldSha) {
|
||||
throw new Error("Карта относится к другой версии сцены.");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function urbanPaths(feature: UrbanMapFeature): number[][][] {
|
||||
return feature.properties.review_status === "rejected" ? [] : feature.geometry.type === "Polygon" ? feature.geometry.coordinates : [feature.geometry.coordinates];
|
||||
}
|
||||
Reference in New Issue
Block a user