hylo.manip.tools¶
Package: hylo-manip · Core contracts
tools ¶
The Tools facade (RFC-0006 part 2): the verbs a program uses as robot. Stateless: the program keeps its own
list of objects and of what each hand holds; every verb reads the robot afresh. The implementations live in the
modules beside it (kinematics, collision, planning, perception, grasping); api_reference(tools) renders the verbs'
docstrings as the reference a code-writing model reads.
Verb
module-attribute
¶
VERBS
module-attribute
¶
VERBS = ('status', 'look', 'find', 'table', 'objects', 'box', 'fit', 'grasps', 'hand_grasps', 'dex_grasps', 'grasp_at', 'place_at', 'hand_points', 'retarget', 'Goal', 'plan', 'why', 'run', 'together', 'holding', 'carried', 'show')
EXAMPLE
module-attribute
¶
EXAMPLE = 'view = robot.look(); table = robot.table(view)\nobj = robot.objects(view, robot.find(view, "red block"), table)[0]\nbox = robot.box(obj.points, table)\nplan = robot.plan(robot.grasps(obj.points, table, scene=view.points), table, view.points)\nif plan is None: print(robot.why())\nelse: out = robot.run(plan); print(out["tcp_error"], robot.holding())\nup = out["tcp"]["arm"].copy(); up[2, 3] += 0.10\nrobot.run(robot.plan(robot.Goal("lift", tcp=up), table, view.points))\nobj_in_tcp = np.linalg.inv(plan.goal.tcp) @ box.pose\nview = robot.look() # rests on whatever is under (0.5, 0.2): table, plate, block\ngoal = robot.place_at(obj_in_tcp, box, xy=(0.5, 0.2), yaw=0.0, table=table, hover=0.01, scene=view.points)\nrobot.run(robot.plan(goal, table, view.points))'
TWO_ARM_EXAMPLE
module-attribute
¶
TWO_ARM_EXAMPLE = 'view = robot.look(); table = robot.table(view)\na = robot.objects(view, robot.find(view, "red block"), table)[0]\nb = robot.objects(view, robot.find(view, "blue block"), table)[0]\npl = robot.plan(robot.grasps(a.points, table, scene=view.points, arm="left"), table, view.points)\npr = robot.plan(robot.grasps(b.points, table, scene=view.points, arm="right"), table, view.points)\nout = robot.run({"left": pl, "right": pr}) # both arms at once; out["error"] if they would touch\nprint(out.get("error"), robot.holding(arm="left"), robot.holding(arm="right"))\nst = robot.status(); ups = {}\nfor arm in ("left", "right"):\n t = st["tcp"][arm].copy(); t[2, 3] += 0.10\n ups[arm] = robot.plan(robot.Goal("lift", arm, tcp=t), table)\nrobot.run(ups, sync=True) # start and stop together, TCPs in step'
Box
dataclass
¶
Oriented box: center (3,), size (3,) = length along yaw >= width, height; yaw in (-pi/2, pi/2] about +z;
bottom z. box.pose is the 4x4 object frame (origin at center, x along length, z up).
CameraView
dataclass
¶
CameraView(rgb: ndarray, depth: ndarray | None, K: ndarray | None, T_world_cam: ndarray | None, seg: ndarray | None = None)
One camera: rgb (H, W, 3) uint8; depth (H, W) metres or None; K (3, 3); T_world_cam (4, 4) in the OpenCV optical frame; seg (H, W) int32 instance ids when the environment gives segmentation.
Detection
dataclass
¶
Fit
dataclass
¶
Goal
dataclass
¶
Goal(verb: Verb, arm: str | None = None, tcp: ndarray | None = None, pre: ndarray | None = None, hand_before: Sequence[float] | None = None, hand: Sequence[float] | None = None, joints: ndarray | None = None, rank: float = 0.0, free: Literal['x', 'z'] | None = None, attached: ndarray | None = None)
One motion the planner may choose. verb: grasp, place, reach, lift, push, press, retreat, home. arm: arm name
(None: the robot's only arm).
tcp: (4, 4) TCP pose to end at. pre: (4, 4) approach pose: the planner reaches pre around obstacles, then moves
in a straight line to tcp (that line is checked against the table and the robot only, not observed points, so it
may touch the object). Without pre, verbs lift, retreat, push and press move in a straight line from the current
TCP; other verbs plan a collision-free joint path to tcp. joints: a joint-space goal instead of tcp (e.g.
home). hand_before: hand command while moving (None: keep the current one). hand: hand command at the end, held
until the hand settles (None: no change). rank: lower is tried first among goals passed together. free: "x" or "z"
lets the planner rotate freely about that TCP axis (e.g. "x" for a top-down approach to a round object).
attached: (N, 3) points of a held object in the TCP frame: they move with the hand and are checked against the
table and observed points like the hand itself (place_at fills it); observed points of the object where it is
now are ignored.
Mask
dataclass
¶
An instance mask in one camera: label (the text label it answers), camera, mask (H, W) bool, score in [0, 1] (1: exact label match), instance (the environment's instance id, when known; label: view.segments[instance]).
Plan
dataclass
¶
Plan(goal: Goal, actions: ndarray, start_q: dict[str, ndarray], info: dict[str, Any] = dict(), path: dict[str, list] = dict())
A timed motion: goal (the one chosen; several arms: the first, all in info["goals"]), actions (T, action_dim) joint targets at control rate, start_q {arm: q} it was planned from (run refuses if the robot moved away), info (ik residual, path length, duration, method), path {arm: joint waypoints} before timing.
Table
dataclass
¶
View
dataclass
¶
View(cams: dict[str, CameraView], points: ndarray, segments: dict[int, str] = dict(), step: int = 0)
One observation: cams {name: CameraView}; points (N, 3) world points fused from every depth camera (voxel-downsampled, robot included); segments {instance id: label} when given; step at which it was taken.
Tools ¶
Tools(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)
robot in programs. executor moves the robot; segmenter answers find (default: the environment's
segmentation when the observation has it, else colour names); show collects images for the model. max_vel
and max_acc (per joint or scalar, rad/s and rad/s^2) bound planned motions; seed makes planning repeatable.
config
instance-attribute
¶
status ¶
Robot and episode now: {"step", "max_steps", "instruction", "ended", "q": {arm: (n,) joint positions}, "hand": {arm: measured hand state, 0 closed .. 1 open}, "tcp": {arm: (4, 4) TCP pose in the world}}.
look ¶
The latest observation: per-camera RGB, depth, intrinsics, pose and segmentation (view.cams), fused world
points of every depth camera (view.points, 5 mm voxels; includes table and robot), view.segments.
find ¶
Instance masks for text labels (one Mask per instance per camera). With environment segmentation a label matches segment labels with the same content words (score 1), else those sharing the most words (score = word overlap); with the colour segmenter only the colour word counts. Empty list: nothing matched.
table ¶
The support plane from view.points by RANSAC (near-horizontal planes only; near
RobotSpec.table_height when given): height, normal, xy extent of its inliers.
objects ¶
Per label (and instance when known): the masked depth as world points, table points and outliers removed (flat markings on the table, e.g. zones, keep their points at table height), cameras merged, split into separate 3D clusters (one Detection each, largest first).
box ¶
Oriented box around object points: minimum-area xy rectangle (size[0] >= size[1], yaw in (-pi/2, pi/2]),
top from the points, bottom at the table when given (hidden sides are filled down to it). box.pose: 4x4.
fit ¶
Rigid ICP of a known shape (model points, its own frame) onto observed world points; partial views fit.
Without init it tries 12 yaws about +z from the centroids. fit.T maps model to world.
grasps ¶
grasps(points: ndarray, table: Table, scene: ndarray | None = None, arm: str | None = None) -> list[Goal]
Ranked grasp goals (best first) for a parallel hand from an object's points: top-down across the narrow
side, across the long side if it fits, side grasps from the robot's side for tall objects. TCP depth is up
to 3 cm below the top (half the height if shorter); width must fit the open hand; candidates whose open hand
(at the goal or the 10 cm pre-pose) hits the table, the object or scene points are dropped. Each Goal has
pre, hand_before=open, hand=closed. Empty: no grasp fits. arm: which arm (None: the only one).
grasp_at ¶
A grasp goal at a TCP pose you chose: pre-pose 10 cm back along the TCP's +x (approach), hand opens
before moving and closes (or goes to hand) at tcp.
hand_grasps ¶
hand_grasps(points: ndarray, table: Table, kind: str = 'power', arm: str | None = None) -> list[Goal]
Dexterous hand: top-down grasp goals, TCP at the object's mid height, closing axis across its box faces
(four directions; first the one nearest the arm base frame's +x, e.g. a humanoid's forward: thumb on the
near side, fingers on the far side).
Opens to HandSpec.open on the way, closes to preset kind.
dex_grasps ¶
dex_grasps(points: ndarray, table: Table, hand: str | None = None, scene: ndarray | None = None, arm: str | None = None, mesh: tuple[ndarray, ndarray] | None = None, top: int = 8) -> list[Goal]
Multi-finger grasp goals (best first) for a dexterous hand from an object's points (or mesh = (V, F)):
hand poses sampled around the object (approach directions times rolls, none from below the table), the open
hand slid in until it touches, each finger closed until it touches, scored by the friction-cone wrench hull
(force closure), the force needed to hold the object against gravity, penetration and fingers in contact,
then refined by a short search over the pose. hand: closing style, "power" (all fingers wrap, palm may
touch), "pinch" (the pinch preset) or None for both. Approaches from the arm's side and from above rank
higher. Each Goal: pre 10 cm back along the approach with hand_before = the open pre-shape, tcp, hand = a
squeeze command past the contact angles. Empty: no grasp found. arm: which arm (None: the only one).
retarget ¶
retarget(keypoints: ndarray, arm: str | None = None, valid: ndarray | None = None, side: str | None = None, scale: float | None = None) -> dict[str, Any]
Human hand keypoints (T, 21, 3) in the MediaPipe layout (wrist 0, thumb 1-4, index 5-8, middle 9-12,
ring 13-16, little 17-20; metres, world frame) -> this arm's hand: {"hand": (T, n) finger commands,
"tcp": (T, 4, 4) TCP poses that put the robot palm where the human palm is, "ee": (T, 4, 4),
"tip_error_mm": (T,) fingertip error per frame, "summary": {...}}. Fingertip and thumb-to-finger vectors
are matched (scaled to the robot hand's size; scale overrides it) within joint limits, smooth across
frames. side: "left"/"right" human hand (a mismatch mirrors it); valid: frames with keypoints.
hand_points ¶
Hand surface points (N, 3) in the TCP frame at command hand (a preset name; None: open). [:, 0].max():
how far the hand reaches past the TCP along +x (e.g. to push a button with it).
place_at ¶
place_at(obj_in_tcp: ndarray, obj_points: ndarray | Box, xy: Sequence[float], yaw: float | None = None, table: Table | None = None, hover: float = 0.03, scene: ndarray | None = None, support: float | None = None, arm: str | None = None) -> Goal
Where the TCP must go so the held object rests at xy. obj_in_tcp: the object frame in the TCP frame at
grasp time (inv(grasp_tcp) @ box.pose). obj_points: the object's Box (its pose is the object frame; best:
the hidden bottom counts) or its points in that frame (apply inv(box.pose) to its world points). The object
keeps its current tilt; its yaw becomes yaw (world, None: unchanged); its lowest point ends hover
metres above the support: support (a height), else the top of scene points (e.g. view.points; robot,
table and the held object ignored) under the object's footprint at xy (a plate, a block to stack on),
else the table (table, else the robot's table height). Pre-pose 10 cm above; hand opens at the goal; the
object rides along as attached geometry (checked against the table and observed points).
plan ¶
plan(goals: Goal | Sequence[Goal], table: Table | None = None, scene: ndarray | None = None) -> Plan | None
The first reachable goal by rank: IK (seeds: current joints, home, random), a collision-free joint path to
pre (or tcp) avoiding the table and scene points (pass view.points: the robot, the table and points
within 8 cm of the hand are ignored), the straight approach to tcp, then the final hand command. Timed to
control steps within velocity and acceleration limits; other arms hold. None: no goal reachable
(robot.why() says why). Deterministic for a given seed.
hold ¶
(steps, action_dim) joint targets that keep every arm where it is now; hand {arm: command} sets those
hands (others keep their last command). Run it with run_actions (a gripper command, a pause).
run_actions ¶
Execute raw joint targets (from hold) through the kernel and the shield; remembers the hand commands.
reach ¶
Can the arm put its TCP at tcp (4x4)? IK only (no collision check, no path): {"ok", "pos_err" (m),
"rot_err" (rad), "q"}.
together ¶
One plan moving several arms at once: each arm follows its own plan from the same moment (a shorter one then holds its last command). sync=True re-times the arms to start and stop together with their TCPs in step (both hands on one object: plan each arm's motion, e.g. two "lift" goals, then together(..., sync=True)). Every step is checked for arms touching each other or the robot; None when they would (robot.why()).
run ¶
Execute a plan (through the kernel and the safety shield) and wait. Returns {"steps", "ended", "success", "reason", "q", "hand", "tcp": {arm: 4x4}, "tcp_error": {"pos": m, "rot": rad} vs the goal's tcp, None for a joints goal}. Refuses ("error", steps 0) if the robot moved more than 0.05 rad since planning: plan again. Several arms at once: run({"left": plan_l, "right": plan_r}, sync=...) runs together(...) first (refused with "error" when the arms would touch); tcp_error is then {arm: ...}.
holding ¶
Parallel hand: True when the measured pads stopped between open and closed after a close command (something is between them); False when open, opening or fully closed. Dexterous hand: True when, after a command nearer closed than open, at least two finger joints stopped more than 0.12 rad short of it.
carried ¶
carried(view: View, points: ndarray, tcp_before: ndarray, tcp_now: ndarray, table: Table) -> dict[str, Any]
Did the object move with the hand? points: its world points seen before the motion; view: a look()
after it. Returns {"carried": bool, "match": fraction of rigidly-moved points seen in the view, "left_behind":
fraction still seen at the old place, "lifted": TCP z change (m), "offset": (3,) mean observed - expected}.
show ¶
Attach an image (an RGB array, or a View: its cameras side by side) to your next turn, with a note.
verbs_for ¶
The verbs the reference lists for a robot: the multi-finger verbs only when one of its hands is dexterous (all verbs without a robot).
api_reference ¶
The toolkit's API reference for a code-writing model: the robot (from the spec), each verb's signature and docstring, and the data types.