"""Small objects to pick up, shared by the generated scenes (tools/make_kitchen.py, tools/make_tabletop.py). The same shapes, masses and material names in every scene, so the page's renderers style them alike (src/render/materials.js) and the skills grasp them alike. Each function returns the MJCF lines of one free body standing (or lying) on a surface at height `z`, turned `yaw` radians about the vertical. """ import math # Round objects get rolling friction (condim 6): without it a sphere set rolling by the smallest # bounce keeps going. ROUND = 'condim="6" friction="1.2 0.02 0.002"' FLAT = 'condim="4" friction="1.2 0.05 0.01"' MATERIALS = { "apple": "0.75 0.1 0.08 1", "orange": "0.95 0.5 0.08 1", "cube": "0.95 0.78 0.1 1", "can": "0.8 0.1 0.15 1", "mug": "0.2 0.45 0.75 1", "bowl": "0.95 0.95 0.93 1", "plate": "0.97 0.97 0.95 1", "banana": "0.96 0.85 0.3 1", "cup": "0.3 0.7 0.5 1", "bottle": "0.15 0.45 0.3 1", "book": "0.6 0.15 0.2 1", "yogurt": "0.95 0.95 0.98 1", "juice_box": "0.95 0.55 0.1 1", "can_2": "0.15 0.4 0.8 1", "lemon": "0.98 0.88 0.25 1", } def f(*v: float) -> str: return " ".join(f"{x:.4g}" for x in v) def body(name: str, pos, geoms: list[str], mass: float, yaw: float = 0.0, shares: list[float] | None = None) -> list[str]: """A free body; its mass split among the geoms equally, or by `shares`.""" turn = f' quat="{f(math.cos(yaw / 2), 0, 0, math.sin(yaw / 2))}"' if yaw else "" lines = [f' ', " "] shares = shares or [1 / len(geoms)] * len(geoms) for g, share in zip(geoms, shares): lines.append(f' {g.replace("/>", f" mass=\"{mass * share:.4g}\" contype=\"1\" conaffinity=\"1\"/>")}') lines.append(" ") return lines def apple(x, y, z, yaw=0.0, name="apple"): return body(name, (x, y, z + 0.025), [f''], 0.08, yaw) def orange(x, y, z, yaw=0.0, name="orange"): return body(name, (x, y, z + 0.024), [f''], 0.07, yaw) def cube(x, y, z, yaw=0.0, name="cube"): return body(name, (x, y, z + 0.02), [f''], 0.04, yaw) def can(x, y, z, yaw=0.0, name="can", material="can"): return body(name, (x, y, z + 0.045), [f''], 0.06, yaw) def lemon(x, y, z, yaw=0.0, name="lemon"): return body(name, (x, y, z + 0.022), [f''], 0.06, yaw) def mug(x, y, z, yaw=0.0, name="mug"): """A mug (9.5 cm tall) with its handle toward `yaw`: 5.9 cm across at most, handle and all, so the open gripper's fingers clear it whichever way it stands.""" return body(name, (x, y, z + 0.0475), [ f'', f'', ], 0.08, yaw, shares=[0.93, 0.07]) # the handle is a small part of its weight def bowl(x, y, z, yaw=0.0, name="bowl"): """A bowl to put things in: a base and a ring of ten wall segments; too wide to pick up.""" ring = [] for k in range(10): a = 2 * math.pi * k / 10 ring.append(f'') return body(name, (x, y, z + 0.003), ['', *ring], 0.3, yaw) def plate(x, y, z, yaw=0.0, name="plate"): """A plate to put things on; too wide to pick up.""" return body(name, (x, y, z + 0.01), [''], 0.25, yaw) def banana(x, y, z, yaw=0.0, name="banana"): """A banana lying along `yaw`.""" return body(name, (x, y, z + 0.017), [f''], 0.1, yaw) def cup(x, y, z, yaw=0.0, name="cup"): return body(name, (x, y, z + 0.045), [f''], 0.06, yaw) def bottle(x, y, z, yaw=0.0, name="bottle"): return body(name, (x, y, z + 0.085), [f''], 0.2, yaw) def book(x, y, z, yaw=0.0, name="book"): return body(name, (x, y, z + 0.012), [''], 0.3, yaw) def yogurt(x, y, z, yaw=0.0, name="yogurt"): return body(name, (x, y, z + 0.035), [f''], 0.12, yaw) def juice_box(x, y, z, yaw=0.0, name="juice_box"): """A juice carton, its wide side along `yaw`.""" return body(name, (x, y, z + 0.06), [f''], 0.2, yaw)