Skip to content

hylo.manip

Package: hylo-manip · Core contracts

manip

Manipulation toolkit for tool-using agents (RFC-0006 part 2): stateless perception, kinematics, grasping and motion-planning tools over one robot described by hylo.core.robot.RobotSpec. Programs see them as robot.

META module-attribute

META = {'contracts': {}, 'maturity': 'unverified', 'plugins': {}}

Executor

Bases: Protocol

observation

observation() -> Observation

The latest observation (after the last executed step).

run

run(actions: ndarray) -> dict[str, Any]

Execute (T, action_dim) joint-position targets, one per control step, and block until done or the episode ended. Returns {"steps": executed, "ended": bool, "success": bool | None, "reason": str | None}.

status

status() -> dict[str, Any]

{"step": int, "max_steps": int, "instruction": str | None, "ended": bool}.

ColourSegmenter

ColourSegmenter(min_pixels: int = 30)

Named colours in HSV (red, orange, brown, yellow, green, cyan, blue, purple, pink, magenta, white, black, gray): a label's colour word selects pixels, split into connected components (one Mask each, score 1.0). Other words of the label are ignored, so "red block" and "red bowl" both match every red region.

min_pixels instance-attribute

min_pixels = min_pixels

segment

segment(view: View, labels: Sequence[str]) -> list[Mask]

EnvSegmenter

EnvSegmenter(min_pixels: int = 15)

The environment's instance segmentation (<cam>.seg with extra["segments"] labels). A query matches the segment labels with equal content words; failing that, those sharing the most words (score = overlap).

min_pixels instance-attribute

min_pixels = min_pixels

segment

segment(view: View, labels: Sequence[str]) -> list[Mask]

MarkSegmenter

MarkSegmenter(choose: Callable[[ndarray, list[ndarray], str], list[int]], propose: Callable[[View], dict[str, list[ndarray]]] | None = None, min_pixels: int = 20)

A vision-language model picks among numbered regions (set-of-marks). propose(view) gives candidate regions per camera ({camera: [mask, ...]}; default: connected regions standing above the table in depth); choose(rgb, regions, label) is the model adapter: it draws the numbers, asks the model and returns the chosen indices.

depth_regions

depth_regions(view: View) -> dict[str, list[np.ndarray]]

segment

segment(view: View, labels: Sequence[str]) -> list[Mask]

Segmenter

Bases: Protocol

segment

segment(view: View, labels: Sequence[str]) -> list[Mask]

Instance masks answering each text label.

Box dataclass

Box(center: ndarray, size: ndarray, yaw: float, bottom: float)

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).

center instance-attribute

center: ndarray

size instance-attribute

size: ndarray

yaw instance-attribute

yaw: float

bottom instance-attribute

bottom: float

pose property

pose: ndarray

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.

rgb instance-attribute

rgb: ndarray

depth instance-attribute

depth: ndarray | None

K instance-attribute

K: ndarray | None

T_world_cam instance-attribute

T_world_cam: ndarray | None

seg class-attribute instance-attribute

seg: ndarray | None = None

Detection dataclass

Detection(label: str, score: float, points: ndarray)

One object: label, score, points (N, 3) world points fused across cameras (table and outliers removed).

label instance-attribute

label: str

score instance-attribute

score: float

points instance-attribute

points: ndarray

Fit dataclass

Fit(T: ndarray, rmse: float, inliers: float)

Rigid registration: T (4, 4) maps model points onto observed ones; rmse (m) over inliers; inliers: fraction of observed points within the tolerance of the moved model.

T instance-attribute

T: ndarray

rmse instance-attribute

rmse: float

inliers instance-attribute

inliers: float

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.

verb instance-attribute

verb: Verb

arm class-attribute instance-attribute

arm: str | None = None

tcp class-attribute instance-attribute

tcp: ndarray | None = None

pre class-attribute instance-attribute

pre: ndarray | None = None

hand_before class-attribute instance-attribute

hand_before: Sequence[float] | None = None

hand class-attribute instance-attribute

hand: Sequence[float] | None = None

joints class-attribute instance-attribute

joints: ndarray | None = None

rank class-attribute instance-attribute

rank: float = 0.0

free class-attribute instance-attribute

free: Literal['x', 'z'] | None = None

attached class-attribute instance-attribute

attached: ndarray | None = None

Mask dataclass

Mask(label: str, camera: str, mask: ndarray, score: float = 1.0, instance: int | None = None)

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]).

label instance-attribute

label: str

camera instance-attribute

camera: str

mask instance-attribute

mask: ndarray

score class-attribute instance-attribute

score: float = 1.0

instance class-attribute instance-attribute

instance: int | None = None

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.

goal instance-attribute

goal: Goal

actions instance-attribute

actions: ndarray

start_q instance-attribute

start_q: dict[str, ndarray]

info class-attribute instance-attribute

info: dict[str, Any] = field(default_factory=dict)

path class-attribute instance-attribute

path: dict[str, list] = field(default_factory=dict)

Table dataclass

Table(height: float, normal: ndarray, extent: ndarray | None = None)

The support plane: height (z), normal (3,) (+z for a level table), extent [[xmin, xmax], [ymin, ymax]].

height instance-attribute

height: float

normal instance-attribute

normal: ndarray

extent class-attribute instance-attribute

extent: ndarray | None = None

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

config = PlannerConfig(control_hz=control_hz, max_vel=max_vel, max_acc=max_acc, seed=seed)

Goal class-attribute instance-attribute

Goal = Goal

status

status() -> dict[str, Any]

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

look() -> View

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

find(view: View, labels: str | Sequence[str]) -> list[Mask]

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

table(view: View) -> 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

objects(view: View, masks: Sequence[Mask], table: Table) -> list[Detection]

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

box(points: ndarray, table: Table | None = None) -> 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

fit(model_points: ndarray, observed: ndarray, init: ndarray | None = None) -> 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

grasp_at(tcp: ndarray, hand: Sequence[float] | None = None, arm: str | None = None) -> Goal

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_points(hand: Sequence[float] | str | None = None, arm: str | None = None) -> np.ndarray

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.

why

why() -> str

Why the last plan() returned None (empty after a success).

hold

hold(steps: int, hand: dict[str, Sequence[float]] | None = None) -> np.ndarray

(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

run_actions(actions: ndarray) -> dict[str, Any]

Execute raw joint targets (from hold) through the kernel and the shield; remembers the hand commands.

reach

reach(tcp: ndarray, arm: str | None = None, free: str | None = None) -> dict[str, Any]

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

together(plans: dict[str, Plan] | Sequence[Plan], sync: bool = False) -> Plan | None

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

run(plan: Plan | dict[str, Plan] | Sequence[Plan], sync: bool = False) -> dict[str, Any]

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

holding(arm: str | None = None) -> bool | None

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

show(image: View | ndarray, note: str = '') -> None

Attach an image (an RGB array, or a View: its cameras side by side) to your next turn, with a note.

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.

cams instance-attribute

cams: dict[str, CameraView]

points instance-attribute

points: ndarray

segments class-attribute instance-attribute

segments: dict[int, str] = field(default_factory=dict)

step class-attribute instance-attribute

step: int = 0

api_reference

api_reference(tools: Tools | None = None) -> str

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.