Add prepared urban route guidance to Gaussian simulation planning
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.
This commit is contained in:
@@ -28,10 +28,12 @@ export class AiEditorRuntime {
|
||||
private dirty = true;
|
||||
private previous = "";
|
||||
private points: AiWaypoint[] = [];
|
||||
private route: number[][] = [];
|
||||
clip = Infinity;
|
||||
height: [number, number] = [0, 1];
|
||||
constructor(private canvas: HTMLCanvasElement, private cache: EditorCache,
|
||||
private onProject: (markers: EditorMarker[]) => void) {
|
||||
private onProject: (markers: EditorMarker[]) => void,
|
||||
private onRouteProject: (points: ScreenPoint[]) => void = () => undefined) {
|
||||
canvas.tabIndex = 0;
|
||||
this.app = new Application(canvas, { graphicsDeviceOptions: { antialias: false, alpha: false,
|
||||
preserveDrawingBuffer: false, powerPreference: "default" } });
|
||||
@@ -65,6 +67,7 @@ export class AiEditorRuntime {
|
||||
const matrix = this.camera.getWorldTransform().data.join(",");
|
||||
if (matrix !== this.previous || this.dirty) {
|
||||
this.previous = matrix; this.dirty = false; app.renderNextFrame = true;
|
||||
this.onRouteProject(this.route.map(p=>this.project(...toEditor(p) as [number,number,number])));
|
||||
this.onProject(this.points.map((p) => {
|
||||
const [x,y,z] = toEditor(p.position);
|
||||
return { id:p.id, base:this.project(x,y,z), top:this.project(x,y+this.preferences.waypoint.height,z),
|
||||
@@ -100,6 +103,8 @@ export class AiEditorRuntime {
|
||||
this.controls.sceneCenter = this.terrain.bounds.getCenter(this.controls.sceneCenter);
|
||||
this.setClip(Infinity); this.dirty = true;
|
||||
}
|
||||
setRoute(points:number[][]) {this.route=points;this.dirty=true;}
|
||||
top() {this.controls.top((this.route.length?this.route:this.points.map(p=>p.position)).map(toEditor));this.syncCamera();this.dirty=true;}
|
||||
setPoints(points: AiWaypoint[]) { this.points = points; this.annotations.set(points,this.selected,this.preferences);this.dirty = true; }
|
||||
setSelected(id: string|null) {this.selected=id;this.annotations.set(this.points,id,this.preferences);this.dirty=true;}
|
||||
setPreferences(preferences: PlannerPreferences) {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { PreparedRoute } from "../../core/simulation/routePreparation";
|
||||
import type { ScreenPoint } from "../../core/simulation/aiPolygon";
|
||||
import { editWaypoints, waypointEditing, waypointShortcut } from "../../core/simulation/waypointEditing";
|
||||
import { SimulationViewTools } from "./SimulationViewTools";
|
||||
import { usePlannerPreferences } from "./usePlannerPreferences";
|
||||
@@ -12,9 +14,9 @@ import { useLocalScene } from "./useLocalScene";
|
||||
import { useSimulationFullscreen } from "./useSimulationFullscreen";
|
||||
|
||||
export interface LocalDraft { cache: EditorCache; points: AiWaypoint[]; id: string; sequence: number }
|
||||
export function AiLocalPlanner({ world, initialPoints, onDraft, actionsHost, headerActions, busy=false }: {
|
||||
export function AiLocalPlanner({ world, initialPoints, onDraft, actionsHost, headerActions, busy=false, preparedRoute=null }: {
|
||||
world: AiWorld; initialPoints: AiWaypoint[]; onDraft: (draft: LocalDraft | null) => void;
|
||||
actionsHost: HTMLElement | null; headerActions: React.ReactNode; busy?: boolean;
|
||||
actionsHost: HTMLElement | null; headerActions: React.ReactNode; busy?: boolean; preparedRoute?:PreparedRoute|null;
|
||||
}) {
|
||||
const markerSvg=useRef<SVGSVGElement>(null);
|
||||
const host = useRef<HTMLDivElement>(null), canvas = useRef<HTMLCanvasElement>(null);
|
||||
@@ -27,6 +29,8 @@ export function AiLocalPlanner({ world, initialPoints, onDraft, actionsHost, hea
|
||||
const [editing,edit] = useReducer(editWaypoints,initialPoints,waypointEditing);
|
||||
const {points,selected,sequence} = editing;
|
||||
const press=useRef<{id:number;x:number;y:number}|null>(null);
|
||||
const [routeProjection,setRouteProjection]=useState<ScreenPoint[]>([]);
|
||||
const [viewMode,setViewMode]=useState<"3d"|"top">("3d");
|
||||
const [markers, setMarkers] = useState<EditorMarker[]>([]);
|
||||
const [mode,setMode] = useState<"view" | "add">("view");
|
||||
const [clip,setClip] = useState(Infinity);
|
||||
@@ -38,7 +42,7 @@ export function AiLocalPlanner({ world, initialPoints, onDraft, actionsHost, hea
|
||||
let active = true;
|
||||
setReady(false); setError(null); setClip(Infinity);
|
||||
let view: AiEditorRuntime;
|
||||
try { view = new AiEditorRuntime(canvas.current,cache,setMarkers); }
|
||||
try { view = new AiEditorRuntime(canvas.current,cache,setMarkers,setRouteProjection); }
|
||||
catch (e) { setError((e as Error).message); return; }
|
||||
runtime.current = view;
|
||||
view.setPreferences(preferences);view.setPoints(initialPoints); view.home();
|
||||
@@ -49,6 +53,10 @@ export function AiLocalPlanner({ world, initialPoints, onDraft, actionsHost, hea
|
||||
runtime.current?.setPoints(points);
|
||||
if (cache?.status === "ready" && ready) callback.current({ cache,points,id:draftId.current,sequence });
|
||||
}, [points,cache,ready,sequence]);
|
||||
useEffect(()=>{
|
||||
runtime.current?.setRoute(preparedRoute?.preview_xyz??[]);
|
||||
if(preparedRoute && ready){runtime.current?.top();setViewMode("top");}
|
||||
},[preparedRoute?.sha256,ready]);
|
||||
useEffect(()=>{runtime.current?.setPreferences(preferences);},[preferences,ready]);
|
||||
useEffect(()=>{runtime.current?.setSelected(selected);},[selected,ready]);
|
||||
useEffect(()=>{runtime.current?.setNavigation(!busy);},[busy,ready]);
|
||||
@@ -76,7 +84,7 @@ export function AiLocalPlanner({ world, initialPoints, onDraft, actionsHost, hea
|
||||
{expanded ? <div className="ai-polygon__actions">{headerActions}</div> : actionsHost ? createPortal(headerActions,actionsHost) : null}
|
||||
<div className="ai-polygon__telemetry-row ai-polygon__telemetry-row--local">
|
||||
<StatusBadge tone={ready ? "success" : "neutral"}>{ready ? "Планирование на этом компьютере" : message}</StatusBadge>
|
||||
<p>{points.length} точек · первая — старт, последняя — финиш</p></div>
|
||||
<p>{preparedRoute?`${preparedRoute.length_m.toFixed(1)} м · маршрут — ориентир, препятствия оцениваются при движении`:`${points.length} точек · первая — старт, последняя — финиш`}</p></div>
|
||||
<div className="ai-polygon__viewer">
|
||||
<div ref={viewport} className="ai-polygon__viewport ai-local-editor" onContextMenu={(e)=>e.preventDefault()}
|
||||
onKeyDown={(e)=>{
|
||||
@@ -89,6 +97,9 @@ export function AiLocalPlanner({ world, initialPoints, onDraft, actionsHost, hea
|
||||
{points.some(p=>p.id===selected)?<IconButton label="Удалить точку" onClick={()=>{
|
||||
edit({type:"delete"});canvas.current?.focus({preventScroll:true});
|
||||
}}><Icon name="trash"/></IconButton>:null}
|
||||
{preparedRoute?<SegmentedControl label="Ракурс маршрута" value={viewMode}
|
||||
items={[{value:"3d",label:"3D"},{value:"top",label:"Вид сверху"}]}
|
||||
onChange={v=>{setViewMode(v);if(v==="top")runtime.current?.top();else runtime.current?.home();}}/>:null}
|
||||
<SegmentedControl label="Инструмент маршрута" value={mode} onChange={(v)=>{setMode(v);runtime.current?.setAddMode(v==="add");}}
|
||||
items={[{value:"view",label:"Обзор"},{value:"add",label:"Waypoint по клику"}]}/>
|
||||
</div>:null}
|
||||
@@ -124,7 +135,8 @@ export function AiLocalPlanner({ world, initialPoints, onDraft, actionsHost, hea
|
||||
drag.current=null;edit({type:"commit"});
|
||||
runtime.current?.setNavigation(!busy);if(e.currentTarget.hasPointerCapture(e.pointerId))e.currentTarget.releasePointerCapture(e.pointerId); }}
|
||||
onPointerCancel={()=>{edit({type:"cancel"});drag.current=null;runtime.current?.setNavigation(!busy);}}>
|
||||
<path className="ai-route__line" d={markers.map((m,i)=>m.base?`${i&&markers[i-1].base?"L":"M"}${m.base[0]*1280},${m.base[1]*720}`:"").join(" ")} />
|
||||
{preparedRoute?<path className="ai-route__line" d={routeProjection.map((p,i)=>p?`${i&&routeProjection[i-1]?"L":"M"}${p[0]*1280},${p[1]*720}`:"").join(" ")} />:null}
|
||||
{!preparedRoute?<path className="ai-route__line" d={markers.map((m,i)=>m.base?`${i&&markers[i-1].base?"L":"M"}${m.base[0]*1280},${m.base[1]*720}`:"").join(" ")} />:null}
|
||||
{markers.map((m,i)=>m.base&&m.top ? <g key={m.id} data-waypoint="true" className={`ai-route__marker ${selected===m.id?"is-selected":""}`}
|
||||
onPointerDown={(e)=>{
|
||||
if (busy || e.button !== 0) return;
|
||||
@@ -134,7 +146,7 @@ export function AiLocalPlanner({ world, initialPoints, onDraft, actionsHost, hea
|
||||
}}>
|
||||
|
||||
|
||||
<text x={m.top[0]*1280+10} y={m.top[1]*720}>{i===0?"Старт":i===markers.length-1?`Финиш · ${i}`:i}</text>
|
||||
<text textAnchor={m.top[0]>.85?"end":"start"} x={m.top[0]*1280+(m.top[0]>.85?-10:10)} y={m.top[1]*720}>{i===0?"Старт":i===markers.length-1?`Финиш · ${i}`:i}</text>
|
||||
{selected===m.id ? (["x","y","z"] as const).map((axis)=>m[axis] ? <g key={axis} className="ai-local-editor__axis-hit" onPointerDown={(e)=>{
|
||||
if (busy || e.button !== 0) return;
|
||||
e.preventDefault();e.stopPropagation();edit({type:"begin"});drag.current={point:points.find((p)=>p.id===m.id)!,axis,offset:m.base!.map((v,i)=>v-position(e)[i])};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Button, TextField, Window, WindowFooterActions } from "@nodedc/ui-react";
|
||||
|
||||
export function AiPlanSaveWindow({name,onName,busy,launch,onClose,onSave}: {
|
||||
name:string;onName:(name:string)=>void;busy:boolean;launch:boolean;
|
||||
export function AiPlanSaveWindow({name,onName,busy,launch,onClose,onSave,error}: {
|
||||
error:string|null;name:string;onName:(name:string)=>void;busy:boolean;launch:boolean;
|
||||
onClose:()=>void;onSave:()=>void;
|
||||
}) {
|
||||
return <Window open title={launch?"Сохранить задание и запустить":"Сохранить задание"}
|
||||
@@ -9,6 +9,7 @@ export function AiPlanSaveWindow({name,onName,busy,launch,onClose,onSave}: {
|
||||
footer={<WindowFooterActions><Button variant="primary" loading={busy} disabled={!name.trim()}
|
||||
onClick={onSave}>{launch?"Сохранить и запустить":"Сохранить"}</Button></WindowFooterActions>}>
|
||||
<div className="ai-polygon__form">
|
||||
{error?<p role="alert">{error}</p>:null}
|
||||
<TextField label="Название задания" value={name} maxLength={120} disabled={busy} onChange={(e)=>onName(e.target.value)}/>
|
||||
<p>Сохраняются текущие точки маршрута и выбранный ровер. Задание появится в списке над сценой.</p>
|
||||
</div>
|
||||
|
||||
@@ -11,6 +11,7 @@ export class EditorCamera {
|
||||
get rotationCenter(){return this.gesture&&!this.gesture.pan?this.gesture.anchor:null;}
|
||||
private keys = new Set<string>();
|
||||
private enabled=true;
|
||||
private topPoints:number[][]|null=null;
|
||||
private addMode=false;
|
||||
private gesture: {id:number;x:number;y:number;anchor:Vector3;depth:number;distance:number;pan:boolean}|null=null;
|
||||
private forward = new Vector3();
|
||||
@@ -48,6 +49,7 @@ export class EditorCamera {
|
||||
};
|
||||
private pointerMove=(e:PointerEvent)=>{
|
||||
const g=this.gesture;if(!g||g.id!==e.pointerId||!this.enabled)return;
|
||||
this.topPoints=null;
|
||||
const dx=e.clientX-g.x,dy=e.clientY-g.y;g.x=e.clientX;g.y=e.clientY;
|
||||
if(g.pan)panCamera(this.camera,g.depth,dx*panSensitivity(g.distance,this.navigation),dy*panSensitivity(g.distance,this.navigation),this.canvas.clientHeight);
|
||||
else orbitCamera(this.camera,g.anchor,dx,dy,this.canvas.clientHeight);
|
||||
@@ -59,6 +61,7 @@ export class EditorCamera {
|
||||
};
|
||||
private zoom=(e:WheelEvent)=>{
|
||||
if(!this.enabled)return;
|
||||
this.topPoints=null;
|
||||
e.preventDefault();this.canvas.focus({preventScroll:true});
|
||||
const rect=this.canvas.getBoundingClientRect(),x=(e.clientX-rect.left)/rect.width,y=(e.clientY-rect.top)/rect.height;
|
||||
const ray=new Vector3(x*2-1,1-y*2,.5).unproject(this.camera).sub(this.camera.position).normalize();
|
||||
@@ -72,15 +75,28 @@ export class EditorCamera {
|
||||
};
|
||||
private keyUp=(e:KeyboardEvent)=>{this.keys.delete(e.code);};
|
||||
private clear=()=>{this.keys.clear();this.gesture=null;};
|
||||
resize(width:number,height:number){this.camera.aspect=width/height;this.camera.updateProjectionMatrix();}
|
||||
resize(width:number,height:number){this.camera.aspect=width/height;this.camera.updateProjectionMatrix();if(this.topPoints)this.top(this.topPoints);}
|
||||
home(point:number[]){
|
||||
this.topPoints=null;
|
||||
const target=new Vector3(...point);
|
||||
this.camera.position.copy(target).add(new Vector3(5,6,8));this.camera.lookAt(target);this.camera.updateMatrixWorld();
|
||||
}
|
||||
top(points:number[][]){
|
||||
if(!points.length)return;
|
||||
this.topPoints=points;
|
||||
const low=[0,1,2].map(i=>Math.min(...points.map(p=>p[i])));
|
||||
const high=[0,1,2].map(i=>Math.max(...points.map(p=>p[i])));
|
||||
const target=new Vector3(...low.map((v,i)=>(v+high[i])/2));
|
||||
const span=Math.max((high[0]-low[0])/this.camera.aspect,high[2]-low[2],10);
|
||||
const distance=span/(2*Math.tan(Math.PI/6))*1.15+high[1]-low[1];
|
||||
this.camera.position.copy(target).add(new Vector3(0,distance,0));
|
||||
this.camera.up.set(0,0,-1);this.camera.lookAt(target);this.camera.up.set(0,1,0);this.camera.updateMatrixWorld();
|
||||
}
|
||||
setAddMode(add:boolean){this.addMode=add;}
|
||||
setNavigation(enabled:boolean){this.enabled=enabled;if(!enabled)this.clear();}
|
||||
update(dt:number){
|
||||
if(!this.enabled||!this.keys.size)return;
|
||||
this.topPoints=null;
|
||||
const pressed=(...keys:string[])=>Number(keys.some(k=>this.keys.has(k)));
|
||||
this.camera.getWorldDirection(this.forward);this.right.crossVectors(this.forward,this.camera.up).normalize();
|
||||
this.delta.copy(this.forward).multiplyScalar(pressed("KeyW","ArrowUp")-pressed("KeyS","ArrowDown"))
|
||||
|
||||
@@ -10,8 +10,8 @@ export const prepareEditor = (world: AiWorld, signal?: AbortSignal) => polygonRe
|
||||
export const fetchEditor = (key: string, signal?: AbortSignal) => polygonRequest<EditorCache>(`/editor-cache/${key}`, { signal });
|
||||
export const editorAssetUrl = (key: string, name: string) => `/api/v1/ai-polygon/editor-cache/${key}/${name}`;
|
||||
export const saveLocalPlan = (cache: EditorCache, robot: AiRobot, points: AiWaypoint[], name: string,
|
||||
draftId: string, sequence: number) => polygonRequest<AiPlan>("/plans", { method: "POST", body: JSON.stringify({
|
||||
draftId: string, sequence: number, routePreparationKey?:string|null) => polygonRequest<AiPlan>("/plans", { method: "POST", body: JSON.stringify({
|
||||
cache_key: cache.key, robot_id: robot.robot_id, robot_sha256: robot.sha256,
|
||||
draft_id: draftId, sequence, points, name,
|
||||
draft_id: draftId, sequence, points, name, route_preparation_key:routePreparationKey??null,
|
||||
}) });
|
||||
export { toEditor, toMission } from "./aiEditorCoordinates";
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { PreparedRoute } from "./routePreparation";
|
||||
import { decodeAIModuleCatalog, type AIModuleCatalog, type AIGroupId } from "../observatory/aiComposition";
|
||||
import type { RoverMotion } from "./roverMotion";
|
||||
import type { RoverSettings } from "./roverSettings";
|
||||
@@ -112,7 +113,7 @@ export interface AiRouteOverlay {
|
||||
export interface AiPlanningState { sequence: number; view_revision: number; points: AiWaypoint[];
|
||||
error: string | null; can_undo: boolean; clip_height: number | null;
|
||||
height_min?: number | null; height_max?: number | null; camera_moving?: boolean }
|
||||
export interface AiPlan { plan_id: string; name: string; sha256: string; world_id: string;
|
||||
export interface AiPlan { prepared_route?:PreparedRoute; route_preparation_key?:string; plan_id: string; name: string; sha256: string; world_id: string;
|
||||
settings?: Pick<AiWorldSettings, "max_speed_mps">;
|
||||
display_name?: string; removed?: boolean;
|
||||
editor_cache_key?: string;
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { polygonRequest, type AiPlan, type AiRobot, type AiWaypoint } from "./aiPolygon";
|
||||
import type { EditorCache } from "./aiEditor";
|
||||
|
||||
export interface PreparedRoute {
|
||||
sha256:string; preview_xyz:number[][]; length_m:number;
|
||||
identity:{world_sha256:string;robot_sha256:string;points:AiWaypoint[]};
|
||||
}
|
||||
export interface RoutePreparation {
|
||||
key:string;status:"queued"|"preparing"|"ready"|"failed";error:string|null;result:PreparedRoute|null;
|
||||
}
|
||||
export function routeMatches(route:PreparedRoute|null|undefined, cache:EditorCache|null,
|
||||
robot:AiRobot|undefined, points:AiWaypoint[]) {
|
||||
return !!route && !!cache && !!robot && route.identity.world_sha256===cache.world.sha256
|
||||
&& route.identity.robot_sha256===robot.sha256 && JSON.stringify(route.identity.points)===JSON.stringify(points);
|
||||
}
|
||||
export function useRoutePreparation(cache:EditorCache|null, robot:AiRobot|undefined,
|
||||
points:AiWaypoint[], plan:AiPlan|undefined, onError:(message:string)=>void) {
|
||||
const [job,setJob]=useState<RoutePreparation|null>(null);
|
||||
const [submitting,setSubmitting]=useState(false);
|
||||
const generation=useRef(0);
|
||||
const signature=JSON.stringify([cache?.key,robot?.sha256,points]);
|
||||
const current=useRef(signature);current.current=signature;
|
||||
const error=useRef(onError);error.current=onError;
|
||||
useEffect(()=>{generation.current++;setJob(null);setSubmitting(false);},[signature]);
|
||||
useEffect(()=>{
|
||||
if(!job || !["queued","preparing"].includes(job.status))return;
|
||||
const key=job.key,stamp=generation.current;
|
||||
let active=true,timer:ReturnType<typeof setTimeout>;
|
||||
const controller=new AbortController();
|
||||
const poll=async()=>{
|
||||
try {
|
||||
const next=await polygonRequest<RoutePreparation>(`/route-preparations/${key}`,{signal:controller.signal});
|
||||
if(active && generation.current===stamp){
|
||||
setJob(next);
|
||||
if(next.status==="failed")error.current(next.error??"Маршрут не построен.");
|
||||
else if(next.status!=="ready")timer=setTimeout(()=>void poll(),1000);
|
||||
}
|
||||
} catch(caught) {
|
||||
if(active){error.current((caught as Error).message);setJob(null);}
|
||||
}
|
||||
};
|
||||
timer=setTimeout(()=>void poll(),500);
|
||||
return()=>{active=false;clearTimeout(timer);controller.abort();};
|
||||
},[job?.key,job?.status]);
|
||||
const generated=routeMatches(job?.result,cache,robot,points)?job?.result:null;
|
||||
const saved=routeMatches(plan?.prepared_route,cache,robot,points)?plan?.prepared_route:null;
|
||||
const route=generated??saved??null;
|
||||
const key=generated?job!.key:saved?plan?.route_preparation_key:null;
|
||||
const prepare=async()=>{
|
||||
if(!cache||!robot||points.length<2)return;
|
||||
const stamp=generation.current,snapshot=signature;
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const next=await polygonRequest<RoutePreparation>("/route-preparations",{method:"POST",body:JSON.stringify({
|
||||
cache_key:cache.key,robot_id:robot.robot_id,robot_sha256:robot.sha256,points,
|
||||
})});
|
||||
if(stamp===generation.current && current.current===snapshot)setJob(next);
|
||||
} catch(caught) {if(stamp===generation.current)error.current((caught as Error).message);}
|
||||
finally {if(stamp===generation.current)setSubmitting(false);}
|
||||
};
|
||||
return {route,key:key??null,prepare,busy:submitting||!!job&&["queued","preparing"].includes(job.status)};
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useRoutePreparation } from "../../core/simulation/routePreparation";
|
||||
import { viewedAiRun } from "../../core/simulation/viewedAiRun";
|
||||
import { lazy, Suspense, useCallback, useEffect, useRef, useState } from "react";
|
||||
import { Button, GlassSurface, Icon, IconButton, LoadingRegion, InspectorSelectField, ResourceList, ResourceRow, StatusBadge, ToastStack } from "@nodedc/ui-react";
|
||||
@@ -45,6 +46,7 @@ export function AiPolygonWorkspace() {
|
||||
const [robotId, setRobotId] = useState<string | null>(null);
|
||||
const [planId, setPlanId] = useState<string | null>(null);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [saveError,setSaveError] = useState<string|null>(null);
|
||||
const [saveOpen, setSaveOpen] = useState(false);
|
||||
const [launchAfterSave,setLaunchAfterSave] = useState(false);
|
||||
const [editorPlan,setEditorPlan] = useState<AiPlan|null>(null);
|
||||
@@ -132,6 +134,8 @@ export function AiPolygonWorkspace() {
|
||||
const plan = planId === null ? plans[0] : plans.find((p) => p.plan_id === planId);
|
||||
const [roverSettings,setRoverSettings] = useRoverSettings(robot,
|
||||
plan?.settings?.max_speed_mps ?? selected?.settings.max_speed_mps ?? .15);
|
||||
const routeRequired=!!selected?.local_scene;
|
||||
const preparation=useRoutePreparation(draft?.cache??null,robot,draft?.points??EMPTY_POINTS,plan,setError);
|
||||
const start = (purpose: "planning" | "evaluation", task=plan) => {
|
||||
if (!selected || !robot) return;
|
||||
if (purpose === "planning") { setEditorPlan(plan??(planId===null?previousPlan:null)??null);setSettingsOpen(false); setDraft(null); setPlanning(true); return; }
|
||||
@@ -145,19 +149,20 @@ export function AiPolygonWorkspace() {
|
||||
};
|
||||
const save = () => {
|
||||
if (!draft || !robot) return;
|
||||
setSaving(true);
|
||||
void saveLocalPlan(draft.cache, robot, draft.points, planName, draft.id, draft.sequence).then(async (saved) => {
|
||||
setSaving(true);setSaveError(null);
|
||||
void saveLocalPlan(draft.cache, robot, draft.points, planName, draft.id, draft.sequence, preparation.key).then(async (saved) => {
|
||||
setPlanId(saved.plan_id);setSaveOpen(false);
|
||||
setCatalog(prior=>prior?{...prior,plans:[saved,...prior.plans.filter(p=>p.plan_id!==saved.plan_id)]}:prior);
|
||||
if(launchAfterSave)start("evaluation",saved);
|
||||
}).catch((caught: Error) => setError(caught.message)).finally(() => setSaving(false));
|
||||
}).catch((caught: Error) => setSaveError(caught.message)).finally(() => setSaving(false));
|
||||
};
|
||||
const openSave = (launch=false) => {
|
||||
setLaunchAfterSave(launch);setPlanName(plan?aiPlanName(plan):`${selected?.name} · маршрут`);setSaveOpen(true);
|
||||
setSaveError(null);setLaunchAfterSave(launch);setPlanName(plan?aiPlanName(plan):`${selected?.name} · маршрут`);setSaveOpen(true);
|
||||
};
|
||||
const launchDraft = () => {
|
||||
if(!draft||!robot)return;
|
||||
if(planMatchesDraft(plan,draft.cache.key,robot.sha256,draft.points))start("evaluation",plan);
|
||||
if(routeRequired && (!preparation.route || !preparation.key))return;
|
||||
if(planMatchesDraft(plan,draft.cache.key,robot.sha256,draft.points) && (!routeRequired || plan?.prepared_route?.sha256===preparation.route?.sha256))start("evaluation",plan);
|
||||
else openSave(true);
|
||||
};
|
||||
const connection = <StatusBadge tone={catalog?.runtime.available ? "success" : "neutral"}>
|
||||
@@ -177,21 +182,24 @@ export function AiPolygonWorkspace() {
|
||||
</div>
|
||||
{roverSettings?<p>{roverSettings.max_speed_mps} м/с · {roverSettings.base_mass_kg+roverSettings.payload_mass_kg} кг с грузом</p>:null}</>:null}
|
||||
{mode==="inference"&&!running&&!starting?<AiTaskSelect inspector={!planning} plans={plans} value={plan?.plan_id??""}
|
||||
disabled={running||starting||saving} onUpdated={planUpdated}
|
||||
disabled={running||starting||saving||preparation.busy} onUpdated={planUpdated}
|
||||
onChange={(id)=>{setPlanId(id);setEditorPlan(plans.find(p=>p.plan_id===id)??null);setSettingsOpen(false);setPlanning(true);}}/>:null}
|
||||
<div className="ai-polygon__actions">{mode === "manual" ? <Button variant="primary" icon={<Icon name={manual ? "stop" : "play"} />}
|
||||
disabled={!robot || !selected.settings.prepared}
|
||||
onClick={()=>{setSettingsOpen(false);setManual(!manual);}}>{manual ? "Завершить" : "Старт"}</Button> : planning ? <>
|
||||
<Button disabled={starting || saving || !draft || draft.points.length < 2}
|
||||
<Button disabled={starting || saving || preparation.busy || (routeRequired && !preparation.route) || !draft || draft.points.length < 2}
|
||||
onClick={()=>openSave()}>Сохранить задание</Button>
|
||||
<Button variant="primary" icon={<Icon name="play"/>} loading={starting}
|
||||
disabled={saving || !draft || draft.points.length<2 || selected.inference_ready===false || !catalog.runtime.available || !!catalog.runtime.active_run}
|
||||
onClick={launchDraft}>Запустить симуляцию</Button>
|
||||
{!routeRequired || preparation.route ? <Button variant="primary" icon={<Icon name="play"/>} loading={starting}
|
||||
disabled={saving || !draft || selected.inference_ready===false || !catalog.runtime.available || !!catalog.runtime.active_run}
|
||||
onClick={launchDraft}>Запустить симуляцию</Button> : <Button variant="primary" icon={<Icon name="plan"/>}
|
||||
loading={preparation.busy} disabled={saving || starting || !draft || draft.points.length<2 || !catalog.runtime.available}
|
||||
onClick={()=>void preparation.prepare()}>Спланировать маршрут</Button>}
|
||||
{preparation.busy?<p role="status">Рассчитываем маршрут по сцене</p>:null}
|
||||
</> : !running ? <>
|
||||
<Button loading={starting} disabled={!robot || !selected.settings.prepared}
|
||||
onClick={() => start("planning")}>Подготовить маршрут</Button>
|
||||
<Button variant="primary" icon={<Icon name="play" />} loading={starting}
|
||||
disabled={!robot || !plan || selected.inference_ready === false || !catalog.runtime.available || !!catalog.runtime.active_run}
|
||||
disabled={!robot || !plan || (routeRequired && !plan.prepared_route) || selected.inference_ready === false || !catalog.runtime.available || !!catalog.runtime.active_run}
|
||||
onClick={() => start("evaluation")}>Запустить симуляцию</Button>
|
||||
</> : <AiRunActions run={run!} onChange={acceptRun} />}</div>
|
||||
</> : null;
|
||||
@@ -250,7 +258,7 @@ export function AiPolygonWorkspace() {
|
||||
<LocalManualScene key={selected.world_id} world={selected} robot={robot} settings={roverSettings} actionsHost={actionsHost} headerActions={sceneActions} />
|
||||
</Suspense> : planning ? <Suspense fallback={<LoadingRegion loading label="Открываем редактор" />}>
|
||||
<AiLocalPlanner key={selected.world_id} world={selected} initialPoints={editorPlan?.points ?? EMPTY_POINTS}
|
||||
busy={starting || saving} onDraft={setDraft} actionsHost={actionsHost} headerActions={sceneActions} />
|
||||
busy={starting || saving || preparation.busy} preparedRoute={preparation.route} onDraft={setDraft} actionsHost={actionsHost} headerActions={sceneActions} />
|
||||
</Suspense> : <LoadingRegion loading={starting} label="Открываем симуляцию на Worker">
|
||||
{mode === "inference" && running && run ? <AiWorldStream key={run.run_id} world={selected} run={run} onBack={returnToLocations} onChange={acceptRun}
|
||||
actionsHost={actionsHost} headerActions={sceneActions}
|
||||
@@ -268,7 +276,7 @@ export function AiPolygonWorkspace() {
|
||||
setRoverSettingsOpen(false);
|
||||
try {setRoverSettings(value);} catch {setError("Настройки применены, но не сохранены в браузере. После перезагрузки их нужно задать снова.");}
|
||||
}}/> : null}
|
||||
{saveOpen?<AiPlanSaveWindow name={planName} onName={setPlanName} busy={saving}
|
||||
{saveOpen?<AiPlanSaveWindow error={saveError} name={planName} onName={setPlanName} busy={saving}
|
||||
launch={launchAfterSave} onClose={()=>setSaveOpen(false)} onSave={save}/>:null}
|
||||
<SimulationSourceImport open={importChoice} onClose={()=>setImportChoice(false)}
|
||||
onPly={()=>setImporting({source:null})} onReady={(id)=>{void load();setSelectedId(id);}} />
|
||||
|
||||
Reference in New Issue
Block a user