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
¶
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).
set ¶
Place the hand: TCP pose in the world and finger joints q (HandSpec.joints order; None: open).
surface ¶
World collision samples after set (all, or those selected by a boolean mask), and their body ids.
tip_jacobians ¶
(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).
points_in_tcp ¶
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.