Skip to content

Sim Interface

SimInterface

Bases: HardwareInterface

A simulated interface for testing and validating purposes.

This class simulates the interface between the robot arm and the control system.

Attributes:

Name Type Description
home_pos

The home position of the robot arm.

current_pos

The current position of the robot arm.

Source code in mbodied/hardware/sim_interface.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
class SimInterface(HardwareInterface):
    """A simulated interface for testing and validating purposes.

    This class simulates the interface between the robot arm and the control system.

    Attributes:
        home_pos: The home position of the robot arm.
        current_pos: The current position of the robot arm.
    """

    def __init__(self):
        """Initializes the SimInterface and sets up the robot arm.

        position: [x, y, z, r, p, y, grasp]
        """
        self.home_pos = [0, 0, 0, 0, 0, 0, 0]
        self.current_pos = self.home_pos

    def do(self, motion: HandControl) -> list[float]:
        """Executes a given HandControl motion and returns the new position of the robot arm.

        Args:
            motion: The HandControl motion to be executed.
        """
        print("Executing motion:", motion)  # noqa: T201
        self.current_pos[0] += motion.pose.x
        self.current_pos[1] += motion.pose.y
        self.current_pos[2] += motion.pose.z
        self.current_pos[3] += motion.pose.roll
        self.current_pos[4] += motion.pose.pitch
        self.current_pos[5] += motion.pose.yaw
        self.current_pos[6] = motion.grasp.value
        print("New position:", self.current_pos)  # noqa: T201

        return self.current_pos

    def get_pose(self) -> list[float]:
        """Gets the current pose of the robot arm.

        Returns:
            list[float]: A list of the current pose values [x, y, z, r, p, y, grasp].
        """
        return self.current_pos

    def capture(self, **_) -> Image:
        """Captures an image."""
        return Image(size=(224, 224))

__init__()

Initializes the SimInterface and sets up the robot arm.

position: [x, y, z, r, p, y, grasp]

Source code in mbodied/hardware/sim_interface.py
30
31
32
33
34
35
36
def __init__(self):
    """Initializes the SimInterface and sets up the robot arm.

    position: [x, y, z, r, p, y, grasp]
    """
    self.home_pos = [0, 0, 0, 0, 0, 0, 0]
    self.current_pos = self.home_pos

capture(**_)

Captures an image.

Source code in mbodied/hardware/sim_interface.py
64
65
66
def capture(self, **_) -> Image:
    """Captures an image."""
    return Image(size=(224, 224))

do(motion)

Executes a given HandControl motion and returns the new position of the robot arm.

Parameters:

Name Type Description Default
motion HandControl

The HandControl motion to be executed.

required
Source code in mbodied/hardware/sim_interface.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def do(self, motion: HandControl) -> list[float]:
    """Executes a given HandControl motion and returns the new position of the robot arm.

    Args:
        motion: The HandControl motion to be executed.
    """
    print("Executing motion:", motion)  # noqa: T201
    self.current_pos[0] += motion.pose.x
    self.current_pos[1] += motion.pose.y
    self.current_pos[2] += motion.pose.z
    self.current_pos[3] += motion.pose.roll
    self.current_pos[4] += motion.pose.pitch
    self.current_pos[5] += motion.pose.yaw
    self.current_pos[6] = motion.grasp.value
    print("New position:", self.current_pos)  # noqa: T201

    return self.current_pos

get_pose()

Gets the current pose of the robot arm.

Returns:

Type Description
list[float]

list[float]: A list of the current pose values [x, y, z, r, p, y, grasp].

Source code in mbodied/hardware/sim_interface.py
56
57
58
59
60
61
62
def get_pose(self) -> list[float]:
    """Gets the current pose of the robot arm.

    Returns:
        list[float]: A list of the current pose values [x, y, z, r, p, y, grasp].
    """
    return self.current_pos