feat: add two-floor elevator simulation
This commit is contained in:
141
scripts/check_model_assets.py
Normal file
141
scripts/check_model_assets.py
Normal file
@@ -0,0 +1,141 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Check that the warehouse world resolves all of its bundled model assets."""
|
||||
|
||||
from pathlib import Path
|
||||
from xml.etree import ElementTree as ET
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
MODELS = ROOT / "models"
|
||||
ERRORS = []
|
||||
|
||||
|
||||
def inside(path, directory):
|
||||
try:
|
||||
path.resolve().relative_to(directory.resolve())
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
|
||||
def check_uri(uri, source):
|
||||
if not uri.startswith("model://"):
|
||||
ERRORS.append(f"{source}: external asset URI {uri}")
|
||||
return
|
||||
relative = uri[len("model://"):]
|
||||
path = MODELS / relative
|
||||
if not relative or not inside(path, MODELS):
|
||||
ERRORS.append(f"{source}: model URI escapes this package: {uri}")
|
||||
return
|
||||
if not path.exists():
|
||||
ERRORS.append(f"{source}: missing {uri}")
|
||||
|
||||
|
||||
def check_file(path, candidates, source, model_dir):
|
||||
if not any(inside(candidate, model_dir) and candidate.is_file()
|
||||
for candidate in candidates):
|
||||
ERRORS.append(f"{source}: missing or external asset {path}")
|
||||
|
||||
|
||||
def main():
|
||||
world = ET.parse(ROOT / "worlds" / "two_floor_elevator.world").getroot()
|
||||
world_uris = world.findall(".//uri")
|
||||
world_uris += world.findall(".//actor/skin/filename")
|
||||
world_uris += world.findall(".//actor/animation/filename")
|
||||
used_names = set()
|
||||
for element in world_uris:
|
||||
uri = (element.text or "").strip()
|
||||
check_uri(uri, "world")
|
||||
if uri.startswith("model://"):
|
||||
used_names.add(uri[len("model://"):].split("/", 1)[0])
|
||||
|
||||
# The actor mesh is visual only unless its locally built plugin enables
|
||||
# Gazebo's bone collisions. Check the world-to-library contract here.
|
||||
actor_plugin = "libtwo_floor_elevator_walking_actor_collision_plugin.so"
|
||||
for actor in world.findall(".//actor"):
|
||||
plugin = actor.find("plugin")
|
||||
bones = set() if plugin is None else {
|
||||
(item.text or "").strip() for item in plugin.findall("collision")
|
||||
}
|
||||
if plugin is None or plugin.get("filename") != actor_plugin:
|
||||
ERRORS.append(f"{actor.get('name')}: missing local collision plugin")
|
||||
if not {"LeftLeg_LeftFoot_collision", "RightLeg_RightFoot_collision"} <= bones:
|
||||
ERRORS.append(f"{actor.get('name')}: missing lower-leg collision scales")
|
||||
|
||||
for name in used_names:
|
||||
model_dir = MODELS / name
|
||||
for filename in ("model.config", "model.sdf"):
|
||||
if not (model_dir / filename).is_file():
|
||||
ERRORS.append(f"{name}: missing {filename}")
|
||||
config = model_dir / "model.config"
|
||||
if config.is_file():
|
||||
for sdf_path in ET.parse(config).getroot().findall(".//sdf"):
|
||||
candidate = model_dir / (sdf_path.text or "").strip()
|
||||
if not inside(candidate, model_dir) or not candidate.is_file():
|
||||
ERRORS.append(f"{config}: missing or external SDF {sdf_path.text}")
|
||||
|
||||
for model_dir in MODELS.iterdir():
|
||||
if model_dir.is_symlink():
|
||||
ERRORS.append(f"external symlink: {model_dir}")
|
||||
if not model_dir.is_dir():
|
||||
continue
|
||||
for sdf in model_dir.glob("*.sdf"):
|
||||
for element in ET.parse(sdf).getroot().findall(".//uri"):
|
||||
check_uri((element.text or "").strip(), sdf)
|
||||
|
||||
for mesh in MODELS.rglob("*"):
|
||||
if mesh.is_symlink():
|
||||
ERRORS.append(f"external symlink: {mesh}")
|
||||
if not mesh.is_file():
|
||||
continue
|
||||
model_dir = mesh.parent.parent
|
||||
if mesh.suffix.lower() == ".dae":
|
||||
dae = ET.parse(mesh).getroot()
|
||||
for image in dae.findall(".//{*}library_images/{*}image"):
|
||||
element = image.find("{*}init_from")
|
||||
if element is None or not element.text:
|
||||
continue
|
||||
texture = element.text.strip()
|
||||
check_file(texture, (mesh.parent / texture,
|
||||
model_dir / "materials" / "textures" / texture,
|
||||
model_dir / texture), mesh, model_dir)
|
||||
elif mesh.suffix.lower() == ".obj":
|
||||
for line in mesh.read_text(errors="replace").splitlines():
|
||||
if line.startswith("mtllib "):
|
||||
library = line.split(None, 1)[1].strip()
|
||||
check_file(library, (mesh.parent / library,), mesh, model_dir)
|
||||
elif mesh.suffix.lower() == ".mtl":
|
||||
for line in mesh.read_text(errors="replace").splitlines():
|
||||
if line.startswith(("map_Kd ", "map_Ka ", "map_Bump ", "bump ")):
|
||||
texture = line.split(None, 1)[1].strip()
|
||||
check_file(texture, (mesh.parent / texture,
|
||||
model_dir / "materials" / "textures" / texture), mesh, model_dir)
|
||||
|
||||
package_xml = (ROOT / "package.xml").read_text()
|
||||
if "<exec_depend>factory_ss_demo</exec_depend>" in package_xml:
|
||||
ERRORS.append("package.xml still depends on factory_ss_demo")
|
||||
package = ET.parse(ROOT / "package.xml").getroot()
|
||||
gazebo_export = package.find("export/gazebo_ros")
|
||||
if gazebo_export is None or gazebo_export.get("gazebo_model_path") != "${prefix}/models":
|
||||
ERRORS.append("package.xml does not export the bundled Gazebo model path")
|
||||
cmake = (ROOT / "CMakeLists.txt").read_text()
|
||||
if "install(DIRECTORY action config docs launch licenses maps models" not in cmake:
|
||||
ERRORS.append("CMakeLists.txt does not install the models directory")
|
||||
if "add_library(two_floor_elevator_walking_actor_collision_plugin SHARED" not in cmake:
|
||||
ERRORS.append("CMakeLists.txt does not build the actor collision plugin")
|
||||
if not (ROOT / "src" / "walking_actor_collision_plugin.cpp").is_file():
|
||||
ERRORS.append("missing local actor collision plugin source")
|
||||
if "add_library(two_floor_elevator_gazebo_plugin SHARED" not in cmake:
|
||||
ERRORS.append("CMakeLists.txt does not build the elevator plugin")
|
||||
if not (ROOT / "src" / "elevator_gazebo_plugin.cpp").is_file():
|
||||
ERRORS.append("missing local elevator plugin source")
|
||||
|
||||
for error in ERRORS:
|
||||
print("ERROR:", error)
|
||||
if ERRORS:
|
||||
raise SystemExit(1)
|
||||
print(f"PASS: {len(used_names)} bundled model directories and all mesh textures resolve locally")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
183
scripts/clip_floor1_workcell.py
Normal file
183
scripts/clip_floor1_workcell.py
Normal file
@@ -0,0 +1,183 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Clip the floor-1 workcell at the outer faces of the warehouse shell.
|
||||
|
||||
Both corner poses map local negative X and Y outside the building. Clipping
|
||||
these two half-planes once therefore works for both workcell instances.
|
||||
"""
|
||||
|
||||
from math import pi
|
||||
from pathlib import Path
|
||||
from xml.etree import ElementTree as ET
|
||||
|
||||
from generate_maps import FLOOR_1_WORKCELLS, SHELL_WALL_THICKNESS, WAREHOUSE_HALF
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
MESH_DIR = ROOT / "models/two_floor_workcell_open/meshes"
|
||||
MODEL_DIR = ROOT / "models/two_floor_workcell_enclosed"
|
||||
SOURCE_MESH = MESH_DIR / "mesh_floor1.dae"
|
||||
TARGET_MESH = MESH_DIR / "mesh_floor1_clipped.dae"
|
||||
SOURCE_SDF = MODEL_DIR / "model_full.sdf"
|
||||
TARGET_SDF = MODEL_DIR / "model.sdf"
|
||||
NS = "http://www.collada.org/2005/11/COLLADASchema"
|
||||
|
||||
SE_X, SE_Y, SE_YAW = FLOOR_1_WORKCELLS[0]
|
||||
NE_X, NE_Y, NE_YAW = FLOOR_1_WORKCELLS[1]
|
||||
if abs(SE_YAW - pi / 2) > 1e-8 or abs(NE_YAW - pi) > 1e-8:
|
||||
raise RuntimeError("floor-1 workcell corner rotations changed")
|
||||
SHELL_OUTER = WAREHOUSE_HALF + SHELL_WALL_THICKNESS / 2
|
||||
# Both corner poses require the same local clipping planes. Fail if a pose
|
||||
# change breaks that property rather than silently leaving exterior geometry.
|
||||
x_limits = (-SHELL_OUTER - SE_Y, NE_X - SHELL_OUTER)
|
||||
y_limits = (SE_X - SHELL_OUTER, NE_Y - SHELL_OUTER)
|
||||
if abs(x_limits[0] - x_limits[1]) > 1e-8 or abs(y_limits[0] - y_limits[1]) > 1e-8:
|
||||
raise RuntimeError("floor-1 workcell corners need separate clipping planes")
|
||||
MIN_X_M = x_limits[0]
|
||||
MIN_Y_M = y_limits[0]
|
||||
MIN_X_MM = MIN_X_M * 1000.0
|
||||
MIN_Y_MM = MIN_Y_M * 1000.0
|
||||
|
||||
|
||||
def clip_mesh():
|
||||
ET.register_namespace("", NS)
|
||||
tree = ET.parse(SOURCE_MESH)
|
||||
mesh = tree.getroot().find(
|
||||
f".//{{{NS}}}geometry[@id='geom-WorkCell']/{{{NS}}}mesh")
|
||||
if mesh is None:
|
||||
raise RuntimeError("workcell geometry is missing")
|
||||
|
||||
source_ids = ("geom-WorkCell-positions", "geom-WorkCell-normals",
|
||||
"geom-WorkCell-map1")
|
||||
arrays = []
|
||||
for source_id in source_ids:
|
||||
source = mesh.find(f"{{{NS}}}source[@id='{source_id}']")
|
||||
if source is None:
|
||||
raise RuntimeError(f"missing Collada source {source_id}")
|
||||
floats = source.find(f"{{{NS}}}float_array")
|
||||
accessor = source.find(f"{{{NS}}}technique_common/{{{NS}}}accessor")
|
||||
stride = int(accessor.get("stride"))
|
||||
original_text = floats.text.strip()
|
||||
values = list(map(float, original_text.split()))
|
||||
assert len(values) == int(floats.get("count")) == stride * int(accessor.get("count"))
|
||||
arrays.append((values, stride, floats, accessor, original_text, []))
|
||||
|
||||
def coordinate(vertex, axis):
|
||||
positions = arrays[0][0]
|
||||
return positions[3 * vertex[0] + axis]
|
||||
|
||||
def intersection(a, b, axis, bound):
|
||||
av, bv = coordinate(a, axis), coordinate(b, axis)
|
||||
t = (bound - av) / (bv - av)
|
||||
indices = []
|
||||
for (values, stride, _, _, _, added), ai, bi in zip(arrays, a, b):
|
||||
result = [values[ai * stride + i] * (1 - t) +
|
||||
values[bi * stride + i] * t for i in range(stride)]
|
||||
index = len(values) // stride
|
||||
values.extend(result)
|
||||
added.extend(result)
|
||||
indices.append(index)
|
||||
return tuple(indices)
|
||||
|
||||
def clip_polygon(vertices, axis, bound):
|
||||
if not vertices:
|
||||
return []
|
||||
output = []
|
||||
previous = vertices[-1]
|
||||
previous_inside = coordinate(previous, axis) >= bound
|
||||
for current in vertices:
|
||||
current_inside = coordinate(current, axis) >= bound
|
||||
if current_inside != previous_inside:
|
||||
output.append(intersection(previous, current, axis, bound))
|
||||
if current_inside:
|
||||
output.append(current)
|
||||
previous, previous_inside = current, current_inside
|
||||
# A polygon touching the clipping plane can produce repeated corners.
|
||||
clean = []
|
||||
for vertex in output:
|
||||
if not clean or any(abs(coordinate(vertex, i) - coordinate(clean[-1], i)) > 1e-6
|
||||
for i in range(3)):
|
||||
clean.append(vertex)
|
||||
if len(clean) > 1 and all(abs(coordinate(clean[0], i) - coordinate(clean[-1], i)) <= 1e-6
|
||||
for i in range(3)):
|
||||
clean.pop()
|
||||
return clean if len(clean) >= 3 else []
|
||||
|
||||
changed = 0
|
||||
for primitive in list(mesh.findall(f"{{{NS}}}polylist")):
|
||||
inputs = primitive.findall(f"{{{NS}}}input")
|
||||
if [(i.get("semantic"), i.get("offset")) for i in inputs] != [
|
||||
("VERTEX", "0"), ("NORMAL", "1"), ("TEXCOORD", "2")]:
|
||||
raise RuntimeError("unexpected workcell polylist layout")
|
||||
counts = list(map(int, primitive.find(f"{{{NS}}}vcount").text.split()))
|
||||
values = list(map(int, primitive.find(f"{{{NS}}}p").text.split()))
|
||||
if len(counts) != int(primitive.get("count")) or sum(counts) * 3 != len(values):
|
||||
raise RuntimeError("invalid workcell polylist indices")
|
||||
offset = 0
|
||||
new_counts, new_values = [], []
|
||||
for count in counts:
|
||||
polygon = [tuple(values[offset + 3 * i:offset + 3 * i + 3])
|
||||
for i in range(count)]
|
||||
offset += count * 3
|
||||
clipped = clip_polygon(polygon, 0, MIN_X_MM)
|
||||
clipped = clip_polygon(clipped, 1, MIN_Y_MM)
|
||||
if clipped != polygon:
|
||||
changed += 1
|
||||
if clipped:
|
||||
new_counts.append(len(clipped))
|
||||
new_values.extend(index for vertex in clipped for index in vertex)
|
||||
if not new_counts:
|
||||
mesh.remove(primitive)
|
||||
continue
|
||||
primitive.set("count", str(len(new_counts)))
|
||||
primitive.find(f"{{{NS}}}vcount").text = " ".join(map(str, new_counts))
|
||||
primitive.find(f"{{{NS}}}p").text = " ".join(map(str, new_values))
|
||||
|
||||
for values, stride, floats, accessor, original_text, added in arrays:
|
||||
floats.set("count", str(len(values)))
|
||||
accessor.set("count", str(len(values) // stride))
|
||||
floats.text = original_text + (" " + " ".join(f"{v:.12g}" for v in added)
|
||||
if added else "")
|
||||
tree.write(TARGET_MESH, encoding="utf-8", xml_declaration=True)
|
||||
print(f"Clipped {changed} polygons -> {TARGET_MESH.relative_to(ROOT)}")
|
||||
|
||||
|
||||
def clip_sdf():
|
||||
tree = ET.parse(SOURCE_SDF)
|
||||
link = tree.getroot().find(".//link")
|
||||
uri = link.find("visual/geometry/mesh/uri")
|
||||
if uri is None or uri.text != "model://two_floor_workcell_open/meshes/mesh_floor1.dae":
|
||||
raise RuntimeError("unexpected floor-1 workcell mesh URI")
|
||||
uri.text = "model://two_floor_workcell_open/meshes/mesh_floor1_clipped.dae"
|
||||
|
||||
changed = 0
|
||||
for item in list(link):
|
||||
if item.tag not in ("visual", "collision"):
|
||||
continue
|
||||
size_element = item.find("geometry/box/size")
|
||||
if size_element is None:
|
||||
continue
|
||||
pose_element = item.find("pose")
|
||||
pose = list(map(float, pose_element.text.split())) if pose_element is not None else [0.0] * 6
|
||||
sx, sy, sz = map(float, size_element.text.split())
|
||||
if any(abs(angle) > 1e-8 for angle in pose[3:]):
|
||||
raise RuntimeError(f"rotated box is not supported: {item.get('name')}")
|
||||
x0, x1 = max(pose[0] - sx / 2, MIN_X_M), pose[0] + sx / 2
|
||||
y0, y1 = max(pose[1] - sy / 2, MIN_Y_M), pose[1] + sy / 2
|
||||
if x1 <= x0 or y1 <= y0:
|
||||
link.remove(item)
|
||||
changed += 1
|
||||
continue
|
||||
if abs((x1 - x0) - sx) > 1e-9 or abs((y1 - y0) - sy) > 1e-9:
|
||||
pose[:2] = [(x0 + x1) / 2, (y0 + y1) / 2]
|
||||
if pose_element is None:
|
||||
pose_element = ET.SubElement(item, "pose")
|
||||
pose_element.text = " ".join(f"{v:.9g}" for v in pose)
|
||||
size_element.text = f"{x1 - x0:.9g} {y1 - y0:.9g} {sz:.9g}"
|
||||
changed += 1
|
||||
tree.write(TARGET_SDF, encoding="utf-8", xml_declaration=True)
|
||||
print(f"Clipped {changed} boxes -> {TARGET_SDF.relative_to(ROOT)}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
clip_mesh()
|
||||
clip_sdf()
|
||||
601
scripts/generate_maps.py
Executable file
601
scripts/generate_maps.py
Executable file
@@ -0,0 +1,601 @@
|
||||
#!/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 = 14.0
|
||||
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('''<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>14.0</floor_2_z>
|
||||
<travel_speed>1.1</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"),
|
||||
))
|
||||
|
||||
# Switchback stair keeps the rise practical and leaves a guarded mezzanine opening.
|
||||
steps_per_flight = 20
|
||||
flight_run = 6.84
|
||||
flight_rise = (FLOOR_2_Z - 0.35) / 2.0
|
||||
for step in range(steps_per_flight):
|
||||
along = step * (flight_run / (steps_per_flight - 1))
|
||||
rise = step * (flight_rise / (steps_per_flight - 1))
|
||||
out.append(model_box(f"stair_flight_1_step_{step:02d}", -43.5 + along, -22.8,
|
||||
0.18 + rise, 0.50, 3.0, 0.18, "0.54 0.57 0.59 1"))
|
||||
out.append(model_box(f"stair_flight_2_step_{step:02d}", -36.66 - along, -18.0,
|
||||
7.18 + rise, 0.50, 3.0, 0.18, "0.58 0.60 0.61 1"))
|
||||
out.append(model_box("stair_mid_landing", -36.5, -20.5, 7.0,
|
||||
2.2, 7.0, 0.18, "0.48 0.52 0.55 1"))
|
||||
rail_length = 9.7
|
||||
out.extend((
|
||||
model_box("stair_flight_1_rail_south", -40.08, -24.35, 4.30,
|
||||
rail_length, 0.10, 0.10, "0.20 0.25 0.29 1", pitch=-0.771),
|
||||
model_box("stair_flight_1_rail_north", -40.08, -21.25, 4.30,
|
||||
rail_length, 0.10, 0.10, "0.20 0.25 0.29 1", pitch=-0.771),
|
||||
model_box("stair_flight_2_rail_south", -40.08, -19.55, 11.30,
|
||||
rail_length, 0.10, 0.10, "0.20 0.25 0.29 1", pitch=0.771),
|
||||
model_box("stair_flight_2_rail_north", -40.08, -16.45, 11.30,
|
||||
rail_length, 0.10, 0.10, "0.20 0.25 0.29 1", pitch=0.771),
|
||||
))
|
||||
|
||||
# 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}")
|
||||
57
scripts/make_open_workcell_mesh.py
Normal file
57
scripts/make_open_workcell_mesh.py
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Derive floor-specific visuals from the bundled original workcell mesh."""
|
||||
|
||||
from pathlib import Path
|
||||
from xml.etree import ElementTree as ET
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SOURCE = ROOT / "models/two_floor_workcell_open/meshes/mesh.dae"
|
||||
OPEN_TARGET = ROOT / "models/two_floor_workcell_open/meshes/mesh_open.dae"
|
||||
FLOOR_1_TARGET = ROOT / "models/two_floor_workcell_open/meshes/mesh_floor1.dae"
|
||||
COLLADA_NS = "http://www.collada.org/2005/11/COLLADASchema"
|
||||
REMOVED_MATERIALS = {
|
||||
"Floor", # The warehouse deck already supplies a flat floor.
|
||||
"Wall_Concrete",
|
||||
"Wall_Corrugated",
|
||||
"Stairs",
|
||||
"Pillar",
|
||||
"RollupDoor", # Door and window faces belong to the removed walls.
|
||||
"singleDorr",
|
||||
"Door_Window_1",
|
||||
"yellowPaint", # Raised stair/structure markings.
|
||||
"Yellow",
|
||||
}
|
||||
|
||||
|
||||
def write_variant(target, removed_materials):
|
||||
tree = ET.parse(SOURCE)
|
||||
mesh = tree.getroot().find(
|
||||
f".//{{{COLLADA_NS}}}geometry[@id='geom-WorkCell']/{{{COLLADA_NS}}}mesh")
|
||||
if mesh is None:
|
||||
raise RuntimeError("workcell mesh geometry is missing")
|
||||
|
||||
removed = set()
|
||||
for primitive in list(mesh):
|
||||
if primitive.tag == f"{{{COLLADA_NS}}}polylist":
|
||||
material = primitive.get("material")
|
||||
if material in removed_materials:
|
||||
mesh.remove(primitive)
|
||||
removed.add(material)
|
||||
if removed != removed_materials:
|
||||
raise RuntimeError(f"unexpected workcell materials: removed {sorted(removed)}")
|
||||
|
||||
tree.write(target, encoding="utf-8", xml_declaration=True)
|
||||
print(f"Wrote {target.relative_to(ROOT)}")
|
||||
|
||||
|
||||
def main():
|
||||
ET.register_namespace("", COLLADA_NS)
|
||||
write_variant(OPEN_TARGET, REMOVED_MATERIALS)
|
||||
# Floor 1 keeps every original wall, pillar, stair and door face. Only the
|
||||
# redundant floor plane is removed because the warehouse deck is its floor.
|
||||
write_variant(FLOOR_1_TARGET, {"Floor"})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
57
scripts/send_ride_goal.py
Executable file
57
scripts/send_ride_goal.py
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Send one simulated floor-to-floor ride action."""
|
||||
|
||||
import sys
|
||||
|
||||
import actionlib
|
||||
import rospy
|
||||
from two_floor_elevator_sim.msg import SimElevatorRideAction, SimElevatorRideGoal
|
||||
|
||||
|
||||
def feedback(message):
|
||||
rospy.loginfo("elevator=%s floor=%s door=%s boarded=%s",
|
||||
message.state_name, message.current_floor,
|
||||
message.door_state, message.robot_boarded)
|
||||
|
||||
|
||||
def main():
|
||||
rospy.init_node("send_sim_elevator_ride")
|
||||
args = rospy.myargv(argv=sys.argv)[1:]
|
||||
if len(args) not in (2, 3, 6):
|
||||
print("usage: send_ride_goal.py FROM_FLOOR TO_FLOOR [TIMEOUT_SEC [DEST_X DEST_Y DEST_YAW]]")
|
||||
return 2
|
||||
|
||||
goal = SimElevatorRideGoal()
|
||||
goal.elevator_id = rospy.get_param("~elevator_id", "sim_elevator")
|
||||
goal.from_floor = args[0]
|
||||
goal.to_floor = args[1]
|
||||
goal.timeout = float(args[2]) if len(args) >= 3 else 180.0
|
||||
if len(args) == 6:
|
||||
goal.navigate_to_destination = True
|
||||
goal.destination_x = float(args[3])
|
||||
goal.destination_y = float(args[4])
|
||||
goal.destination_yaw = float(args[5])
|
||||
|
||||
client = actionlib.SimpleActionClient("/sim_elevator/ride", SimElevatorRideAction)
|
||||
if not client.wait_for_server(rospy.Duration(15.0)):
|
||||
rospy.logerr("action server /sim_elevator/ride is unavailable")
|
||||
return 1
|
||||
client.send_goal(goal, feedback_cb=feedback)
|
||||
finished = client.wait_for_result(rospy.Duration(goal.timeout + 20.0))
|
||||
if not finished:
|
||||
client.cancel_goal()
|
||||
rospy.logerr("ride action timed out in the client")
|
||||
return 1
|
||||
result = client.get_result()
|
||||
if result is None:
|
||||
rospy.logerr("ride ended without a result")
|
||||
return 1
|
||||
if not result.success:
|
||||
rospy.logerr("ride failed (%s): %s", result.error_code, result.message)
|
||||
return 1
|
||||
rospy.loginfo("ride complete at %s: %s", result.reached_floor, result.message)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user