Skip to content

Hand API

User-facing API for commanding a dexterous hand.

Source code in dexterous_hand/hand.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class Hand:
    """User-facing API for commanding a dexterous hand."""

    def __init__(self, driver: HandDriver, grasp_library: GraspLibrary | None = None) -> None:
        self.driver = driver
        self.grasps = grasp_library or GraspLibrary()

    @classmethod
    def mock(cls) -> "Hand":
        """Create a mock hand suitable for examples and tests."""
        driver = MockHandDriver(DEFAULT_JOINTS)
        driver.connect()
        return cls(driver)

    def read_joints(self) -> list[JointState]:
        """Read current joint states."""
        return self.driver.read_joints()

    def move_joints(self, positions_rad: dict[str, float]) -> None:
        """Move joints to target positions."""
        self.driver.command_positions(positions_rad)

    def move_to_grasp(self, grasp_name: str) -> None:
        """Move to a named grasp pose."""
        pose = self.grasps.get(grasp_name)
        self.move_joints(pose.joint_positions_rad)

    def open(self) -> None:
        """Open the hand to a neutral pose."""
        joints = {state.name: 0.0 for state in self.read_joints()}
        self.move_joints(joints)

    def stop(self) -> None:
        """Stop motion immediately."""
        self.driver.stop()

mock() classmethod

Create a mock hand suitable for examples and tests.

Source code in dexterous_hand/hand.py
26
27
28
29
30
31
@classmethod
def mock(cls) -> "Hand":
    """Create a mock hand suitable for examples and tests."""
    driver = MockHandDriver(DEFAULT_JOINTS)
    driver.connect()
    return cls(driver)

move_joints(positions_rad)

Move joints to target positions.

Source code in dexterous_hand/hand.py
37
38
39
def move_joints(self, positions_rad: dict[str, float]) -> None:
    """Move joints to target positions."""
    self.driver.command_positions(positions_rad)

move_to_grasp(grasp_name)

Move to a named grasp pose.

Source code in dexterous_hand/hand.py
41
42
43
44
def move_to_grasp(self, grasp_name: str) -> None:
    """Move to a named grasp pose."""
    pose = self.grasps.get(grasp_name)
    self.move_joints(pose.joint_positions_rad)

open()

Open the hand to a neutral pose.

Source code in dexterous_hand/hand.py
46
47
48
49
def open(self) -> None:
    """Open the hand to a neutral pose."""
    joints = {state.name: 0.0 for state in self.read_joints()}
    self.move_joints(joints)

read_joints()

Read current joint states.

Source code in dexterous_hand/hand.py
33
34
35
def read_joints(self) -> list[JointState]:
    """Read current joint states."""
    return self.driver.read_joints()

stop()

Stop motion immediately.

Source code in dexterous_hand/hand.py
51
52
53
def stop(self) -> None:
    """Stop motion immediately."""
    self.driver.stop()