Files
two_floor_elevator_sim/scripts/generate_maps.py

606 lines
32 KiB
Python
Executable File

#!/usr/bin/env python3
"""Generate the two-floor elevator warehouse world and matching navigation maps."""
from math import atan2, cos, hypot, pi, sin
from pathlib import Path
from xml.etree import ElementTree as ET
ROOT = Path(__file__).resolve().parents[1]
OUTPUT = ROOT / "maps"
RESOLUTION = 0.05
SIZE = 2048
ORIGIN = -51.2
FREE = 254
OCCUPIED = 0
FLOOR_2_Z = 28.0
ELEVATOR_TRAVEL_SPEED = 2.2
FLOORS = ((1, 0.0), (2, FLOOR_2_Z))
WAREHOUSE_HALF = 46.0
SHELL_WALL_THICKNESS = 0.30
RACK_X = (-28.0, -20.5)
RACK_Y = (-32.0, -18.0, 18.0, 32.0)
# Both floors fit 25 shelves in the green storage zone (-33 <= x <= -17).
# The two columns keep a 3.3 m gap between their map obstacle footprints.
FLOOR_1_EXTRA_RACKS = (
(-28.0, -25.0), (-28.0, 25.0),
(-28.0, -28.5), (-28.0, -12.0), (-28.0, -6.0),
(-28.0, 0.0), (-28.0, 6.0), (-28.0, 12.0), (-28.0, 28.5),
(-20.5, -28.5), (-20.5, -25.0), (-20.5, -12.0),
(-20.5, -6.0), (-20.5, 0.0), (-20.5, 6.0),
(-20.5, 12.0), (-20.5, 25.0),
)
FLOOR_2_RACKS = ((-29.0, -32.0), (-20.5, -32.0),
(-29.0, -25.0), (-29.0, -18.0), (-20.5, -18.0),
(-29.0, 18.0), (-20.5, 18.0),
(-20.5, 25.0), (-29.0, 32.0), (-20.5, 32.0),
(-29.0, -28.5), (-29.0, -12.0), (-29.0, -6.0),
(-29.0, 0.0), (-29.0, 6.0), (-29.0, 12.0),
(-29.0, 25.0), (-29.0, 28.5),
(-20.5, -25.0), (-20.5, -11.0), (-20.5, -5.0),
(-20.5, 1.0), (-20.5, 7.0), (-20.5, 13.0),
(-20.5, 28.5))
# ShelfE has a roughly 3.92 x 0.88 m collision footprint. ShelfD has no local mesh;
# ShelfF is 18 m long and overlapped neighboring racks in the former layout.
RACK_MODELS = ("two_floor_aws_robomaker_warehouse_ShelfE_01",)
# The two original L-shaped walls overlap the outer shell at the east corners.
# South-east needs +90 deg; north-east needs 180 deg (90 deg farther around).
FLOOR_1_WORKCELLS = ((35.98, -36.74, pi / 2),
(36.74, 35.98, pi))
CONVEYORS = ((-2.0, -32.0), (-2.0, 32.0))
MACHINES = ((7.0, -32.0), (7.0, 32.0))
FLOOR_2_WORKCELLS = ((24.0, -32.0, 0.0),
(22.0, 31.0, 1.5708))
FLOOR_2_CONVEYORS = ((-2.0, -32.0), (-4.0, 31.0))
FLOOR_2_MACHINES = ((7.0, -32.0), (6.0, 31.0))
FLOOR_2_INSPECTION_BENCH = (6.0, 40.0)
PALLETS = ((-41.0, -12.0), (-41.0, 0.0), (-41.0, 12.0),
(-36.0, -12.0), (-36.0, 0.0), (-36.0, 12.0),
(10.0, -20.0), (10.0, 20.0), (35.0, -18.0), (35.0, 18.0))
ATRIUM_RECT = (-12.0, 12.0, -14.0, 14.0)
LIFT_X = 39.0
LIFT_Y = 0.0
# Matches the car, paired doors, and the configurable safety map overlay.
LIFT_RECT = (37.5, 40.9, -1.75, 1.75)
LIFT_MAP_SHIFT_X = 35.72
LIFT_MAP_SHIFT_Y = 0.0
STAIR_RECT = (-44.0, -36.0, -25.0, -15.0)
PILLARS = tuple((x, y) for x in (-42.0, -7.0, 36.0) for y in (-42.0, 42.0))
FLOOR_ZONES = (
(-39.0, 0.0, 12.0, 28.0, "0.20 0.38 0.50 1"), # receiving and staging
(-25.0, 0.0, 16.0, 72.0, "0.24 0.36 0.31 1"), # pallet storage
(0.0, 0.0, 18.0, 74.0, "0.43 0.37 0.26 1"), # production aisle
(27.0, 0.0, 18.0, 72.0, "0.28 0.34 0.39 1"), # work cells / dispatch
)
MEZZANINE_ZONES = (
(-25.0, 0.0, 16.0, 72.0, "0.24 0.36 0.31 1"),
(27.0, 0.0, 17.0, 72.0, "0.28 0.34 0.39 1"),
(0.0, -32.0, 18.0, 20.0, "0.43 0.37 0.26 1"),
(-3.0, 32.0, 18.0, 20.0, "0.43 0.37 0.26 1"),
)
def in_rect(x, y, rect):
x0, x1, y0, y1 = rect
return x0 <= x <= x1 and y0 <= y <= y1
def model_box(name, x, y, z, sx, sy, sz, color, collision=True, yaw=0.0, pitch=0.0):
collision_xml = ""
if collision:
collision_xml = (f'<collision name="collision"><geometry><box><size>{sx} {sy} {sz}'
f'</size></box></geometry></collision>')
return (f'<model name="{name}"><static>true</static><pose>{x} {y} {z} 0 {pitch} {yaw}</pose>'
f'<link name="link">{collision_xml}<visual name="visual"><geometry><box>'
f'<size>{sx} {sy} {sz}</size></box></geometry><material><ambient>{color}</ambient>'
f'<diffuse>{color}</diffuse></material></visual></link></model>')
def model_cylinder(name, x, y, z, radius, length, color):
return (f'<model name="{name}"><static>true</static><pose>{x} {y} {z} 0 1.5708 0</pose>'
f'<link name="link"><collision name="collision"><geometry><cylinder><radius>{radius}'
f'</radius><length>{length}</length></cylinder></geometry></collision><visual name="visual">'
f'<geometry><cylinder><radius>{radius}</radius><length>{length}</length></cylinder></geometry>'
f'<material><ambient>{color}</ambient><diffuse>{color}</diffuse></material></visual></link></model>')
def floor_patch(name, x, y, z, sx, sy, color):
return (f'<model name="{name}"><static>true</static><pose>{x} {y} {z} 0 0 0</pose>'
f'<link name="link"><visual name="visual"><cast_shadows>false</cast_shadows>'
f'<geometry><plane><normal>0 0 1</normal>'
f'<size>{sx} {sy}</size></plane></geometry><material><ambient>{color}</ambient><diffuse>{color}</diffuse>'
f'</material></visual></link></model>')
def link_box(name, x, y, z, sx, sy, sz, color, collision=True):
collision_xml = ""
if collision:
collision_xml = (f'<collision name="collision"><geometry><box><size>{sx} {sy} {sz}'
f'</size></box></geometry></collision>')
return (f'<link name="{name}"><pose>{x} {y} {z} 0 0 0</pose>{collision_xml}'
f'<visual name="visual"><geometry><box><size>{sx} {sy} {sz}</size></box></geometry>'
f'<material><ambient>{color}</ambient><diffuse>{color}</diffuse></material></visual></link>')
def include_model(uri, name, x, y, z, yaw=0.0, static=None):
static_xml = "" if static is None else f"<static>{str(static).lower()}</static>"
return (f'<include><uri>model://{uri}</uri><name>{name}</name>'
f'<pose>{x} {y} {z} 0 0 {yaw}</pose>{static_xml}</include>')
def walking_actor(name, z, waypoints):
"""Loop a worker with explicit, stationary turns at both route endpoints."""
if len(waypoints) < 5 or waypoints[0][1:] != waypoints[-1][1:]:
raise ValueError(f"{name}: route must end at its starting pose")
for start, end in zip(waypoints, waypoints[1:]):
t0, x0, y0, yaw0 = start
t1, x1, y1, yaw1 = end
if t1 <= t0:
raise ValueError(f"{name}: waypoint times must increase")
if hypot(x1 - x0, y1 - y0) > 1e-6:
heading = atan2(y1 - y0, x1 - x0)
if any(abs((yaw - heading + pi) % (2 * pi) - pi) > 0.01
for yaw in (yaw0, yaw1)):
raise ValueError(f"{name}: walking segment faces away from travel direction")
points = "".join(
f'<waypoint><time>{time}</time><pose>{x} {y} {z} 0 0 {yaw}</pose></waypoint>'
for time, x, y, yaw in waypoints
)
# Same walk.dae skeleton and leg collision scaling used in factory_ss_demo.
# A local plugin initializes the actor's generated bone links; the scripted
# waypoints keep ownership of movement and the stationary endpoint turns.
bone_scales = (
("LHipJoint_LeftUpLeg_collision", "0.01 0.001 0.001"),
("LeftUpLeg_LeftLeg_collision", "8.0 8.0 1.0"),
("LeftLeg_LeftFoot_collision", "10.0 10.0 1.5"),
("LeftFoot_LeftToeBase_collision", "4.0 4.0 1.5"),
("RHipJoint_RightUpLeg_collision", "0.01 0.001 0.001"),
("RightUpLeg_RightLeg_collision", "8.0 8.0 1.0"),
("RightLeg_RightFoot_collision", "10.0 10.0 1.5"),
("RightFoot_RightToeBase_collision", "4.0 4.0 1.5"),
("Spine_Spine1_collision", "0.01 0.001 0.001"),
("Neck_Neck1_collision", "0.01 0.001 0.001"),
("Neck1_Head_collision", "5.0 5.0 3.0"),
("LeftShoulder_LeftArm_collision", "0.01 0.001 0.001"),
("LeftArm_LeftForeArm_collision", "5.0 5.0 1.0"),
("LeftForeArm_LeftHand_collision", "5.0 5.0 1.0"),
("LeftFingerBase_LeftHandIndex1_collision", "4.0 4.0 3.0"),
("RightShoulder_RightArm_collision", "0.01 0.001 0.001"),
("RightArm_RightForeArm_collision", "5.0 5.0 1.0"),
("RightForeArm_RightHand_collision", "5.0 5.0 1.0"),
("RightFingerBase_RightHandIndex1_collision", "4.0 4.0 3.0"),
("LowerBack_Spine_collision", "12.0 20.0 5.0"),
)
collisions = "".join(
f'<collision scale="{scale}"'
+ (' pose="0.05 0 0 0 -0.2 0"' if bone == "LowerBack_Spine_collision" else '')
+ f'>{bone}</collision>'
for bone, scale in bone_scales
)
return (f'<actor name="{name}"><pose>0 0 0 0 0 0</pose>'
'<skin><filename>model://two_floor_walking_person/meshes/walk.dae</filename><scale>1.0</scale></skin>'
'<animation name="walking"><filename>model://two_floor_walking_person/meshes/walk.dae</filename>'
'<scale>1.0</scale><interpolate_x>true</interpolate_x></animation>'
f'<script><loop>true</loop><auto_start>true</auto_start>'
f'<trajectory id="0" type="walking">{points}</trajectory></script>'
'<plugin name="walking_actor_collision" '
'filename="libtwo_floor_elevator_walking_actor_collision_plugin.so">'
f'{collisions}</plugin></actor>')
def rack_instances(floor, z):
out = []
if floor == 2:
for idx, (x, y) in enumerate(FLOOR_2_RACKS):
out.append(include_model(RACK_MODELS[0], f"rack_f2_{idx}", x, y, z))
return out
for ix, x in enumerate(RACK_X):
for iy, y in enumerate(RACK_Y):
uri = RACK_MODELS[(ix * 3 + iy) % len(RACK_MODELS)]
out.append(include_model(uri, f"rack_f{floor}_{ix}_{iy}", x, y, z))
for idx, (x, y) in enumerate(FLOOR_1_EXTRA_RACKS):
out.append(include_model(RACK_MODELS[0], f"rack_f1_extra_{idx}", x, y, z))
return out
def workcell_collision_boxes(floor):
"""Use each floor's workcell SDF boxes when rasterizing the floor maps."""
model = "two_floor_workcell_enclosed" if floor == 1 else "two_floor_workcell_open"
sdf = ET.parse(ROOT / f"models/{model}/model.sdf").getroot()
boxes = []
for collision in sdf.findall(".//link/collision"):
if collision.get("name") == "floor":
continue # A walkable floor is not a map obstacle.
size = collision.findtext("geometry/box/size")
if size is None:
raise ValueError(f"workcell collision {collision.get('name')} has no box")
local_pose = tuple(map(float, collision.findtext("pose", "0 0 0 0 0 0").split()))
if len(local_pose) != 6 or any(abs(angle) > 1e-6 for angle in local_pose[3:]):
raise ValueError(f"unsupported workcell collision pose: {local_pose}")
sx, sy, _ = map(float, size.split())
boxes.append((local_pose[0], local_pose[1], sx, sy))
if not boxes:
raise ValueError("workcell has no collision boxes")
return boxes
def mark_map(floor):
pixels = bytearray([FREE] * (SIZE * SIZE))
def mark_rect(x0, x1, y0, y1):
col0 = max(0, int((x0 - ORIGIN) / RESOLUTION))
col1 = min(SIZE, int((x1 - ORIGIN) / RESOLUTION) + 1)
row0 = max(0, int((y0 - ORIGIN) / RESOLUTION))
row1 = min(SIZE, int((y1 - ORIGIN) / RESOLUTION) + 1)
for map_row in range(row0, row1):
image_row = SIZE - 1 - map_row
begin = image_row * SIZE + col0
pixels[begin:begin + col1 - col0] = bytes([OCCUPIED]) * (col1 - col0)
mark_rect(-46.2, -45.8, -46.2, 46.2)
mark_rect(45.8, 46.2, -46.2, 46.2)
mark_rect(-46.2, 46.2, -46.2, -45.8)
mark_rect(-46.2, 46.2, 45.8, 46.2)
mark_rect(*LIFT_RECT)
mark_rect(*STAIR_RECT)
if floor == 2:
mark_rect(*ATRIUM_RECT)
for x, y in PILLARS:
mark_rect(x - 0.45, x + 0.45, y - 0.45, y + 0.45)
rack_centers = (FLOOR_2_RACKS if floor == 2 else
tuple((x, y) for x in RACK_X for y in RACK_Y) + FLOOR_1_EXTRA_RACKS)
for x, y in rack_centers:
mark_rect(x - 2.1, x + 2.1, y - 0.6, y + 0.6)
workcells = FLOOR_2_WORKCELLS if floor == 2 else FLOOR_1_WORKCELLS
conveyors = FLOOR_2_CONVEYORS if floor == 2 else CONVEYORS
machines = FLOOR_2_MACHINES if floor == 2 else MACHINES
workcell_boxes = workcell_collision_boxes(floor)
for x, y, yaw in workcells:
c, s = cos(yaw), sin(yaw)
for local_x, local_y, sx, sy in workcell_boxes:
center_x = x + c * local_x - s * local_y
center_y = y + s * local_x + c * local_y
half_x = (abs(c) * sx + abs(s) * sy) / 2
half_y = (abs(s) * sx + abs(c) * sy) / 2
mark_rect(center_x - half_x, center_x + half_x,
center_y - half_y, center_y + half_y)
for x, y in conveyors:
mark_rect(x - 6.2, x + 6.2, y - 0.8, y + 0.8)
for x, y in machines:
mark_rect(x - 1.6, x + 1.6, y - 1.7, y + 1.7)
for x, y in PALLETS:
mark_rect(x - 0.65, x + 0.65, y - 0.65, y + 0.65)
# Conveyor controls, packing benches, dock container, and pallet jack.
extras = [(4.0, -27.0, 0.8, 0.7), (4.0, 37.0, 0.8, 0.7),
(-38.0, 15.0, 1.8, 0.9), (-40.0, 24.0, 2.0, 5.0),
(-40.0, -3.0, 1.2, 1.0), (18.0, 0.0, 2.0, 1.0),
(28.5, 0.0, 1.8, 0.9), (37.1, 2.05, 0.25, 0.38),
(15.0, 18.0, 1.25, 1.25), (17.0, -18.0, 1.25, 1.25),
(4.0, 36.3, 0.8, 0.7)]
if floor == 2:
# The north line console moves with its machine; the new bench is a
# floor-2-only obstacle. Floor-1 map footprints remain byte-identical.
extras.pop(1)
extras[-1] = (2.9, 35.3, 0.8, 0.7)
extras.append((*FLOOR_2_INSPECTION_BENCH, 1.6, 0.6))
for x, y, hx, hy in extras:
mark_rect(x - hx, x + hx, y - hy, y + hy)
folder = OUTPUT / f"floor_{floor}"
folder.mkdir(parents=True, exist_ok=True)
(folder / f"floor_{floor}.pgm").write_bytes(
f"P5\n{SIZE} {SIZE}\n255\n".encode("ascii") + pixels)
(folder / f"floor_{floor}.yaml").write_text(
f"image: floor_{floor}.pgm\nresolution: {RESOLUTION:.6f}\n"
f"origin: [{ORIGIN:.6f}, {ORIGIN:.6f}, 0.0]\n"
"negate: 0\noccupied_thresh: 0.65\nfree_thresh: 0.196\n")
def floor_deck(floor, z):
x_edges = (-46.0, -44.0, -36.0, -12.0, 12.0, 37.5, 40.9, 46.0)
y_edges = (-46.0, -25.0, -15.0, -14.0, 14.0, -1.75, 1.75, 24.0, 46.0)
# Sort the axis split points; the lift aperture is cut from both floors,
# while the mezzanine atrium and stair opening are only cut from floor 2.
y_edges = tuple(sorted(y_edges))
# Merge adjacent cells with the same unobstructed Y span. This keeps the
# lift, atrium, and stair openings while avoiding dozens of box seams on
# the drive surface.
rectangles = []
open_runs = {}
for xi in range(len(x_edges) - 1):
x0, x1 = x_edges[xi:xi + 2]
runs = []
run_start = None
for yi in range(len(y_edges) - 1):
y0, y1 = y_edges[yi:yi + 2]
cx, cy = (x0 + x1) / 2.0, (y0 + y1) / 2.0
opening = in_rect(cx, cy, LIFT_RECT) or (
floor == 2 and (in_rect(cx, cy, ATRIUM_RECT) or in_rect(cx, cy, STAIR_RECT)))
if not opening and run_start is None:
run_start = y0
if opening and run_start is not None:
runs.append((run_start, y0))
run_start = None
if run_start is not None:
runs.append((run_start, y_edges[-1]))
next_runs = {run: open_runs.get(run, x0) for run in runs}
for (y0, y1), start_x in open_runs.items():
if (y0, y1) not in next_runs:
rectangles.append((start_x, x0, y0, y1))
open_runs = next_runs
for (y0, y1), start_x in open_runs.items():
rectangles.append((start_x, x_edges[-1], y0, y1))
shade = "0.47 0.50 0.52 1" if floor == 1 else "0.52 0.52 0.48 1"
return [model_box(f"floor_{floor}_deck_{idx}", (x0 + x1) / 2.0, (y0 + y1) / 2.0,
z - 0.15, x1 - x0, y1 - y0, 0.30, shade)
for idx, (x0, x1, y0, y1) in enumerate(rectangles)]
def conveyor_line(name, x, y, z):
out = [
model_box(f"{name}_base", x, y, z + 0.42, 12.0, 1.05, 0.68, "0.22 0.25 0.28 1"),
model_box(f"{name}_belt", x, y, z + 0.80, 11.4, 0.72, 0.10, "0.12 0.14 0.15 1"),
model_box(f"{name}_guard_a", x, y - 0.49, z + 0.91, 11.6, 0.06, 0.18, "0.76 0.60 0.12 1"),
model_box(f"{name}_guard_b", x, y + 0.49, z + 0.91, 11.6, 0.06, 0.18, "0.76 0.60 0.12 1"),
]
for i in range(12):
roller_x = x - 5.25 + i * 0.95
out.append(model_cylinder(f"{name}_roller_{i}", roller_x, y, z + 0.78,
0.055, 0.78, "0.53 0.56 0.58 1"))
for i, color in enumerate(("0.18 0.58 0.40 1", "0.77 0.33 0.20 1", "0.20 0.39 0.68 1")):
bx = x - 3.4 + i * 2.1
out.append(model_box(f"{name}_carton_{i}", bx, y, z + 1.28, 0.9, 0.72, 0.82, color))
return out
def elevator_car():
parts = [
'<model name="elevator_car"><static>true</static><pose>39.0 0.0 0 0 0 0</pose>',
link_box("platform", 0, 0, -0.04, 2.8, 2.8, 0.08, "0.20 0.24 0.28 1"),
link_box("left_side", 0, -1.36, 1.15, 2.8, 0.08, 2.3, "0.33 0.40 0.46 1"),
link_box("right_side", 0, 1.36, 1.15, 2.8, 0.08, 2.3, "0.33 0.40 0.46 1"),
link_box("rear", 1.36, 0, 1.15, 0.08, 2.8, 2.3, "0.54 0.59 0.62 1"),
link_box("rear_mirror", 1.30, 0.10, 1.40, 0.025, 1.45, 1.22, "0.31 0.43 0.52 1", False),
link_box("rear_handrail", 1.20, 0.10, 0.92, 0.07, 1.45, 0.055, "0.80 0.83 0.85 1", False),
link_box("control_panel", 1.28, -0.90, 1.18, 0.06, 0.27, 0.62, "0.07 0.09 0.10 1", False),
link_box("indicator", 1.24, -0.90, 1.42, 0.02, 0.16, 0.12, "0.10 0.72 0.42 1", False),
'</model>',
]
return "\n".join(parts)
def elevator_components():
out = [
elevator_car(),
model_box("elevator_car_door_left", 37.64, -0.70, 1.15,
0.08, 1.4, 2.3, "0.55 0.60 0.64 1"),
model_box("elevator_car_door_right", 37.64, 0.70, 1.15,
0.08, 1.4, 2.3, "0.55 0.60 0.64 1"),
]
for floor, z in FLOORS:
out.extend((
model_box(f"landing_door_floor_{floor}_left", 37.52, -0.70, z + 1.15,
0.08, 1.4, 2.3, "0.68 0.72 0.75 1"),
model_box(f"landing_door_floor_{floor}_right", 37.52, 0.70, z + 1.15,
0.08, 1.4, 2.3, "0.68 0.72 0.75 1"),
))
# Fixed jambs and header frame each landing; doors remain independently animated.
out.extend((
model_box(f"lift_jamb_left_f{floor}", 37.48, -1.52, z + 1.20,
0.16, 0.16, 2.4, "0.24 0.29 0.33 1"),
model_box(f"lift_jamb_right_f{floor}", 37.48, 1.52, z + 1.20,
0.16, 0.16, 2.4, "0.24 0.29 0.33 1"),
model_box(f"lift_header_f{floor}", 37.48, 0.0, z + 2.42,
0.16, 3.2, 0.16, "0.24 0.29 0.33 1"),
model_box(f"lift_threshold_f{floor}", 37.58, 0.0, z + 0.015,
0.22, 2.85, 0.03, "0.82 0.64 0.10 1", False),
model_box(f"lift_guard_north_f{floor}", 39.15, 1.70, z + 0.58,
2.9, 0.10, 1.16, "0.20 0.25 0.29 1"),
model_box(f"lift_guard_south_f{floor}", 39.15, -1.70, z + 0.58,
2.9, 0.10, 1.16, "0.20 0.25 0.29 1"),
model_box(f"lift_guard_rear_f{floor}", 40.70, 0.0, z + 0.58,
0.10, 3.5, 1.16, "0.20 0.25 0.29 1"),
model_box(f"lift_call_panel_f{floor}", 37.12, 2.05, z + 1.15,
0.12, 0.28, 1.35, "0.10 0.13 0.16 1"),
model_box(f"lift_display_f{floor}", 37.04, 2.05, z + 1.52,
0.025, 0.18, 0.13, "0.12 0.75 0.46 1", False),
))
out.append(model_box("elevator_guide_left", 40.78, -1.48, FLOOR_2_Z / 2.0,
0.08, 0.08, FLOOR_2_Z, "0.19 0.22 0.25 1"))
out.append(model_box("elevator_guide_right", 40.78, 1.48, FLOOR_2_Z / 2.0,
0.08, 0.08, FLOOR_2_Z, "0.19 0.22 0.25 1"))
out.append(f'''<plugin name="two_floor_elevator_controller" filename="libtwo_floor_elevator_gazebo_plugin.so">
<elevator_id>sim_elevator</elevator_id><car_id>sim_car_1</car_id>
<car_model>elevator_car</car_model><robot_model>robot</robot_model>
<door_floor_1_left_model>landing_door_floor_1_left</door_floor_1_left_model>
<door_floor_1_right_model>landing_door_floor_1_right</door_floor_1_right_model>
<door_floor_2_left_model>landing_door_floor_2_left</door_floor_2_left_model>
<door_floor_2_right_model>landing_door_floor_2_right</door_floor_2_right_model>
<car_door_left_model>elevator_car_door_left</car_door_left_model>
<car_door_right_model>elevator_car_door_right</car_door_right_model>
<floor_1_id>floor_1</floor_1_id><floor_2_id>floor_2</floor_2_id>
<floor_1_z>0.0</floor_1_z><floor_2_z>{FLOOR_2_Z}</floor_2_z>
<travel_speed>{ELEVATOR_TRAVEL_SPEED}</travel_speed><travel_timeout>30.0</travel_timeout>
<door_travel_time>1.5</door_travel_time><door_open_timeout>12.0</door_open_timeout>
<door_leaf_open_offset>1.4</door_leaf_open_offset><door_pocket_offset_x>0.15</door_pocket_offset_x>
<cabin_half_x>1.4</cabin_half_x><cabin_half_y>1.4</cabin_half_y>
<door_half_width>1.4</door_half_width><boarding_timeout>45.0</boarding_timeout>
</plugin>''')
return out
def build_world():
out = ['''<?xml version="1.0"?>
<sdf version="1.7">
<world name="two_floor_warehouse">
<gravity>0 0 -9.81</gravity>
<physics name="default_physics" type="ode"><max_step_size>0.001</max_step_size>
<real_time_update_rate>1000</real_time_update_rate><real_time_factor>1.0</real_time_factor>
<ode><solver><type>quick</type><iters>100</iters><sor>1.3</sor></solver></ode>
</physics>
<scene><ambient>0.60 0.63 0.65 1</ambient><background>0.25 0.31 0.37 1</background><shadows>true</shadows></scene>
<gui><camera name="warehouse_overview"><pose>-88 -106 99 0 0.62 0.72</pose>
<view_controller>orbit</view_controller><projection_type>perspective</projection_type></camera></gui>
<light name="sun" type="directional"><pose>0 0 32 0 0 0</pose><direction>-0.35 0.25 -1</direction>
<diffuse>0.90 0.90 0.86 1</diffuse><specular>0.22 0.22 0.22 1</specular><cast_shadows>true</cast_shadows></light>
<model name="ground_plane"><static>true</static><pose>0 0 -2 0 0 0</pose><link name="ground">
<collision name="collision"><geometry><plane><normal>0 0 1</normal><size>140 140</size></plane></geometry></collision>
<visual name="visual"><geometry><plane><normal>0 0 1</normal><size>140 140</size></plane></geometry>
<material><ambient>0.26 0.28 0.30 1</ambient></material></visual>
</link></model>''']
for floor, z in FLOORS:
prefix = f"floor_{floor}"
out.extend(floor_deck(floor, z))
# The original floor-1 workcell walls reach 7.25 m; match their top
# edge so the corner enclosures blend into the perimeter shell.
wall_height = 7.25 if floor == 1 else 6.0
wall_z = z + wall_height / 2
wall_color = "0.65 0.68 0.70 1" if floor == 1 else "0.70 0.68 0.61 1"
out.extend((
model_box(f"{prefix}_north_wall", 0, 46, wall_z,
92, SHELL_WALL_THICKNESS, wall_height, wall_color),
model_box(f"{prefix}_south_wall", 0, -46, wall_z,
92, SHELL_WALL_THICKNESS, wall_height, wall_color),
model_box(f"{prefix}_east_wall", 46, 0, wall_z,
SHELL_WALL_THICKNESS, 92, wall_height, wall_color),
model_box(f"{prefix}_west_wall", -46, 0, wall_z,
SHELL_WALL_THICKNESS, 92, wall_height, wall_color),
))
# Thin, visual-only planar paint keeps the collision floor level.
# Colored department floors help distinguish operations when viewing the whole site.
zones = FLOOR_ZONES if floor == 1 else MEZZANINE_ZONES
for ix, (cx, cy, sx, sy, color) in enumerate(zones):
out.append(floor_patch(f"{prefix}_zone_{ix}", cx, cy, z + 0.002, sx, sy, color))
# Yellow/black dock and lift approach markings.
for ix in range(12):
x = -44.0 + ix * 0.85
if ix % 2 == 0:
out.append(floor_patch(f"{prefix}_dock_hazard_{ix}", x, 5.4, z + 0.004,
0.52, 0.12, "0.90 0.66 0.08 1"))
out.append(floor_patch(f"{prefix}_lift_hazard_{ix}", 37.0, -1.65 + ix * 0.30,
z + 0.004, 0.12, 0.24, "0.90 0.66 0.08 1"))
# Open structural frame leaves a large, guarded atrium above the floor-1 production line.
for idx, (x, y) in enumerate(PILLARS):
out.append(model_box(f"support_column_{idx}", x, y, FLOOR_2_Z / 2.0,
0.70, 0.70, FLOOR_2_Z, "0.42 0.46 0.49 1"))
rail_z = FLOOR_2_Z + 0.58
out.extend((
model_box("atrium_guard_east", 12.0, 0, rail_z, 0.12, 28.0, 1.16, "0.19 0.24 0.28 1"),
model_box("atrium_guard_west", -12.0, 0, rail_z, 0.12, 28.0, 1.16, "0.19 0.24 0.28 1"),
model_box("atrium_guard_north", 0, 14.0, rail_z, 24.0, 0.12, 1.16, "0.19 0.24 0.28 1"),
model_box("atrium_guard_south", 0, -14.0, rail_z, 24.0, 0.12, 1.16, "0.19 0.24 0.28 1"),
model_box("stairwell_guard_east", -36.0, -20.0, rail_z, 0.12, 10.0, 1.16, "0.86 0.62 0.12 1"),
model_box("stairwell_guard_west", -44.0, -20.0, rail_z, 0.12, 10.0, 1.16, "0.86 0.62 0.12 1"),
model_box("stairwell_guard_north", -40.0, -15.0, rail_z, 8.0, 0.12, 1.16, "0.86 0.62 0.12 1"),
model_box("stairwell_guard_south", -40.0, -25.0, rail_z, 8.0, 0.12, 1.16, "0.86 0.62 0.12 1"),
))
# Eight switchback flights fit the existing blocked stairwell footprint.
# The perimeter remains guarded; this stair is decorative, not a robot route.
flights, steps_per_flight = 8, 20
flight_run = 6.84
flight_rise = FLOOR_2_Z / flights
step_rise = flight_rise / steps_per_flight
rail_length = hypot(flight_run, flight_rise)
rail_pitch = atan2(flight_rise, flight_run)
for flight in range(flights):
forward = flight % 2 == 0
lane_y = -22.8 if forward else -18.0
for step in range(steps_per_flight):
along = step * flight_run / (steps_per_flight - 1)
x = -43.5 + along if forward else -36.66 - along
z = flight * flight_rise + (step + 1) * step_rise - 0.09
out.append(model_box(f"stair_flight_{flight + 1}_step_{step:02d}", x, lane_y, z,
0.50, 3.0, 0.18, "0.54 0.57 0.59 1"))
for side, dy in (("south", -1.55), ("north", 1.55)):
out.append(model_box(f"stair_flight_{flight + 1}_rail_{side}", -40.08, lane_y + dy,
flight * flight_rise + flight_rise / 2.0 + 1.0,
rail_length, 0.10, 0.10, "0.20 0.25 0.29 1",
pitch=-rail_pitch if forward else rail_pitch))
if flight < flights - 1:
landing_x = -36.7 if forward else -43.3
out.append(model_box(f"stair_landing_{flight + 1}", landing_x, -20.4,
(flight + 1) * flight_rise - 0.09,
1.3, 7.8, 0.18, "0.48 0.52 0.55 1"))
# Factory traffic: receiving, mixed rack storage, two production conveyors,
# assembly work cells, packing benches, boxed pallets, and dispatch staging.
for floor, z in FLOORS:
workcells = FLOOR_2_WORKCELLS if floor == 2 else FLOOR_1_WORKCELLS
conveyors = FLOOR_2_CONVEYORS if floor == 2 else CONVEYORS
machines = FLOOR_2_MACHINES if floor == 2 else MACHINES
out.extend(rack_instances(floor, z))
for idx, (x, y, yaw) in enumerate(workcells):
uri = "two_floor_workcell_enclosed" if floor == 1 else "two_floor_workcell_open"
out.append(include_model(uri, f"assembly_workcell_f{floor}_{idx}",
x, y, z, yaw, True))
for idx, (x, y) in enumerate(conveyors):
out.extend(conveyor_line(f"line_f{floor}_{idx}", x, y, z))
for idx, (x, y) in enumerate(machines):
out.append(model_box(f"process_machine_f{floor}_{idx}", x, y, z + 1.55,
2.8, 2.8, 3.1, "0.34 0.39 0.42 1"))
out.append(model_box(f"machine_window_f{floor}_{idx}", x - 0.15, y - 1.41, z + 1.9,
1.65, 0.025, 0.85, "0.16 0.46 0.52 1", False))
out.append(include_model("two_floor_control_console", f"line_console_f{floor}_{idx}",
x - 3.1, y + 4.3, z, 0.0, True))
for idx, (x, y) in enumerate(PALLETS):
out.append(include_model("two_floor_euro_pallet", f"load_pallet_f{floor}_{idx}", x, y, z, 0.0, True))
# Load a selection of pallets with visually distinct cartons and totes.
for idx, (x, y) in enumerate(PALLETS[:6]):
uri = ("two_floor_big_box", "two_floor_big_box2", "two_floor_big_box3", "two_floor_big_box4", "two_floor_closed_box_ariac", "two_floor_open_box_ariac")[idx]
out.append(include_model(uri, f"cargo_{uri}_f{floor}_{idx}", x, y, z, 0.0, False))
out.append(include_model("two_floor_aws_robomaker_warehouse_DeskC_01", f"dock_desk_f{floor}", -38.0, 15.0, z, 0.0))
out.append(include_model("two_floor_aws_robomaker_warehouse_TrashCanC_01", f"trash_bin_f{floor}", 34.0, 15.0, z, 0.0))
out.append(include_model("two_floor_aws_robomaker_warehouse_ClutteringA_01", f"material_tote_f{floor}", 15.0, 18.0, z, 0.0, True))
out.append(include_model("two_floor_aws_robomaker_warehouse_ClutteringC_01", f"material_crate_f{floor}", 17.0, -18.0, z, 0.0, True))
out.append(include_model("two_floor_aws_robomaker_warehouse_PalletJackB_01", f"pallet_jack_f{floor}", -40.0, -3.0, z, 0.2, True))
out.append(model_box(f"packing_bench_f{floor}", 18.0, 0.0, z + 0.46,
3.8, 1.2, 0.92, "0.46 0.34 0.23 1"))
out.append(model_box(f"qc_table_f{floor}", 28.5, 0.0, z + 0.48,
3.2, 1.4, 0.96, "0.40 0.45 0.47 1"))
out.append(include_model("two_floor_aws_robomaker_warehouse_DeskC_01", f"qc_station_f{floor}",
21.0, 2.8, z, 1.5708))
if floor == 2:
bx, by = FLOOR_2_INSPECTION_BENCH
out.append(model_box("floor_2_inspection_bench", bx, by, z + 0.48,
3.0, 1.0, 0.96, "0.24 0.48 0.55 1"))
# Keep one directional light and ambient lighting. The 24 per-floor
# point lights made Gazebo's orbit/zoom GUI noticeably less responsive
# in a direct comparison with an otherwise identical world.
if floor == 1:
out.append(include_model("two_floor_shipping_container_ariac", "receiving_container", -40.0, 23.0, z, 0.0, True))
out.extend(elevator_components())
out.extend((
walking_actor("worker_storage_f1", 0.0,
((0, -13, -34, 1.5708), (68, -13, 34, 1.5708),
(72, -13, 34, -1.5708), (140, -13, -34, -1.5708),
(144, -13, -34, 1.5708))),
walking_actor("worker_dispatch_f1", 0.0,
((0, 34, -12, 1.5708), (24, 34, 12, 1.5708),
(28, 34, 12, -1.5708), (52, 34, -12, -1.5708),
(56, 34, -12, 1.5708))),
walking_actor("worker_atrium_f2", FLOOR_2_Z,
((0, -10, 18, 0), (20, 10, 18, 0),
(24, 10, 18, 3.14159), (44, -10, 18, 3.14159),
(48, -10, 18, 0))),
walking_actor("worker_dispatch_f2", FLOOR_2_Z,
((0, 34, -12, 1.5708), (24, 34, 12, 1.5708),
(28, 34, 12, -1.5708), (52, 34, -12, -1.5708),
(56, 34, -12, 1.5708))),
))
out.append(" </world>\n</sdf>\n")
(ROOT / "worlds" / "two_floor_elevator.world").write_text("\n".join(out))
if __name__ == "__main__":
OUTPUT.mkdir(parents=True, exist_ok=True)
for floor, _ in FLOORS:
mark_map(floor)
build_world()
print(f"Generated two-floor warehouse (floor 2 z={FLOOR_2_Z} m) and maps under {OUTPUT}")