Skip to content

hylo.manip.handmodel

Package: hylo-manip · Core contracts

handmodel

A dexterous hand on its own: the subtree of an arm model's hand body, cut out of any MJCF (or URDF) with MuJoCo's model editor and hung under a mocap root so its pose in the world can be set freely. The grasp planner and the retargeting solver work on it.

hand = HandModel.from_arm(robot_spec.arm("right"))      # the hand of an arm, as its ArmSpec describes it
hand = HandModel(model_path, "palm", hand_spec)          # any model file, its hand body and a HandSpec
hand.set(T_world_tcp, q)                                 # place it (TCP pose) with finger joints q
pts, link = hand.surface()                               # collision surface samples in the world, link per point

Fingers are found from the kinematic tree: each child chain of the hand body that holds finger joints is one finger (its joints in HandSpec.joints order, its links, its tip: the collision point of its last link farthest from the finger's first joint). The thumb is the finger whose names say so ("thumb", "th"), else the one whose base lies farthest from the others; the other fingers are named by hints in their body and joint names (index / ff, middle / mf, ring / rf, little / lf), else in order. The human wrist's place on the hand (for retargeting) is a site named "wrist" on the hand body when the model has one, else the end of the palm's collision geometry opposite the fingers.

FINGER_HINTS module-attribute

FINGER_HINTS = (('thumb', ('thumb', 'th')), ('index', ('index', 'ff', 'first', 'if')), ('middle', ('middle', 'mf', 'mid')), ('ring', ('ring', 'rf')), ('little', ('little', 'pinky', 'lf', 'pf')))

Finger dataclass

Finger(name: str, joints: list[int], bodies: list[int], tip_body: int, tip_local: ndarray, base_body: int)

name instance-attribute

name: str

joints instance-attribute

joints: list[int]

bodies instance-attribute

bodies: list[int]

tip_body instance-attribute

tip_body: int

tip_local instance-attribute

tip_local: ndarray

base_body instance-attribute

base_body: int

HandModel dataclass

HandModel(model_path: str, ee_body: str, hand: HandSpec, name: str = 'hand', spacing: float = 0.004, wrist_in_ee: Sequence[float] | None = None, finger_names: dict[str, str] | None = None)

See the module docstring. spacing: distance between collision surface samples (m).

model_path instance-attribute

model_path: str

ee_body instance-attribute

ee_body: str

hand instance-attribute

hand: HandSpec

name class-attribute instance-attribute

name: str = 'hand'

spacing class-attribute instance-attribute

spacing: float = 0.004

wrist_in_ee class-attribute instance-attribute

wrist_in_ee: Sequence[float] | None = None

finger_names class-attribute instance-attribute

finger_names: dict[str, str] | None = None

spec class-attribute instance-attribute

spec: MjSpec = field(init=False, repr=False)

from_arm classmethod

from_arm(arm: ArmSpec, **kw) -> 'HandModel'

finger

finger(name: str) -> Finger

clip

clip(q: ndarray) -> np.ndarray

set

set(T_world_tcp: ndarray, q: Sequence[float] | None = None) -> None

Place the hand: TCP pose in the world and finger joints q (HandSpec.joints order; None: open).

set_ee

set_ee(T_world_ee: ndarray, q: Sequence[float] | None = None) -> None

ee_pose

ee_pose() -> np.ndarray

surface

surface(mask: ndarray | None = None) -> tuple[np.ndarray, np.ndarray]

World collision samples after set (all, or those selected by a boolean mask), and their body ids.

tips

tips() -> np.ndarray

(n_fingers, 3) fingertip points in the world after set.

tip_jacobians

tip_jacobians() -> np.ndarray

(n_fingers, 3, n_joints) Jacobians of the fingertip points w.r.t. the finger joints, after set (needs mj_kinematics + mj_comPos, done here).

wrist

wrist() -> np.ndarray

finger_bases

finger_bases() -> np.ndarray

points_in_tcp

points_in_tcp(q: Sequence[float] | None = None) -> tuple[np.ndarray, np.ndarray]

Collision samples in the TCP frame at finger joints q (None: open), and the finger index per point (-1: palm).

extract_hand

extract_hand(model_path: str | Path, ee_body: str, finger_joints: Sequence[str], *, root: str = 'hand_root') -> mujoco.MjSpec

A new model spec holding only ee_body's subtree under a mocap body root (world pose = the ee frame). Joints of the ee body itself (the arm's last joints) are dropped, actuators kept only on finger joints, and meshes no geom uses are removed, so only the hand's mesh files are read.