reachy2_sdk.grippers.parallel_gripper

Reachy ParallelGripper module.

Handles all specific methods to a ParallelGripper.

  1"""Reachy ParallelGripper module.
  2
  3Handles all specific methods to a ParallelGripper.
  4"""
  5
  6from typing import Any, List, Optional
  7
  8import grpc
  9import numpy as np
 10from google.protobuf.wrappers_pb2 import FloatValue
 11from reachy2_sdk_api.goto_pb2 import GoToId, GoToRequest, JointsGoal
 12from reachy2_sdk_api.goto_pb2_grpc import GoToServiceStub
 13from reachy2_sdk_api.hand_pb2 import Hand as Hand_proto
 14from reachy2_sdk_api.hand_pb2 import (
 15    HandJointGoal,
 16    HandPosition,
 17    HandPositionRequest,
 18    HandState,
 19    HandStatus,
 20    ParallelGripperPosition,
 21)
 22from reachy2_sdk_api.hand_pb2_grpc import HandServiceStub
 23
 24from ..parts.hand import Hand
 25from ..utils.utils import get_grpc_interpolation_mode
 26from .gripper_joint import GripperJoint
 27
 28
 29class ParallelGripper(Hand):
 30    """Class for controlling the Reachy's parallel gripper.
 31
 32    The `ParallelGripper` class provides methods to control the gripper of Reachy, including opening and closing
 33    the hand, setting the goal position, and checking the hand's state. It also manages the hand's
 34    compliance status (whether it is stiff or free). It implements all specific behaviors for the parallel gripper.
 35
 36    Attributes:
 37        opening: The opening of the hand as a percentage (0-100), rounded to two decimal places.
 38        present_position: The current position of the hand in degrees.
 39        goal_position: The target goal position of the hand in degrees.
 40    """
 41
 42    def __init__(
 43        self,
 44        hand_msg: Hand_proto,
 45        initial_state: HandState,
 46        grpc_channel: grpc.Channel,
 47        goto_stub: GoToServiceStub,
 48    ) -> None:
 49        """Initialize the ParallelGripper component.
 50
 51        Sets up the necessary attributes and configuration for the hand, including the gRPC
 52        stub and initial state.
 53
 54        Args:
 55            hand_msg: The Hand_proto object containing the configuration details for the hand.
 56            initial_state: The initial state of the hand, represented as a HandState object.
 57            grpc_channel: The gRPC channel used to communicate with the hand's gRPC service.
 58            goto_stub: The gRPC stub for controlling goto movements.
 59        """
 60        super().__init__(hand_msg, grpc_channel, goto_stub)
 61        self._stub = HandServiceStub(grpc_channel)
 62
 63        self._joints = {"finger": GripperJoint(initial_state)}
 64
 65    def __repr__(self) -> str:
 66        """Clean representation of a ParallelGripper."""
 67        s = "\n\t".join([str(joint) for joint in self._joints.values()])
 68        return f"""<ParallelGripper on={self.is_on()} joints=\n\t{
 69            s
 70        }\n>"""
 71
 72    @property
 73    def opening(self) -> float:
 74        """Get the opening of the parallel gripper only joint as a percentage.
 75
 76        Returns:
 77            The hand opening as a percentage (0-100), rounded to two decimal places.
 78        """
 79        return float(self._joints["finger"].opening)
 80
 81    @property
 82    def present_position(self) -> float:
 83        """Get the current position of the parallel gripper only joint.
 84
 85        Returns:
 86            The present position of the hand in degrees.
 87        """
 88        return float(self._joints["finger"].present_position)
 89
 90    @property
 91    def goal_position(self) -> float:
 92        """Get the goal position of the parallel gripper only joint.
 93
 94        Returns:
 95            The goal position of the hand in degrees.
 96        """
 97        return float(self._joints["finger"].goal_position)
 98
 99    @goal_position.setter
100    def goal_position(self, value: float | int) -> None:
101        """Set the goal position for the parallel gripper only joint.
102
103        Args:
104            value: The goal position to set, specified as a float or int.
105
106        Raises:
107            TypeError: If the provided value is not a float or int.
108        """
109        self._joints["finger"].goal_position = value
110
111    def _check_goto_parameters(self, target: Any, duration: Optional[float] = 0, q0: Optional[List[float]] = None) -> None:
112        """Check the validity of the parameters for the `goto` method.
113
114        Args:
115            duration: The time in seconds for the movement to be completed.
116            target: The target position, either a float or int.
117            q0: An optional initial joint configuration for inverse kinematics (not used for the hand). Defaults to None.
118
119        Raises:
120            TypeError: If the target is not a float or a int.
121            ValueError: If the duration is set to 0.
122        """
123        if not (isinstance(target, float) or isinstance(target, int)):
124            raise TypeError(f"Invalid target: must be either a float or a int, got {type(target)} instead.")
125
126        elif duration == 0:
127            raise ValueError("duration cannot be set to 0.")
128
129    def get_current_opening(self) -> float:
130        """Get the current opening of the parallel gripper only joint.
131
132        Returns:
133            The current opening of the hand as a percentage (0-100).
134        """
135        return self.opening
136
137    def set_opening(self, percentage: float) -> None:
138        """Set the opening value for the parallel gripper only joint.
139
140        Args:
141            percentage: The desired opening percentage of the hand, ranging from 0 to 100.
142
143        Raises:
144            ValueError: If the percentage is not between 0 and 100.
145            RuntimeError: If the gripper is off and the opening value cannot be set.
146        """
147        if not 0.0 <= percentage <= 100.0:
148            raise ValueError(f"Percentage should be between 0 and 100, not {percentage}")
149        if self.is_off():
150            raise RuntimeError("Gripper is off. Opening value not sent.")
151
152        self._stub.SetHandPosition(
153            HandPositionRequest(
154                id=self._part_id,
155                position=HandPosition(
156                    parallel_gripper=ParallelGripperPosition(opening_percentage=FloatValue(value=percentage / 100.0))
157                ),
158            )
159        )
160        self._joints["finger"]._is_moving = True
161
162    def _get_goal_positions_message(self) -> Optional[HandPositionRequest]:
163        """Get the HandPositionRequest message to send the goal positions to the actuator."""
164        if self._joints["finger"]._outgoing_goal_positions is not None:
165            if self.is_off():
166                self._logger.warning(f"{self._part_id.name} is off. Command not sent.")
167                return None
168            command = HandPositionRequest(
169                id=self._part_id,
170                position=HandPosition(
171                    parallel_gripper=ParallelGripperPosition(
172                        position=FloatValue(value=self._joints["finger"]._outgoing_goal_positions)
173                    )
174                ),
175            )
176            self._joints["finger"]._is_moving = True
177            return command
178        return None
179
180    def goto_posture(
181        self,
182        common_posture: str = "default",
183        duration: float = 2,
184        wait: bool = False,
185        wait_for_goto_end: bool = True,
186        interpolation_mode: str = "minimum_jerk",
187    ) -> GoToId:
188        """Send the gripper to default open posture with optional parameters for duration, waiting, and interpolation mode.
189
190        Args:
191            common_posture: The standard posture. It can be 'default' or 'elbow_90'. Defaults to 'default'.
192                Modifying the posture has no effect on the hand.
193            duration: The time duration in seconds for the robot to move to the specified posture.
194                Defaults to 2.
195            wait: Determines whether the program should wait for the movement to finish before
196                returning. If set to `True`, the program waits for the movement to complete before continuing
197                execution. Defaults to `False`.
198            wait_for_goto_end: Specifies whether commands will be sent to a part immediately or
199                only after all previous commands in the queue have been executed. If set to `False`, the program
200                will cancel all executing moves and queues. Defaults to `True`.
201            interpolation_mode: The type of interpolation used when moving the gripper.
202                Can be 'minimum_jerk' or 'linear'. Defaults to 'minimum_jerk'.
203
204        Returns:
205            A unique GoToId identifier for this specific movement.
206        """
207        if not wait_for_goto_end:
208            self.cancel_all_goto()
209        if self.is_on():
210            return self.goto(100.0, duration, wait, percentage=True, interpolation_mode=interpolation_mode)
211        else:
212            self._logger.warning(f"{self._part_id.name} is off. No command sent.")
213        return GoToId(id=-1)
214
215    def goto(
216        self,
217        target: float | int,
218        duration: float = 2,
219        wait: bool = False,
220        interpolation_mode: str = "minimum_jerk",
221        degrees: bool = True,
222        percentage: float = False,
223    ) -> GoToId:
224        """Move the hand to a specified goal position.
225
226        Args:
227            target: The target position. It can either be a float or int.
228            duration: The time in seconds for the movement to be completed. Defaults to 2.
229            wait: If True, the function waits until the movement is completed before returning.
230                    Defaults to False.
231            interpolation_mode: The interpolation method to be used. It can be either "minimum_jerk"
232                    or "linear". Defaults to "minimum_jerk".
233            degrees: If True, the joint values in the `target` argument are treated as degrees.
234                    Defaults to True.
235            percentage: If True, the target value is treated as a percentage of opening. Defaults to False.
236
237        Returns:
238            GoToId: The unique GoToId identifier for the movement command.
239        """
240        self._check_goto_parameters(target, duration)
241
242        if self.is_off():
243            self._logger.warning(f"{self._part_id.name} is off. Goto not sent.")
244            return GoToId(id=-1)
245
246        if degrees and not percentage:
247            target = np.deg2rad(target)
248
249        if percentage:
250            parallel_gripper_target = ParallelGripperPosition(opening_percentage=FloatValue(value=target / 100.0))
251        else:
252            parallel_gripper_target = ParallelGripperPosition(position=FloatValue(value=target))
253
254        request = GoToRequest(
255            joints_goal=JointsGoal(
256                hand_joint_goal=HandJointGoal(
257                    goal_request=HandPositionRequest(
258                        id=self._part_id,
259                        position=HandPosition(parallel_gripper=parallel_gripper_target),
260                    ),
261                    duration=FloatValue(value=duration),
262                )
263            ),
264            interpolation_mode=get_grpc_interpolation_mode(interpolation_mode),
265        )
266
267        response = self._goto_stub.GoToJoints(request)
268
269        if response.id == -1:
270            self._logger.error(f"Position {target} was not reachable. No command sent.")
271        elif wait:
272            self._wait_goto(response, duration)
273        self._joints["finger"]._is_moving = True
274        if interpolation_mode == "minimum_jerk":
275            self._nb_steps_to_ignore = 10
276        return response
277
278    def _update_with(self, new_state: HandState) -> None:
279        """Update the hand with a newly received (partial) state from the gRPC server.
280
281        This method updates the present position, goal position, opening, and compliance status.
282        It also checks if the hand is still moving based on the new state.
283
284        Args:
285            new_state: A HandState object representing the new state of the hand.
286        """
287        self._joints["finger"]._update_with(new_state)
288
289    def _update_audit_status(self, new_status: HandStatus) -> None:
290        """Update the audit status with the new status received from the gRPC server.
291
292        Args:
293            new_status: A HandStatus object representing the new status of the hand.
294        """
295        pass  # pragma: no cover
296
297    @property
298    def status(self) -> Optional[str]:
299        """Get the current audit status of the actuator.
300
301        Returns:
302            The audit status as a string, representing the latest error or status
303            message, or `None` if there is no error.
304        """
305        pass
class ParallelGripper(reachy2_sdk.parts.hand.Hand):
 30class ParallelGripper(Hand):
 31    """Class for controlling the Reachy's parallel gripper.
 32
 33    The `ParallelGripper` class provides methods to control the gripper of Reachy, including opening and closing
 34    the hand, setting the goal position, and checking the hand's state. It also manages the hand's
 35    compliance status (whether it is stiff or free). It implements all specific behaviors for the parallel gripper.
 36
 37    Attributes:
 38        opening: The opening of the hand as a percentage (0-100), rounded to two decimal places.
 39        present_position: The current position of the hand in degrees.
 40        goal_position: The target goal position of the hand in degrees.
 41    """
 42
 43    def __init__(
 44        self,
 45        hand_msg: Hand_proto,
 46        initial_state: HandState,
 47        grpc_channel: grpc.Channel,
 48        goto_stub: GoToServiceStub,
 49    ) -> None:
 50        """Initialize the ParallelGripper component.
 51
 52        Sets up the necessary attributes and configuration for the hand, including the gRPC
 53        stub and initial state.
 54
 55        Args:
 56            hand_msg: The Hand_proto object containing the configuration details for the hand.
 57            initial_state: The initial state of the hand, represented as a HandState object.
 58            grpc_channel: The gRPC channel used to communicate with the hand's gRPC service.
 59            goto_stub: The gRPC stub for controlling goto movements.
 60        """
 61        super().__init__(hand_msg, grpc_channel, goto_stub)
 62        self._stub = HandServiceStub(grpc_channel)
 63
 64        self._joints = {"finger": GripperJoint(initial_state)}
 65
 66    def __repr__(self) -> str:
 67        """Clean representation of a ParallelGripper."""
 68        s = "\n\t".join([str(joint) for joint in self._joints.values()])
 69        return f"""<ParallelGripper on={self.is_on()} joints=\n\t{
 70            s
 71        }\n>"""
 72
 73    @property
 74    def opening(self) -> float:
 75        """Get the opening of the parallel gripper only joint as a percentage.
 76
 77        Returns:
 78            The hand opening as a percentage (0-100), rounded to two decimal places.
 79        """
 80        return float(self._joints["finger"].opening)
 81
 82    @property
 83    def present_position(self) -> float:
 84        """Get the current position of the parallel gripper only joint.
 85
 86        Returns:
 87            The present position of the hand in degrees.
 88        """
 89        return float(self._joints["finger"].present_position)
 90
 91    @property
 92    def goal_position(self) -> float:
 93        """Get the goal position of the parallel gripper only joint.
 94
 95        Returns:
 96            The goal position of the hand in degrees.
 97        """
 98        return float(self._joints["finger"].goal_position)
 99
100    @goal_position.setter
101    def goal_position(self, value: float | int) -> None:
102        """Set the goal position for the parallel gripper only joint.
103
104        Args:
105            value: The goal position to set, specified as a float or int.
106
107        Raises:
108            TypeError: If the provided value is not a float or int.
109        """
110        self._joints["finger"].goal_position = value
111
112    def _check_goto_parameters(self, target: Any, duration: Optional[float] = 0, q0: Optional[List[float]] = None) -> None:
113        """Check the validity of the parameters for the `goto` method.
114
115        Args:
116            duration: The time in seconds for the movement to be completed.
117            target: The target position, either a float or int.
118            q0: An optional initial joint configuration for inverse kinematics (not used for the hand). Defaults to None.
119
120        Raises:
121            TypeError: If the target is not a float or a int.
122            ValueError: If the duration is set to 0.
123        """
124        if not (isinstance(target, float) or isinstance(target, int)):
125            raise TypeError(f"Invalid target: must be either a float or a int, got {type(target)} instead.")
126
127        elif duration == 0:
128            raise ValueError("duration cannot be set to 0.")
129
130    def get_current_opening(self) -> float:
131        """Get the current opening of the parallel gripper only joint.
132
133        Returns:
134            The current opening of the hand as a percentage (0-100).
135        """
136        return self.opening
137
138    def set_opening(self, percentage: float) -> None:
139        """Set the opening value for the parallel gripper only joint.
140
141        Args:
142            percentage: The desired opening percentage of the hand, ranging from 0 to 100.
143
144        Raises:
145            ValueError: If the percentage is not between 0 and 100.
146            RuntimeError: If the gripper is off and the opening value cannot be set.
147        """
148        if not 0.0 <= percentage <= 100.0:
149            raise ValueError(f"Percentage should be between 0 and 100, not {percentage}")
150        if self.is_off():
151            raise RuntimeError("Gripper is off. Opening value not sent.")
152
153        self._stub.SetHandPosition(
154            HandPositionRequest(
155                id=self._part_id,
156                position=HandPosition(
157                    parallel_gripper=ParallelGripperPosition(opening_percentage=FloatValue(value=percentage / 100.0))
158                ),
159            )
160        )
161        self._joints["finger"]._is_moving = True
162
163    def _get_goal_positions_message(self) -> Optional[HandPositionRequest]:
164        """Get the HandPositionRequest message to send the goal positions to the actuator."""
165        if self._joints["finger"]._outgoing_goal_positions is not None:
166            if self.is_off():
167                self._logger.warning(f"{self._part_id.name} is off. Command not sent.")
168                return None
169            command = HandPositionRequest(
170                id=self._part_id,
171                position=HandPosition(
172                    parallel_gripper=ParallelGripperPosition(
173                        position=FloatValue(value=self._joints["finger"]._outgoing_goal_positions)
174                    )
175                ),
176            )
177            self._joints["finger"]._is_moving = True
178            return command
179        return None
180
181    def goto_posture(
182        self,
183        common_posture: str = "default",
184        duration: float = 2,
185        wait: bool = False,
186        wait_for_goto_end: bool = True,
187        interpolation_mode: str = "minimum_jerk",
188    ) -> GoToId:
189        """Send the gripper to default open posture with optional parameters for duration, waiting, and interpolation mode.
190
191        Args:
192            common_posture: The standard posture. It can be 'default' or 'elbow_90'. Defaults to 'default'.
193                Modifying the posture has no effect on the hand.
194            duration: The time duration in seconds for the robot to move to the specified posture.
195                Defaults to 2.
196            wait: Determines whether the program should wait for the movement to finish before
197                returning. If set to `True`, the program waits for the movement to complete before continuing
198                execution. Defaults to `False`.
199            wait_for_goto_end: Specifies whether commands will be sent to a part immediately or
200                only after all previous commands in the queue have been executed. If set to `False`, the program
201                will cancel all executing moves and queues. Defaults to `True`.
202            interpolation_mode: The type of interpolation used when moving the gripper.
203                Can be 'minimum_jerk' or 'linear'. Defaults to 'minimum_jerk'.
204
205        Returns:
206            A unique GoToId identifier for this specific movement.
207        """
208        if not wait_for_goto_end:
209            self.cancel_all_goto()
210        if self.is_on():
211            return self.goto(100.0, duration, wait, percentage=True, interpolation_mode=interpolation_mode)
212        else:
213            self._logger.warning(f"{self._part_id.name} is off. No command sent.")
214        return GoToId(id=-1)
215
216    def goto(
217        self,
218        target: float | int,
219        duration: float = 2,
220        wait: bool = False,
221        interpolation_mode: str = "minimum_jerk",
222        degrees: bool = True,
223        percentage: float = False,
224    ) -> GoToId:
225        """Move the hand to a specified goal position.
226
227        Args:
228            target: The target position. It can either be a float or int.
229            duration: The time in seconds for the movement to be completed. Defaults to 2.
230            wait: If True, the function waits until the movement is completed before returning.
231                    Defaults to False.
232            interpolation_mode: The interpolation method to be used. It can be either "minimum_jerk"
233                    or "linear". Defaults to "minimum_jerk".
234            degrees: If True, the joint values in the `target` argument are treated as degrees.
235                    Defaults to True.
236            percentage: If True, the target value is treated as a percentage of opening. Defaults to False.
237
238        Returns:
239            GoToId: The unique GoToId identifier for the movement command.
240        """
241        self._check_goto_parameters(target, duration)
242
243        if self.is_off():
244            self._logger.warning(f"{self._part_id.name} is off. Goto not sent.")
245            return GoToId(id=-1)
246
247        if degrees and not percentage:
248            target = np.deg2rad(target)
249
250        if percentage:
251            parallel_gripper_target = ParallelGripperPosition(opening_percentage=FloatValue(value=target / 100.0))
252        else:
253            parallel_gripper_target = ParallelGripperPosition(position=FloatValue(value=target))
254
255        request = GoToRequest(
256            joints_goal=JointsGoal(
257                hand_joint_goal=HandJointGoal(
258                    goal_request=HandPositionRequest(
259                        id=self._part_id,
260                        position=HandPosition(parallel_gripper=parallel_gripper_target),
261                    ),
262                    duration=FloatValue(value=duration),
263                )
264            ),
265            interpolation_mode=get_grpc_interpolation_mode(interpolation_mode),
266        )
267
268        response = self._goto_stub.GoToJoints(request)
269
270        if response.id == -1:
271            self._logger.error(f"Position {target} was not reachable. No command sent.")
272        elif wait:
273            self._wait_goto(response, duration)
274        self._joints["finger"]._is_moving = True
275        if interpolation_mode == "minimum_jerk":
276            self._nb_steps_to_ignore = 10
277        return response
278
279    def _update_with(self, new_state: HandState) -> None:
280        """Update the hand with a newly received (partial) state from the gRPC server.
281
282        This method updates the present position, goal position, opening, and compliance status.
283        It also checks if the hand is still moving based on the new state.
284
285        Args:
286            new_state: A HandState object representing the new state of the hand.
287        """
288        self._joints["finger"]._update_with(new_state)
289
290    def _update_audit_status(self, new_status: HandStatus) -> None:
291        """Update the audit status with the new status received from the gRPC server.
292
293        Args:
294            new_status: A HandStatus object representing the new status of the hand.
295        """
296        pass  # pragma: no cover
297
298    @property
299    def status(self) -> Optional[str]:
300        """Get the current audit status of the actuator.
301
302        Returns:
303            The audit status as a string, representing the latest error or status
304            message, or `None` if there is no error.
305        """
306        pass

Class for controlling the Reachy's parallel gripper.

The ParallelGripper class provides methods to control the gripper of Reachy, including opening and closing the hand, setting the goal position, and checking the hand's state. It also manages the hand's compliance status (whether it is stiff or free). It implements all specific behaviors for the parallel gripper.

Attributes:
  • opening: The opening of the hand as a percentage (0-100), rounded to two decimal places.
  • present_position: The current position of the hand in degrees.
  • goal_position: The target goal position of the hand in degrees.
ParallelGripper( hand_msg: hand_pb2.Hand, initial_state: hand_pb2.HandState, grpc_channel: grpc.Channel, goto_stub: reachy2_sdk_api.goto_pb2_grpc.GoToServiceStub)
43    def __init__(
44        self,
45        hand_msg: Hand_proto,
46        initial_state: HandState,
47        grpc_channel: grpc.Channel,
48        goto_stub: GoToServiceStub,
49    ) -> None:
50        """Initialize the ParallelGripper component.
51
52        Sets up the necessary attributes and configuration for the hand, including the gRPC
53        stub and initial state.
54
55        Args:
56            hand_msg: The Hand_proto object containing the configuration details for the hand.
57            initial_state: The initial state of the hand, represented as a HandState object.
58            grpc_channel: The gRPC channel used to communicate with the hand's gRPC service.
59            goto_stub: The gRPC stub for controlling goto movements.
60        """
61        super().__init__(hand_msg, grpc_channel, goto_stub)
62        self._stub = HandServiceStub(grpc_channel)
63
64        self._joints = {"finger": GripperJoint(initial_state)}

Initialize the ParallelGripper component.

Sets up the necessary attributes and configuration for the hand, including the gRPC stub and initial state.

Arguments:
  • hand_msg: The Hand_proto object containing the configuration details for the hand.
  • initial_state: The initial state of the hand, represented as a HandState object.
  • grpc_channel: The gRPC channel used to communicate with the hand's gRPC service.
  • goto_stub: The gRPC stub for controlling goto movements.
opening: float
73    @property
74    def opening(self) -> float:
75        """Get the opening of the parallel gripper only joint as a percentage.
76
77        Returns:
78            The hand opening as a percentage (0-100), rounded to two decimal places.
79        """
80        return float(self._joints["finger"].opening)

Get the opening of the parallel gripper only joint as a percentage.

Returns:

The hand opening as a percentage (0-100), rounded to two decimal places.

present_position: float
82    @property
83    def present_position(self) -> float:
84        """Get the current position of the parallel gripper only joint.
85
86        Returns:
87            The present position of the hand in degrees.
88        """
89        return float(self._joints["finger"].present_position)

Get the current position of the parallel gripper only joint.

Returns:

The present position of the hand in degrees.

goal_position: float
91    @property
92    def goal_position(self) -> float:
93        """Get the goal position of the parallel gripper only joint.
94
95        Returns:
96            The goal position of the hand in degrees.
97        """
98        return float(self._joints["finger"].goal_position)

Get the goal position of the parallel gripper only joint.

Returns:

The goal position of the hand in degrees.

def get_current_opening(self) -> float:
130    def get_current_opening(self) -> float:
131        """Get the current opening of the parallel gripper only joint.
132
133        Returns:
134            The current opening of the hand as a percentage (0-100).
135        """
136        return self.opening

Get the current opening of the parallel gripper only joint.

Returns:

The current opening of the hand as a percentage (0-100).

def set_opening(self, percentage: float) -> None:
138    def set_opening(self, percentage: float) -> None:
139        """Set the opening value for the parallel gripper only joint.
140
141        Args:
142            percentage: The desired opening percentage of the hand, ranging from 0 to 100.
143
144        Raises:
145            ValueError: If the percentage is not between 0 and 100.
146            RuntimeError: If the gripper is off and the opening value cannot be set.
147        """
148        if not 0.0 <= percentage <= 100.0:
149            raise ValueError(f"Percentage should be between 0 and 100, not {percentage}")
150        if self.is_off():
151            raise RuntimeError("Gripper is off. Opening value not sent.")
152
153        self._stub.SetHandPosition(
154            HandPositionRequest(
155                id=self._part_id,
156                position=HandPosition(
157                    parallel_gripper=ParallelGripperPosition(opening_percentage=FloatValue(value=percentage / 100.0))
158                ),
159            )
160        )
161        self._joints["finger"]._is_moving = True

Set the opening value for the parallel gripper only joint.

Arguments:
  • percentage: The desired opening percentage of the hand, ranging from 0 to 100.
Raises:
  • ValueError: If the percentage is not between 0 and 100.
  • RuntimeError: If the gripper is off and the opening value cannot be set.
def goto_posture( self, common_posture: str = 'default', duration: float = 2, wait: bool = False, wait_for_goto_end: bool = True, interpolation_mode: str = 'minimum_jerk') -> goto_pb2.GoToId:
181    def goto_posture(
182        self,
183        common_posture: str = "default",
184        duration: float = 2,
185        wait: bool = False,
186        wait_for_goto_end: bool = True,
187        interpolation_mode: str = "minimum_jerk",
188    ) -> GoToId:
189        """Send the gripper to default open posture with optional parameters for duration, waiting, and interpolation mode.
190
191        Args:
192            common_posture: The standard posture. It can be 'default' or 'elbow_90'. Defaults to 'default'.
193                Modifying the posture has no effect on the hand.
194            duration: The time duration in seconds for the robot to move to the specified posture.
195                Defaults to 2.
196            wait: Determines whether the program should wait for the movement to finish before
197                returning. If set to `True`, the program waits for the movement to complete before continuing
198                execution. Defaults to `False`.
199            wait_for_goto_end: Specifies whether commands will be sent to a part immediately or
200                only after all previous commands in the queue have been executed. If set to `False`, the program
201                will cancel all executing moves and queues. Defaults to `True`.
202            interpolation_mode: The type of interpolation used when moving the gripper.
203                Can be 'minimum_jerk' or 'linear'. Defaults to 'minimum_jerk'.
204
205        Returns:
206            A unique GoToId identifier for this specific movement.
207        """
208        if not wait_for_goto_end:
209            self.cancel_all_goto()
210        if self.is_on():
211            return self.goto(100.0, duration, wait, percentage=True, interpolation_mode=interpolation_mode)
212        else:
213            self._logger.warning(f"{self._part_id.name} is off. No command sent.")
214        return GoToId(id=-1)

Send the gripper to default open posture with optional parameters for duration, waiting, and interpolation mode.

Arguments:
  • common_posture: The standard posture. It can be 'default' or 'elbow_90'. Defaults to 'default'. Modifying the posture has no effect on the hand.
  • duration: The time duration in seconds for the robot to move to the specified posture. Defaults to 2.
  • wait: Determines whether the program should wait for the movement to finish before returning. If set to True, the program waits for the movement to complete before continuing execution. Defaults to False.
  • wait_for_goto_end: Specifies whether commands will be sent to a part immediately or only after all previous commands in the queue have been executed. If set to False, the program will cancel all executing moves and queues. Defaults to True.
  • interpolation_mode: The type of interpolation used when moving the gripper. Can be 'minimum_jerk' or 'linear'. Defaults to 'minimum_jerk'.
Returns:

A unique GoToId identifier for this specific movement.

def goto( self, target: float | int, duration: float = 2, wait: bool = False, interpolation_mode: str = 'minimum_jerk', degrees: bool = True, percentage: float = False) -> goto_pb2.GoToId:
216    def goto(
217        self,
218        target: float | int,
219        duration: float = 2,
220        wait: bool = False,
221        interpolation_mode: str = "minimum_jerk",
222        degrees: bool = True,
223        percentage: float = False,
224    ) -> GoToId:
225        """Move the hand to a specified goal position.
226
227        Args:
228            target: The target position. It can either be a float or int.
229            duration: The time in seconds for the movement to be completed. Defaults to 2.
230            wait: If True, the function waits until the movement is completed before returning.
231                    Defaults to False.
232            interpolation_mode: The interpolation method to be used. It can be either "minimum_jerk"
233                    or "linear". Defaults to "minimum_jerk".
234            degrees: If True, the joint values in the `target` argument are treated as degrees.
235                    Defaults to True.
236            percentage: If True, the target value is treated as a percentage of opening. Defaults to False.
237
238        Returns:
239            GoToId: The unique GoToId identifier for the movement command.
240        """
241        self._check_goto_parameters(target, duration)
242
243        if self.is_off():
244            self._logger.warning(f"{self._part_id.name} is off. Goto not sent.")
245            return GoToId(id=-1)
246
247        if degrees and not percentage:
248            target = np.deg2rad(target)
249
250        if percentage:
251            parallel_gripper_target = ParallelGripperPosition(opening_percentage=FloatValue(value=target / 100.0))
252        else:
253            parallel_gripper_target = ParallelGripperPosition(position=FloatValue(value=target))
254
255        request = GoToRequest(
256            joints_goal=JointsGoal(
257                hand_joint_goal=HandJointGoal(
258                    goal_request=HandPositionRequest(
259                        id=self._part_id,
260                        position=HandPosition(parallel_gripper=parallel_gripper_target),
261                    ),
262                    duration=FloatValue(value=duration),
263                )
264            ),
265            interpolation_mode=get_grpc_interpolation_mode(interpolation_mode),
266        )
267
268        response = self._goto_stub.GoToJoints(request)
269
270        if response.id == -1:
271            self._logger.error(f"Position {target} was not reachable. No command sent.")
272        elif wait:
273            self._wait_goto(response, duration)
274        self._joints["finger"]._is_moving = True
275        if interpolation_mode == "minimum_jerk":
276            self._nb_steps_to_ignore = 10
277        return response

Move the hand to a specified goal position.

Arguments:
  • target: The target position. It can either be a float or int.
  • duration: The time in seconds for the movement to be completed. Defaults to 2.
  • wait: If True, the function waits until the movement is completed before returning. Defaults to False.
  • interpolation_mode: The interpolation method to be used. It can be either "minimum_jerk" or "linear". Defaults to "minimum_jerk".
  • degrees: If True, the joint values in the target argument are treated as degrees. Defaults to True.
  • percentage: If True, the target value is treated as a percentage of opening. Defaults to False.
Returns:

GoToId: The unique GoToId identifier for the movement command.

status: Optional[str]
298    @property
299    def status(self) -> Optional[str]:
300        """Get the current audit status of the actuator.
301
302        Returns:
303            The audit status as a string, representing the latest error or status
304            message, or `None` if there is no error.
305        """
306        pass

Get the current audit status of the actuator.

Returns:

The audit status as a string, representing the latest error or status message, or None if there is no error.