feat(phase2): implement AMR robot state machine, task lifecycles, inventory catalog, and Phase 2 OpenUSD scene

This commit is contained in:
2026-10-19 16:16:23 +05:30
parent 0427ab273d
commit 863eda87f5
21 changed files with 2206 additions and 74 deletions
+97 -12
View File
@@ -1,7 +1,8 @@
"""OpenUSD scene generator for Warehouse Robot Fleet Digital Twin.
Exports an ASCII OpenUSD (.usda) scene compliant with NVIDIA Omniverse Kit 110.4
and standard USD specifications (Z-up, 1.0 meter units).
and standard USD specifications (Z-up, 1.0 meter units). Supports visual representations
of facility geometry, zones, operational stations, charging pads, and the AMR robot fleet.
"""
from __future__ import annotations
@@ -9,18 +10,41 @@ from __future__ import annotations
from pathlib import Path
from typing import Any, Dict, List, Optional
from warehouse_twin.domain.robot import Robot, RobotTypeSpec
from warehouse_twin.domain.warehouse import WarehouseModel
class WarehouseUSDGenerator:
"""Generates OpenUSD (.usda) 3D scenes from a WarehouseModel."""
"""Generates OpenUSD (.usda) 3D scenes from WarehouseModel and Robot fleet entities."""
def __init__(self, model: WarehouseModel) -> None:
"""Initialize generator with physical warehouse layout model."""
def __init__(
self,
model: WarehouseModel,
robots: Optional[List[Robot]] = None,
) -> None:
"""Initialize generator with physical warehouse layout model and optional robot fleet."""
self.model = model
self.robots = robots or []
@classmethod
def from_config_bundle(cls, bundle: Any) -> WarehouseUSDGenerator:
"""Construct generator loading both warehouse layout and fleet from ConfigBundle."""
model = WarehouseModel.from_config_dict(bundle.warehouse)
# Parse robot type specs
type_specs: Dict[str, RobotTypeSpec] = {}
for t_id, t_data in bundle.robots.get("robot_types", {}).items():
type_specs[t_id] = RobotTypeSpec.from_dict(t_id, t_data)
# Build robot fleet entities
robots: List[Robot] = []
for r_data in bundle.robots.get("fleet", []):
robots.append(Robot.from_fleet_dict(r_data, type_specs))
return cls(model, robots)
def generate_usda_content(self) -> str:
"""Construct valid ASCII OpenUSD 3D stage content representing the warehouse."""
"""Construct valid ASCII OpenUSD 3D stage content representing the warehouse and AMRs."""
dims = self.model.dimensions
w = dims.width
d = dims.depth
@@ -150,7 +174,7 @@ class WarehouseUSDGenerator:
spec = rack_specs.get(loc.zone, {"color": "(0.5, 0.5, 0.5)", "scale": (1.0, 0.5, 1.5)})
col = spec["color"]
sx, sy, sz = spec["scale"]
rz = sz # base is at z=0, center is at z=sz
rz = sz
lines.extend([
f' def Xform "{loc_id}"',
@@ -179,18 +203,17 @@ class WarehouseUSDGenerator:
for st_id, st in self.model.stations.items():
pos = st.position
# Distinguish station visuals
if "inbound" in st.station_type.value:
st_col = "(0.85, 0.25, 0.2)" # Inbound red/orange
st_col = "(0.85, 0.25, 0.2)"
st_dim = (1.5, 2.0, 0.15)
elif "outbound" in st.station_type.value:
st_col = "(0.9, 0.4, 0.1)" # Outbound amber
st_col = "(0.9, 0.4, 0.1)"
st_dim = (1.5, 2.0, 0.15)
elif "picking" in st.station_type.value:
st_col = "(0.2, 0.75, 0.85)" # Picking teal/cyan
st_col = "(0.2, 0.75, 0.85)"
st_dim = (2.0, 1.2, 0.4)
else:
st_col = "(0.25, 0.8, 0.35)" # Production feed green
st_col = "(0.25, 0.8, 0.35)"
st_dim = (1.8, 1.8, 0.25)
lines.extend([
@@ -228,7 +251,7 @@ class WarehouseUSDGenerator:
"",
' def Cube "ChargePad"',
" {",
" color3f[] primvars:displayColor = [(0.15, 0.85, 0.95)]", # Electric cyan pad
" color3f[] primvars:displayColor = [(0.15, 0.85, 0.95)]",
" }",
"",
' def Cube "StationPedestal"',
@@ -243,6 +266,68 @@ class WarehouseUSDGenerator:
lines.extend([
" }",
])
# -------------------------------------------------------------------------
# Autonomous Mobile Robot (AMR) Fleet (Phase 2 Addition)
# -------------------------------------------------------------------------
if self.robots:
lines.extend([
"",
" # -------------------------------------------------------------------------",
" # Autonomous Mobile Robot (AMR) Fleet",
" # -------------------------------------------------------------------------",
' def Scope "Robots"',
" {",
])
for robot in self.robots:
is_heavy = "heavy" in robot.robot_type
pos = robot.position
if is_heavy:
# Heavy AMR: Industrial Amber rugged pallet chassis (1.4m x 1.0m x 0.45m)
chassis_col = "(0.92, 0.65, 0.08)"
indicator_col = "(0.15, 0.85, 0.3)" # Emerald ready glow
scale_tuple = (0.70, 0.50, 0.225)
elev_z = 0.225
else:
# Light AMR: High-tech pearl white agile chassis (0.8m x 0.6m x 0.35m)
chassis_col = "(0.88, 0.90, 0.95)"
indicator_col = "(0.15, 0.75, 0.95)" # Electric cyan ready glow
scale_tuple = (0.40, 0.30, 0.175)
elev_z = 0.175
lines.extend([
f' def Xform "{robot.robot_id}"',
" {",
f" double3 xformOp:translate = ({pos.x:.2f}, {pos.y:.2f}, {elev_z:.3f})",
f" double3 xformOp:rotateZ = {robot.yaw_degrees:.1f}",
' uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateZ"]',
"",
' def Cube "Chassis"',
" {",
f" double3 xformOp:scale = ({scale_tuple[0]}, {scale_tuple[1]}, {scale_tuple[2]})",
' uniform token[] xformOpOrder = ["xformOp:scale"]',
f" color3f[] primvars:displayColor = [{chassis_col}]",
" float[] primvars:displayRoughness = [0.25]",
" }",
"",
' def Cube "StatusDome"',
" {",
f" double3 xformOp:translate = (0.0, 0.0, {scale_tuple[2] + 0.08:.3f})",
f" double3 xformOp:scale = ({scale_tuple[0] * 0.4:.3f}, {scale_tuple[1] * 0.4:.3f}, 0.05)",
' uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:scale"]',
f" color3f[] primvars:displayColor = [{indicator_col}]",
" }",
" }",
])
lines.extend([
" }",
])
lines.extend([
"}",
"",
])