feat(phase-4): implement spatial routing, time-space reservations, and traffic manager

- Implemented PathPlanner using NetworkX Dijkstra/A* with dynamic edge congestion weights and robot capability enforcement.
- Implemented TimeSpaceReservationGrid with head-on collision avoidance on bidirectional corridors and 1.0s following headway buffers.
- Implemented TrafficManager with multi-AMR right-of-way arbitration (task priority, loaded over empty) and deadlock timeout dynamic rerouting.
- Integrated waypoint traversal into SimPy simulation engine with real-time trajectory recording and export.
- Generated omniverse/scenes/warehouse_phase4.usda with navigation corridor overlays.
- Expanded test suite to 95 unit tests with 100% pass rate.
This commit is contained in:
2026-10-21 10:59:11 +05:30
parent 3d9fb6be66
commit 56806079a9
20 changed files with 3225 additions and 104 deletions
+74
View File
@@ -0,0 +1,74 @@
"""Unit tests for AMR motion trajectory recording and JSON export."""
from __future__ import annotations
import json
from pathlib import Path
import pytest
from warehouse_twin.config.loader import ConfigLoader
from warehouse_twin.domain.inventory import InventoryCatalog
from warehouse_twin.domain.robot import Robot, RobotTypeSpec
from warehouse_twin.domain.warehouse import WarehouseModel
from warehouse_twin.simulation.dispatcher import DispatcherSettings
from warehouse_twin.simulation.order_generator import WorkloadConfig
from warehouse_twin.simulation.sim_engine import SimulationEnvironment
def test_trajectory_recording_and_export(project_config_dir: Path, tmp_path: Path):
"""Verify trajectory recording during simulation and JSON export schema compliance."""
loader = ConfigLoader(project_config_dir)
bundle = loader.load_all()
warehouse = WarehouseModel.from_config_dict(bundle.warehouse)
catalog = InventoryCatalog.from_config_dict(bundle.inventory)
type_specs = {
t_id: RobotTypeSpec.from_dict(t_id, t_data)
for t_id, t_data in bundle.robots["robot_types"].items()
}
fleet = [
Robot.from_fleet_dict(r_data, type_specs)
for r_data in bundle.robots["fleet"]
]
workload = WorkloadConfig.from_dict(bundle.simulation)
dispatch_settings = DispatcherSettings.from_dict(bundle.dispatch_policies)
env = SimulationEnvironment(
warehouse=warehouse,
catalog=catalog,
fleet=fleet,
workload_config=workload,
dispatcher_settings=dispatch_settings,
seed=42,
)
env.run(until=300.0)
# Verify trajectory recording in memory
for r_id in env.robots:
assert r_id in env.trajectories
assert len(env.trajectories[r_id]) > 0
point = env.trajectories[r_id][0]
assert "t" in point
assert "pos" in point
assert "yaw_deg" in point
assert "state" in point
assert len(point["pos"]) == 3
# Export trajectory
out_file = tmp_path / "test_trajectory.json"
exported_path = env.export_trajectories(out_file)
assert exported_path.exists()
assert exported_path.stat().st_size > 1000
with open(exported_path, "r", encoding="utf-8") as f:
data = json.load(f)
assert "metadata" in data
assert "robots" in data
meta = data["metadata"]
assert meta["coordinate_system"] == "right_handed_cartesian_meters_z_up"
assert meta["total_robots"] == 4
assert meta["total_trajectory_points"] > 10
assert len(data["robots"]) == 4