Skip to content

hylo.manip.dexgrasp

Package: hylo-manip · Core contracts

dexgrasp

Multi-finger grasp planning for any dexterous hand (a HandModel: HandSpec plus its MJCF) on an object given as points or a mesh.

Object: one or more convex parts (the hull of the points, of the mesh, or of each given part), so the signed distance to the object is the smallest of the parts' hull distances and a ray's entry into the object is exact. A partial point cloud seen from above is extruded down to the table first (the hidden underside is solid).

Planning, per candidate hand pose: 1. sample: approach directions (+x of the TCP) over the sphere, minus those from below the table, times rolls about the approach (the +y closing axis); the TCP aims at the object's centre (plus offsets during refinement); 2. approach: the open hand (a rigid point set) slides along the approach until its first point would enter the object or the table (ray-hull entry distances, exact), never past the centre; 3. close: each finger moves from the open command towards the closing command (HandSpec.closed for "power", the "pinch" preset for "pinch") until its links touch the object (a sweep, then bisection per finger); 4. score: contacts are the finger and palm samples within a few millimetres of the surface (one per link, the hull facet's normal); the epsilon measure of their friction-cone wrenches (force closure when positive), the total normal force needed to hold the object against gravity, penetration, how many fingers touch, and an optional preferred approach direction or pose; 5. refine: the best few are perturbed (offset, tilt, roll) for a couple of rounds and re-scored (a short cross-entropy search over the pose; the fingers re-close each time).

plan() returns DexGrasp records, best first; to_goals() turns them into toolkit Goals (pre-pose back along the approach with the hand open, then the hand closing to a squeeze command past the contact angles).

ObjectGeom dataclass

ObjectGeom(planes: list[ndarray], points: ndarray, centre: ndarray, radius: float, mass: float = 0.1, part_spheres: list | None = None)

An object as convex parts (list of facet arrays) with its surface samples.

planes instance-attribute

planes: list[ndarray]

points instance-attribute

points: ndarray

centre instance-attribute

centre: ndarray

radius instance-attribute

radius: float

mass class-attribute instance-attribute

mass: float = 0.1

part_spheres class-attribute instance-attribute

part_spheres: list | None = None

from_parts classmethod

from_parts(parts: Sequence[ndarray], mass: float = 0.1, spacing: float = 0.004) -> 'ObjectGeom'

parts: point sets (world), each one convex part (its hull).

from_points classmethod

from_points(points: ndarray, table_z: float | None = None, mass: float = 0.1) -> 'ObjectGeom'

One convex part from observed points; with a table height the points are extruded down to it.

from_mesh classmethod

from_mesh(V: ndarray, F: ndarray, parts: Sequence[tuple[ndarray, ndarray]] | None = None, mass: float = 0.1, spacing: float = 0.004) -> 'ObjectGeom'

A mesh (its hull), or several convex parts of it (V, F each) for a concave object.

sdf

sdf(P: ndarray, far: float | None = None) -> tuple[np.ndarray, np.ndarray]

Signed distance (negative inside; outside a lower bound of the true distance) and the outward normal of the nearest facet. With far, points farther than radius + far from the centre are not evaluated (their distance is reported as far, normal zero).

entry

entry(P: ndarray, a: ndarray) -> np.ndarray

Per point, the smallest advance s >= 0 along unit direction a at which it enters the object (inf: never).

DexGrasp dataclass

DexGrasp(tcp: ndarray, approach: ndarray, q_open: ndarray, q_contact: ndarray, q_squeeze: ndarray, contacts: ndarray, normals: ndarray, contact_fingers: list[str], epsilon: float, effort: float, penetration: float, score: float, style: str, refined: bool = False, info: dict = dict())

tcp instance-attribute

tcp: ndarray

approach instance-attribute

approach: ndarray

q_open instance-attribute

q_open: ndarray

q_contact instance-attribute

q_contact: ndarray

q_squeeze instance-attribute

q_squeeze: ndarray

contacts instance-attribute

contacts: ndarray

normals instance-attribute

normals: ndarray

contact_fingers instance-attribute

contact_fingers: list[str]

epsilon instance-attribute

epsilon: float

effort instance-attribute

effort: float

penetration instance-attribute

penetration: float

score instance-attribute

score: float

style instance-attribute

style: str

refined class-attribute instance-attribute

refined: bool = False

info class-attribute instance-attribute

info: dict = field(default_factory=dict)

force_closure property

force_closure: bool

PlannerConfig dataclass

PlannerConfig(mu: float = 0.5, cone_edges: int = 8, n_dirs: int = 32, n_rolls: int = 6, min_down: float = -0.25, max_up: float = 0.2, table_clearance: float = 0.004, contact_tol: float = 0.004, pen_tol: float = 0.0015, max_penetration: float = 0.004, sweep: int = 14, squeeze: float = 0.35, pre_dist: float = 0.1, keep: int = 10, refine_top: int = 6, refine_rounds: int = 2, refine_samples: int = 10, offset_sigma: float = 0.008, tilt_sigma: float = 0.15, seed: int = 0)

mu class-attribute instance-attribute

mu: float = 0.5

cone_edges class-attribute instance-attribute

cone_edges: int = 8

n_dirs class-attribute instance-attribute

n_dirs: int = 32

n_rolls class-attribute instance-attribute

n_rolls: int = 6

min_down class-attribute instance-attribute

min_down: float = -0.25

max_up class-attribute instance-attribute

max_up: float = 0.2

table_clearance class-attribute instance-attribute

table_clearance: float = 0.004

contact_tol class-attribute instance-attribute

contact_tol: float = 0.004

pen_tol class-attribute instance-attribute

pen_tol: float = 0.0015

max_penetration class-attribute instance-attribute

max_penetration: float = 0.004

sweep class-attribute instance-attribute

sweep: int = 14

squeeze class-attribute instance-attribute

squeeze: float = 0.35

pre_dist class-attribute instance-attribute

pre_dist: float = 0.1

keep class-attribute instance-attribute

keep: int = 10

refine_top class-attribute instance-attribute

refine_top: int = 6

refine_rounds class-attribute instance-attribute

refine_rounds: int = 2

refine_samples class-attribute instance-attribute

refine_samples: int = 10

offset_sigma class-attribute instance-attribute

offset_sigma: float = 0.008

tilt_sigma class-attribute instance-attribute

tilt_sigma: float = 0.15

seed class-attribute instance-attribute

seed: int = 0

DexGraspPlanner

DexGraspPlanner(hand: HandModel, config: PlannerConfig | None = None)

Grasps of one hand. See the module docstring.

closing_target

closing_target(style: str) -> np.ndarray

evaluate

evaluate(obj: ObjectGeom, R: ndarray, aim: ndarray, table_z: float | None, style: str, q_open: ndarray | None = None, scene: ndarray | None = None, prefer: dict | None = None) -> DexGrasp | None

Approach along R's x axis towards aim, close, score. None when the hand cannot get near. Without q_open the hand approaches open, and again with a wider pre-shape (half way to the "flat" preset) when the open hand stops short of the aim (fingertips on the object's top); the better grasp is kept.

wide_preshape

wide_preshape() -> np.ndarray | None

candidates

candidates(table_z: float | None) -> list[np.ndarray]

plan

plan(obj: ObjectGeom, table_z: float | None = None, style: str | None = None, scene: ndarray | None = None, prefer: dict | None = None, rotations: Sequence[ndarray] | None = None) -> list[DexGrasp]

Ranked grasps (best first). style: "power", "pinch" (a preset name) or None for both. prefer: {"approach": unit vector, "tcp": 4x4 pose, "w_approach", "w_rot", "w_pos"} biases the ranking towards it. rotations: candidate TCP rotations instead of the sampled sphere.

pre_pose

pre_pose(g: DexGrasp, dist: float | None = None) -> np.ndarray

mesh_surface

mesh_surface(V: ndarray, F: ndarray, spacing: float = 0.004, seed: int = 0) -> np.ndarray

Points on a triangle mesh, about spacing apart (plus the vertices).

to_goals

to_goals(grasps: Sequence[DexGrasp], arm: str | None, pre_dist: float = 0.1) -> list

Toolkit Goals (verb "grasp"): pre-pose back along the approach, hand open while moving, then the squeeze.