Skip to content

hylo.codeagents.scene_free_tools

Package: hylo-code-agents · Core contracts

scene_free_tools

The privileged toolkit for free scenes: hylo-manip's Tools plus the simulator's free-form state.

tools: {type: hylo.codeagents.scene_free_tools:PrivilegedFreeTools}     (env mujoco.free_scene, privileged_obs)

robot.scene() returns rigid bodies, cable nodes, flex vertices, joint values and sites; robot.points(name) turns a body, cable or flex into points for the grasping verbs; robot.top_down(xyz, yaw) builds a top-down TCP pose. The reference text (with a one-arm or a two-arm example, by the robot) is prepended to the toolkit's own.

PRIVILEGED_FREE_TOOLS module-attribute

PRIVILEGED_FREE_TOOLS = 'hylo.codeagents.scene_free_tools:PrivilegedFreeTools'

FREE_REFERENCE module-attribute

FREE_REFERENCE = '## Privileged simulator state (this run is flagged privileged)\nThis task was built as a free-form scene; robot.scene() gives the simulator\'s ground truth. Prefer it to perception.\nrobot.scene() -> dict\n    {"bodies": {name: {"pos", "quat", "bounds": (min, max), "top", "free", "mocap", "parent", "label"}},\n     "cables": {prefix: {"nodes": (N, 3) in chain order, "bodies", "radius", "label"}},\n     "flexes": {name: {"vertices": (N, 3), "bodies", "radius", "label"}},\n     "joints": {name: {"type": "hinge" | "slide", "value", "range", "units", "body"}},\n     "sites": {name: (3,)}, "table": {"height", "x", "y"}}; fresh at every call.\nrobot.points(name, spacing=0.006) -> (N, 3) world points of a body, cable or flex (for robot.grasps / robot.box).\nrobot.top_down(xyz, yaw=0.0) -> 4x4 top-down TCP pose at xyz (closing axis at angle yaw about z): for grasp_at.\nrobot.scene_table(height=None) -> Table: the table, or a support plane at `height`.\nThin things (a cable end, a cloth edge): grasp with robot.grasp_at(robot.top_down(p, yaw), arm=...) where p is the\nnode / vertex position but at least 1.7 cm above the surface under it (the fingertips reach about 1.5 cm below the\nTCP, and plan() refuses poses whose fingers would hit the table); yaw across the cable (perpendicular to the line\nbetween neighbouring nodes). Move a held thing with robot.Goal("move", arm,\ntcp=T) through robot.plan(goal, table) (a joint-space path) and check robot.scene() after every motion.\n'

FREE_ONE_ARM_EXAMPLE module-attribute

FREE_ONE_ARM_EXAMPLE = '\nExample (one arm: lift the end of a cable and lay it at a point):\n    s = robot.scene(); table = robot.scene_table()\n    n = s["cables"]["rope"]["nodes"]; end, nxt = n[-1], n[-2]\n    d = end - nxt; yaw = math.atan2(d[1], d[0]) + math.pi / 2\n    p = end.copy(); p[2] = max(p[2], table.height + 0.017)\n    out = robot.run(robot.plan(robot.grasp_at(robot.top_down(p, yaw)), table)); print(out["tcp_error"])\n    up = out["tcp"]["arm"].copy(); up[2, 3] += 0.10\n    robot.run(robot.plan(robot.Goal("move", tcp=up), table))\n    to = robot.top_down([0.1, 0.2, table.height + 0.05], yaw)\n    robot.run(robot.plan(robot.Goal("move", tcp=to, hand=robot.spec.arms[0].hand.open), table))\n    print(robot.scene()["cables"]["rope"]["nodes"][-1])\n'

FREE_TWO_ARM_EXAMPLE module-attribute

FREE_TWO_ARM_EXAMPLE = '\nExample (two arms: take both ends of a cable and lift them together):\n    s = robot.scene(); table = robot.scene_table()\n    n = s["cables"]["rope"]["nodes"]\n    plans = {}\n    for arm, i, j in (("left", 0, 1), ("right", -1, -2)):\n        d = n[i] - n[j]; yaw = math.atan2(d[1], d[0]) + math.pi / 2\n        p = n[i].copy(); p[2] = max(p[2], table.height + 0.017)\n        plans[arm] = robot.plan(robot.grasp_at(robot.top_down(p, yaw), arm=arm), table)\n        if plans[arm] is None: print(arm, robot.why())\n    out = robot.run(plans); print(out.get("error"), out["tcp_error"])\n    st = robot.status(); ups = {}\n    for arm in ("left", "right"):\n        t = st["tcp"][arm].copy(); t[2, 3] += 0.15\n        ups[arm] = robot.plan(robot.Goal("lift", arm, tcp=t), table)\n    out = robot.run(ups, sync=True)\n    print(robot.scene()["cables"]["rope"]["nodes"][[0, -1]])\n'

PrivilegedFreeTools

PrivilegedFreeTools(spec: RobotSpec, executor: Executor, *, segmenter: Any | None = None, control_hz: float = 20.0, show: Callable[[ndarray, str], None] | None = None, max_vel: float | Sequence[float] = 1.0, max_acc: float | Sequence[float] = 2.0, seed: int = 0)

Bases: Tools

The hylo-manip toolkit plus PRIVILEGED free-scene state (the env must run with privileged_obs: true).

privileged class-attribute instance-attribute

privileged = True

scene

scene() -> dict[str, Any]

PRIVILEGED: the scene now, from the simulator: {"bodies": {name: {"pos", "quat", "bounds": (min, max), "top", "free", "mocap", "parent", "label"}}, "cables": {prefix: {"nodes" (N, 3) in chain order, "bodies", "radius", "label"}}, "flexes": {name: {"vertices" (N, 3), "bodies", "radius", "label"}}, "joints": {name: {"type", "value", "range", "units", "body"}}, "sites": {name: (3,)}, "table": {"height", "x", "y"}}.

points

points(name: str, spacing: float = 0.006) -> np.ndarray

PRIVILEGED: (N, 3) world points of a thing for the toolkit's grasping verbs: a body's bounding-box surface, a cable's nodes filled in along the chain (and around its radius), a flex's vertices.

top_down

top_down(xyz: Sequence[float], yaw: float = 0.0) -> np.ndarray

A top-down TCP pose (4x4) at xyz: approach (+x) straight down, closing axis (+y) at angle yaw about world z (0: fingers close along world y). Use with robot.grasp_at / robot.Goal.

scene_table

scene_table(height: float | None = None) -> Table

PRIVILEGED: the table as a Table (height from the simulator), or a support plane at height.

extra_reference

extra_reference() -> str