reachy2_sdk.orbita.orbita_motor

Reachy OrbitaMotor module.

Handles all specific methods to OrbitaMotor.

 1"""Reachy OrbitaMotor module.
 2
 3Handles all specific methods to OrbitaMotor.
 4"""
 5
 6from typing import Any, Dict
 7
 8import numpy as np
 9from google.protobuf.wrappers_pb2 import FloatValue
10from reachy2_sdk_api.component_pb2 import PIDGains
11
12from .utils import unwrapped_pid_value
13
14
15class OrbitaMotor:
16    """The OrbitaMotor class represents any Orbita3d or Orbita2d motor.
17
18    The OrbitaMotor class is used to store the up-to-date state of the motor, especially:
19    - its temperature (RO)
20    - its compliancy (RO)
21    - its speed limit (RW)
22    - its torque limit (RW)
23    - its pid (RW)
24    """
25
26    def __init__(self, initial_state: Dict[str, Any], actuator: Any) -> None:
27        """Initialize the motor with its initial state.
28
29        Args:
30            initial_state: A dictionary containing the initial state values for the motor. The keys should include
31                "temperature", "speed_limit", "torque_limit", "compliant", and "pid", with corresponding
32                FloatValue objects as values.
33            actuator: The actuator to which the motor belongs.
34        """
35        self._actuator = actuator
36        self._update_with(initial_state)
37
38    @property
39    def speed_limit(self) -> float:
40        """Get the speed limit of the motor, as a percentage of the max allowed speed, rounded to three decimal places."""
41        return float(np.round(self._speed_limit, 3))
42
43    @property
44    def temperature(self) -> float:
45        """Get the current temperature of the motor in Celsius degrees."""
46        return float(self._temperature)
47
48    @property
49    def torque_limit(self) -> float:
50        """Get the torque limit of the axis, as a percentage of the max allowed speed, rounded to three decimal places."""
51        return float(np.round(self._torque_limit, 3))
52
53    @property
54    def compliant(self) -> float:
55        """Get the compliance status of the motor."""
56        return float(self._compliant)
57
58    @property
59    def pid(self) -> PIDGains:
60        """Get the PID gains of the motor."""
61        return self._pid
62
63    def _update_with(self, new_state: Dict[str, FloatValue]) -> None:
64        """Update the state of the motor with new values from the provided state dictionary.
65
66        Args:
67            new_state: A dictionary containing the new state values for the axis. The keys should include
68                "temperature", "speed_limit", "torque_limit", "compliant", and "pid", with corresponding
69                FloatValue objects as values.
70        """
71        self._temperature = new_state["temperature"].value
72        self._speed_limit = new_state["speed_limit"].value * 100  # received value in [0, 1]
73        self._torque_limit = new_state["torque_limit"].value * 100  # received value in [0, 1]
74        self._compliant = new_state["compliant"].value
75        self._pid = unwrapped_pid_value(new_state["pid"])
class OrbitaMotor:
16class OrbitaMotor:
17    """The OrbitaMotor class represents any Orbita3d or Orbita2d motor.
18
19    The OrbitaMotor class is used to store the up-to-date state of the motor, especially:
20    - its temperature (RO)
21    - its compliancy (RO)
22    - its speed limit (RW)
23    - its torque limit (RW)
24    - its pid (RW)
25    """
26
27    def __init__(self, initial_state: Dict[str, Any], actuator: Any) -> None:
28        """Initialize the motor with its initial state.
29
30        Args:
31            initial_state: A dictionary containing the initial state values for the motor. The keys should include
32                "temperature", "speed_limit", "torque_limit", "compliant", and "pid", with corresponding
33                FloatValue objects as values.
34            actuator: The actuator to which the motor belongs.
35        """
36        self._actuator = actuator
37        self._update_with(initial_state)
38
39    @property
40    def speed_limit(self) -> float:
41        """Get the speed limit of the motor, as a percentage of the max allowed speed, rounded to three decimal places."""
42        return float(np.round(self._speed_limit, 3))
43
44    @property
45    def temperature(self) -> float:
46        """Get the current temperature of the motor in Celsius degrees."""
47        return float(self._temperature)
48
49    @property
50    def torque_limit(self) -> float:
51        """Get the torque limit of the axis, as a percentage of the max allowed speed, rounded to three decimal places."""
52        return float(np.round(self._torque_limit, 3))
53
54    @property
55    def compliant(self) -> float:
56        """Get the compliance status of the motor."""
57        return float(self._compliant)
58
59    @property
60    def pid(self) -> PIDGains:
61        """Get the PID gains of the motor."""
62        return self._pid
63
64    def _update_with(self, new_state: Dict[str, FloatValue]) -> None:
65        """Update the state of the motor with new values from the provided state dictionary.
66
67        Args:
68            new_state: A dictionary containing the new state values for the axis. The keys should include
69                "temperature", "speed_limit", "torque_limit", "compliant", and "pid", with corresponding
70                FloatValue objects as values.
71        """
72        self._temperature = new_state["temperature"].value
73        self._speed_limit = new_state["speed_limit"].value * 100  # received value in [0, 1]
74        self._torque_limit = new_state["torque_limit"].value * 100  # received value in [0, 1]
75        self._compliant = new_state["compliant"].value
76        self._pid = unwrapped_pid_value(new_state["pid"])

The OrbitaMotor class represents any Orbita3d or Orbita2d motor.

The OrbitaMotor class is used to store the up-to-date state of the motor, especially:

  • its temperature (RO)
  • its compliancy (RO)
  • its speed limit (RW)
  • its torque limit (RW)
  • its pid (RW)
OrbitaMotor(initial_state: Dict[str, Any], actuator: Any)
27    def __init__(self, initial_state: Dict[str, Any], actuator: Any) -> None:
28        """Initialize the motor with its initial state.
29
30        Args:
31            initial_state: A dictionary containing the initial state values for the motor. The keys should include
32                "temperature", "speed_limit", "torque_limit", "compliant", and "pid", with corresponding
33                FloatValue objects as values.
34            actuator: The actuator to which the motor belongs.
35        """
36        self._actuator = actuator
37        self._update_with(initial_state)

Initialize the motor with its initial state.

Arguments:
  • initial_state: A dictionary containing the initial state values for the motor. The keys should include "temperature", "speed_limit", "torque_limit", "compliant", and "pid", with corresponding FloatValue objects as values.
  • actuator: The actuator to which the motor belongs.
speed_limit: float
39    @property
40    def speed_limit(self) -> float:
41        """Get the speed limit of the motor, as a percentage of the max allowed speed, rounded to three decimal places."""
42        return float(np.round(self._speed_limit, 3))

Get the speed limit of the motor, as a percentage of the max allowed speed, rounded to three decimal places.

temperature: float
44    @property
45    def temperature(self) -> float:
46        """Get the current temperature of the motor in Celsius degrees."""
47        return float(self._temperature)

Get the current temperature of the motor in Celsius degrees.

torque_limit: float
49    @property
50    def torque_limit(self) -> float:
51        """Get the torque limit of the axis, as a percentage of the max allowed speed, rounded to three decimal places."""
52        return float(np.round(self._torque_limit, 3))

Get the torque limit of the axis, as a percentage of the max allowed speed, rounded to three decimal places.

compliant: float
54    @property
55    def compliant(self) -> float:
56        """Get the compliance status of the motor."""
57        return float(self._compliant)

Get the compliance status of the motor.

pid: component_pb2.PIDGains
59    @property
60    def pid(self) -> PIDGains:
61        """Get the PID gains of the motor."""
62        return self._pid

Get the PID gains of the motor.