Skip to content

Commit

Permalink
orbita_joint.py under Google format
Browse files Browse the repository at this point in the history
  • Loading branch information
glannuzel committed Oct 9, 2024
1 parent a059964 commit d7b71ea
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/reachy2_sdk/orbita/orbita_joint.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,28 @@ def __repr__(self) -> str:

@property
def present_position(self) -> float:
"""Get the present position of the joint in degrees."""
return to_position(self._present_position)

@property
def goal_position(self) -> float:
"""Get the goal position of the joint in degrees."""
return to_position(self._goal_position)

@goal_position.setter
def goal_position(self, value: float | int) -> None:
"""Set the goal position of the joint in degrees.
The goal position is not send to the joint immediately, it is stored locally until the `send_goal_positions` method
is called.
Args:
value: The goal position to set, specified as a float or int.
Raises:
TypeError: If the provided value is not a float or int.
"""

if isinstance(value, float) | isinstance(value, int):
self._actuator._set_outgoing_goal_position(self._axis_type, to_internal_position(value))
else:
Expand All @@ -62,9 +76,21 @@ def goto(
interpolation_mode: str = "minimum_jerk",
degrees: bool = True,
) -> GoToId:
"""Send the joint to the goal position in duration.
"""Send the joint to the specified goal position within a given duration.
Acts like a goto movements on the part, goto on joints are stacked on the part they belong to.
Acts like a "goto" movement on the part, where "goto" movements for joints are queued on the part they belong to.
Args:
goal_position: The target position to move the joint to.
duration: The time in seconds for the joint to reach the goal position. Defaults to 2.
wait: Whether to wait for the movement to finish before continuing. Defaults to False.
interpolation_mode: The type of interpolation to use for the movement, either "minimum_jerk" or "linear".
Defaults to "minimum_jerk".
degrees: Whether the goal position is specified in degrees. If True, the position is interpreted as degrees.
Defaults to True.
Returns:
The GoToId associated with the movement command.
"""
return self._actuator._part._goto_single_joint(
self._position_order_in_part,
Expand All @@ -76,5 +102,11 @@ def goto(
)

def _update_with(self, new_state: Dict[str, FloatValue]) -> None:
"""Update the present and goal positions of the joint with new state values.
Args:
new_state: A dictionary containing the new state values for the joint. The keys should include
"present_position" and "goal_position", with corresponding FloatValue objects as values.
"""
self._present_position = new_state["present_position"].value
self._goal_position = new_state["goal_position"].value

0 comments on commit d7b71ea

Please sign in to comment.