"""A domestic worktable and camera rig, authored in metres for the chess scene.
The tabletop stays at z=0. Small cosmetic details have no contacts; the table,
stand, board and tray have physical support geometry. No training postprocessing.
"""
from __future__ import annotations
import itertools
import math
TABLE_CENTER = (0.18, 0, -0.02)
TABLE_HALF = (0.60, 0.40, 0.02)
FLOOR_Z = -0.74
OVERHEAD_POS = (0.42, 0, 0.56)
ROVER_CAMERA_POS = (0.105, -0.14, 0.18)
ROVER_CAMERA_FOV = 90
MAST_XY = (-0.16, 0.23)
# Deck placeholder footprint (x from the arm axis). The front stops at the board's near
# edge: at 0.11 the board border ran 12 mm under the deck, and diagonal grasps on rank 8
# put a finger over the deck. The real rover body must not reach further forward than
# this below finger height.
DECK_BACK = -0.110
DECK_FRONT = 0.098
DECK_HALF_Y = 0.090
DECK_CX = (DECK_FRONT + DECK_BACK) / 2
DECK_HX = (DECK_FRONT - DECK_BACK) / 2
def numbers(values):
return " ".join(f"{x:.8g}" for x in values)
def bevel_asset(name, half, bevel, uv=False):
vertices = []
for signs in itertools.product((-1, 1), repeat=3):
for axis in range(3):
vertices.extend(signs[i] * (half[i] if i == axis else half[i] - bevel) for i in range(3))
coords = []
for i in range(0, len(vertices), 3):
coords.extend((vertices[i] / (2 * half[0]) + 0.5, vertices[i+1] / (2 * half[1]) + 0.5))
texture = f' texcoord="{numbers(coords)}"' if uv else ''
return f''
def box(name, pos, half, material, cosmetic=True, extra=""):
contact = 'contype="0" conaffinity="0" group="1"' if cosmetic else ''
return (f'')
def rod(name, start, end, radius, material="rubber", cosmetic=True):
contact = 'contype="0" conaffinity="0" group="1"' if cosmetic else ''
return (f'')
def mesh_geom(name, mesh, pos, material):
return (f'')
def screw(name, x, y, z, radius=0.0022):
return (f''
+ box(name + "_slot", (x, y, z + 0.00061), (radius * 0.65, radius * 0.13, 0.000025), "rubber"))
def assets():
return "\n".join([
bevel_asset("tabletop_mesh", TABLE_HALF, 0.003, uv=True),
bevel_asset("stand_case_mesh", (DECK_HX - 0.002, DECK_HALF_Y - 0.002, 0.024), 0.002),
bevel_asset("stand_plate_mesh", (DECK_HX, DECK_HALF_Y, 0.003), 0.001),
bevel_asset("camera_case_mesh", (0.024, 0.018, 0.011), 0.002),
bevel_asset("power_supply_mesh", (0.038, 0.022, 0.014), 0.002),
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
# Floors the phase 2 randomiser can put under the table (besides the wood textures).
'',
'',
'',
# Everyday clutter (colours set per episode).
'',
'',
'',
'',
'',
'',
'',
'',
'',
])
def room():
# The table is one static body so phase 2 can slide it under the robot and board
# (the board then sometimes sits near an edge or corner, with the floor in view).
table = [
# Same table contact height as the previous infinite plane, finite footprint.
'',
mesh_geom("table_surface", "tabletop_mesh", TABLE_CENTER, "table_mat"),
box("table_apron_front", (0.18, -0.33, -0.065), (0.54, 0.012, 0.025), "case_mat"),
box("table_apron_back", (0.18, 0.33, -0.065), (0.54, 0.012, 0.025), "case_mat"),
]
for i, (x, y) in enumerate(itertools.product((-0.34, 0.70), (-0.33, 0.33))):
table.append(box(f"table_leg_{i}", (x, y, -0.385), (0.018, 0.018, 0.345), "case_mat", False))
table.append(box(f"table_foot_{i}", (x, y, -0.733), (0.019, 0.019, 0.007), "rubber", False))
geoms = [
'
' + "\n".join(table) + '',
f'',
box("back_wall", (-0.78, 0.0, 0.5), (0.04, 1.8, 1.24), "wall_mat", False),
box("side_wall", (0.65, 1.2, 0.5), (1.43, 0.04, 1.24), "wall_mat", False),
box("back_skirting", (-0.735, 0, FLOOR_Z + 0.045), (0.006, 1.16, 0.045), "trim_mat"),
box("side_skirting", (0.68, 1.153, FLOOR_Z + 0.045), (1.42, 0.006, 0.045), "trim_mat"),
]
return "\n".join(geoms)
def stand(deck_height, rover_camera_axes):
if not math.isclose(deck_height, 0.06):
raise ValueError("Stand enclosure is designed for a 60 mm deck; update its geometry when changing height.")
parts = [
f'',
mesh_geom("stand_enclosure", "stand_case_mesh", (DECK_CX, 0, 0.030), "case_mat"),
mesh_geom("stand_top", "stand_plate_mesh", (DECK_CX, 0, 0.057), "anodized"),
box("stand_bottom_seam", (DECK_CX, 0, 0.007), (DECK_HX - 0.003, DECK_HALF_Y - 0.003, 0.001), "rubber"),
]
feet_x = (DECK_CX - DECK_HX + 0.017, DECK_CX + DECK_HX - 0.017)
for i, (x, y) in enumerate(itertools.product(feet_x, (-0.073, 0.073))):
parts.append(f'')
parts.append(screw(f"stand_screw_{i}", x, y, 0.0603))
for i in range(9):
parts.append(box(f"case_vent_{i}", (-0.060 + 0.014 * i, -0.0881, 0.030), (0.003, 0.00008, 0.009), "rubber"))
parts.append(box("power_socket", (-0.1082, -0.023, 0.027), (0.0002, 0.008, 0.005), "rubber"))
parts.append(rover_camera(rover_camera_axes))
return '' + "\n".join(parts) + ''
def rover_camera(xyaxes):
"""Self-contained camera stalk, parented to the rover deck rather than the room."""
rx, ry, rz, ux, uy, uz = map(float, xyaxes.split())
back = (ry*uz-rz*uy, rz*ux-rx*uz, rx*uy-ry*ux)
housing = tuple(p + 0.026*b for p, b in zip(ROVER_CAMERA_POS, back))
stalk_tip = (housing[0], housing[1], housing[2] - 0.016)
parts = [
'',
rod("rover_camera_stalk", (0.084, -0.073, 0.066), stalk_tip,
0.0045, "anodized", cosmetic=False),
rod("rover_camera_bracket", stalk_tip, housing,
0.004, "anodized", cosmetic=False),
rod("rover_camera_cable", (0.078, -0.078, 0.061),
(stalk_tip[0] - 0.005, stalk_tip[1] - 0.005, stalk_tip[2]), 0.0015),
rod("rover_camera_cable_top", (stalk_tip[0] - 0.005, stalk_tip[1] - 0.005, stalk_tip[2]), housing, 0.0015),
]
parts.append(f'''
{mesh_geom("rover_camera_housing", "camera_case_mesh", (0, 0, 0.026), "case_mat")}
''')
return "\n".join(parts)
def camera_rig(camera_pos, xyaxes):
mx, my = MAST_XY
x, y, z = camera_pos
parts = [
f'',
box("mast_column", (mx, my, 0.311), (0.010, 0.010, 0.297), "anodized", False),
rod("camera_boom", (mx, my, 0.603), (x, y, 0.603), 0.008, "anodized", False),
rod("camera_drop_bracket", (x, y, 0.603), (x, y, z + 0.025), 0.005, "steel"),
mesh_geom("overhead_housing", "camera_case_mesh", (x, y, z + 0.022), "case_mat"),
f'',
f'',
f'',
]
points = [(x + 0.020, y, z + 0.026), (x + 0.03, y, 0.618), (mx, my + 0.013, 0.618),
(mx, my + 0.013, 0.018), (mx - 0.035, my + 0.04, 0.003), (-0.30, 0.29, 0.003)]
parts.extend(rod(f"camera_usb_{i}", a, b, 0.0016) for i, (a, b) in enumerate(zip(points, points[1:])))
return '' + "\n".join(parts) + ''
def cables():
parts = [mesh_geom("power_brick", "power_supply_mesh", (-0.265, -0.12, 0.014), "rubber")]
points = [(-0.108, -0.023, 0.027), (-0.13, -0.025, 0.025), (-0.155, -0.05, 0.003),
(-0.178, -0.1, 0.003), (-0.205, -0.12, 0.007), (-0.227, -0.12, 0.012)]
parts.extend(rod(f"arm_power_{i}", a, b, 0.002) for i, (a, b) in enumerate(zip(points, points[1:])))
points = [(-0.303, -0.12, 0.012), (-0.34, -0.14, 0.003), (-0.39, -0.15, 0.003), (-0.422, -0.15, -0.01), (-0.44, -0.15, -0.40)]
parts.extend(rod(f"mains_cable_{i}", a, b, 0.0025) for i, (a, b) in enumerate(zip(points, points[1:])))
return "\n".join(parts)
def board_details(half, border, top):
# Thin contrasting marquetry surrounds the 64 squares, clear of their contacts.
parts = []
for sign in (-1, 1):
parts.append(box(f"board_frame_x_{sign}", (sign * (half + border/2), 0, top/2),
(border/2, half + border, top/2), "border_mat", False))
parts.append(box(f"board_frame_y_{sign}", (0, sign * (half + border/2), top/2),
(half, border/2, top/2), "border_mat", False))
parts.append(box(f"inlay_x_{sign}", (sign * (half + 0.0015), 0, top + 0.000015),
(0.00035, half + 0.00185, 0.000015), "inlay_mat"))
parts.append(box(f"inlay_y_{sign}", (0, sign * (half + 0.0015), top + 0.000015),
(half + 0.00185, 0.00035, 0.000015), "inlay_mat"))
return "\n".join(parts)
def tray(hx=0.045, hy=0.035, rim=0.020):
"""Capture tray: 2 mm floor and walls, felt liner, rounded rim at height `rim`.
ChessWorld reads the interior and rim height back from `tray_floor` and `tray_wall_y_1`."""
parts = [
f'',
box("tray_felt", (0, 0, 0.00405), (hx - 0.0025, hy - 0.0025, 0.00005), "felt"),
]
for sign in (-1, 1):
parts.append(f'')
parts.append(f'')
parts.append(rod(f"tray_rim_x_{sign}", (-hx, sign * hy, rim), (hx, sign * hy, rim), 0.0012, "bin_mat"))
parts.append(rod(f"tray_rim_y_{sign}", (sign * hx, -hy, rim), (sign * hx, hy, rim), 0.0012, "bin_mat"))
return "\n".join(parts)
CABLES = 2 # randomised cables lying on the table
CABLE_SEGMENTS = 14
def _hidden(name, kind, material, pos=(0, 0, 0), size=None, extra=""):
size_attr = f' size="{numbers(size)}"' if size is not None else ""
return (f'')
def clutter():
"""Everyday things around the board: a laptop, a phone, a mug, a notebook, a pen and
cables. Visual only, parked out of sight in geom group 5 (not rendered) until the
phase 2 randomiser places a random subset and moves their geoms to group 1."""
import math as _m
t = _m.radians(20) # laptop screen leans back 20 deg (open 110 deg)
screen_pos = (0, 0.108 + 0.105 * _m.sin(t), 0.016 + 0.105 * _m.cos(t))
screen_quat = f"{_m.cos(-t / 2):.6f} {_m.sin(-t / 2):.6f} 0 0"
parts = [
'',
_hidden("laptop_base", "box", "device_mat", (0, 0, 0.008), (0.155, 0.108, 0.008)),
_hidden("laptop_keys", "box", "rubber", (0, -0.015, 0.0162), (0.135, 0.055, 0.0002)),
_hidden("laptop_lid", "box", "device_mat", screen_pos, (0.155, 0.004, 0.105), f'quat="{screen_quat}"'),
_hidden("laptop_display", "box", "lens", (0, screen_pos[1] - 0.0042 * _m.cos(t), screen_pos[2] + 0.0042 * _m.sin(t)),
(0.145, 0.0002, 0.095), f'quat="{screen_quat}"'),
'',
'',
_hidden("phone_body", "box", "device2_mat", (0, 0, 0.004), (0.074, 0.036, 0.004)),
_hidden("phone_screen", "box", "lens", (0, 0, 0.0081), (0.070, 0.033, 0.0001)),
'',
'',
_hidden("mug_body", "cylinder", "mug_mat", (0, 0, 0.048), (0.040, 0.048)),
_hidden("mug_coffee", "cylinder", "rubber", (0, 0, 0.086), (0.036, 0.0005)),
f'',
f'',
f'',
'',
'',
_hidden("notebook_cover", "box", "notebook_mat", (0, 0, 0.007), (0.105, 0.075, 0.007)),
_hidden("notebook_pages", "box", "trim_mat", (0.002, 0, 0.007), (0.104, 0.073, 0.0065)),
'',
'',
f'',
'',
]
for k in range(CABLES):
for i in range(CABLE_SEGMENTS):
parts.append(f'')
return "\n".join(parts)