reachy2_sdk.config.reachy_info

ReachyInfo module.

This module provides main informations about the robot.

  1"""ReachyInfo module.
  2
  3This module provides main informations about the robot.
  4"""
  5
  6import logging
  7from typing import Any, Dict, List, Optional
  8
  9import reachy2_sdk_api
 10from reachy2_sdk_api.reachy_pb2 import Reachy, ReachyCoreMode
 11
 12from ..parts.mobile_base import MobileBase
 13
 14
 15class ReachyInfo:
 16    """The ReachyInfo class saves information of the global robot.
 17
 18    The ReachyInfo class gives access to informations that won't be modified during the session:
 19        the robot's hardware version
 20        the robot's core software version
 21        the robot's configuration
 22        the robot's serial_number
 23    But also to the battery voltage.
 24    """
 25
 26    def __init__(self, reachy: Reachy) -> None:
 27        """Initialize the ReachyInfo instance with robot details.
 28
 29        Args:
 30            reachy: The Reachy robot object, which provides the robot's info and configuration details.
 31        """
 32        self._logger = logging.getLogger(__name__)
 33        self._robot_serial_number: str = reachy.info.serial_number
 34
 35        self._hardware_version: str = reachy.info.version_hard
 36        self._core_software_version: str = reachy.info.version_soft
 37
 38        try:
 39            self._robot_api_version: Optional[str] = reachy.info.api_version if reachy.info.api_version else None
 40            self._check_api_compatibility()
 41        except AttributeError:
 42            self._robot_api_version = None
 43            self._logger.warning(
 44                "Your local API version is below the required version for reachy2_sdk."
 45                "\nPlease update the reachy2_sdk_api package to ensure compatibility."
 46            )
 47
 48        self._enabled_parts: Dict[str, Any] = {}
 49        self._disabled_parts: List[str] = []
 50        self._mobile_base: Optional[MobileBase] = None
 51
 52        self._mode: ReachyCoreMode = reachy.info.core_mode
 53
 54        self._set_config(reachy)
 55
 56    def _check_api_compatibility(self) -> None:
 57        """Check the compatibility of the API versions between the robot and the SDK."""
 58        if self._robot_api_version is None:
 59            self._logger.warning(
 60                "The robot's API version is below your local API version."
 61                "\nSome features may not work properly."
 62                "\nPlease update the reachy2_core image on the robot to ensure compatibility."
 63                " or downgrade your local reachy2_sdk package."
 64            )
 65        elif reachy2_sdk_api.__version__ != self._robot_api_version:
 66            local_version = reachy2_sdk_api.__version__.split(".")
 67            robot_version = self._robot_api_version.split(".")
 68            for local, remote in zip(local_version, robot_version):
 69                if int(local) > int(remote):
 70                    self._logger.warning(
 71                        f"Local API version ({reachy2_sdk_api.__version__}) is different"
 72                        f" from the robot's API version ({self._robot_api_version})."
 73                        f"\nSome features may not work properly."
 74                        f"\nPlease update the reachy2_core image on the robot to ensure compatibility,"
 75                        f" or downgrade your local reachy2_sdk package."
 76                    )
 77                    break
 78                elif int(local) < int(remote):
 79                    self._logger.warning(
 80                        f"Local API version ({reachy2_sdk_api.__version__}) is different"
 81                        f" from the robot's API version ({self._robot_api_version})."
 82                        f"\nSome features may not work properly."
 83                        f"\nPlease update your local reachy2_sdk package to ensure compatibility."
 84                    )
 85                    break
 86
 87    def _set_config(self, msg: Reachy) -> None:
 88        """Determine the robot's configuration.
 89
 90        Sets the configuration string to indicate whether the robot is a full kit, starter kit
 91        (with left or right arm), or a custom configuration. Also accounts for the presence of a mobile base.
 92
 93        Args:
 94            msg: The Reachy instance containing the current configuration of the robot.
 95        """
 96        self.config: str = ""
 97
 98        mobile_base_presence = ""
 99        if msg.HasField("mobile_base"):
100            mobile_base_presence = " with mobile_base"
101        if msg.HasField("head"):
102            if msg.HasField("l_arm") and msg.HasField("r_arm"):
103                self.config = "full_kit" + mobile_base_presence
104            elif msg.HasField("l_arm"):
105                self.config = "starter_kit (left arm)" + mobile_base_presence
106            else:
107                self.config = "starter_kit (right arm)" + mobile_base_presence
108        else:
109            self.config = "custom_config"
110
111    def _set_mobile_base(self, mobile_base: MobileBase) -> None:
112        """Set the mobile base for the robot.
113
114        Args:
115            mobile_base: The MobileBase instance to associate with the robot.
116        """
117        self._mobile_base = mobile_base
118
119    def __repr__(self) -> str:
120        """Clean representation of a ReachyInfo."""
121        repr_template = (
122            '<ReachyInfo mode="{mode}" \n'
123            ' robot_serial_number="{serial_number}" \n'
124            ' hardware_version="{hardware_version}" \n'
125            ' core_software_version="{software_version}" \n'
126            ' robot_api_version="{api_version}" \n'
127            " battery_voltage={battery_voltage} >"
128        )
129        return repr_template.format(
130            mode=self.mode,
131            serial_number=self.robot_serial_number,
132            hardware_version=self.hardware_version,
133            software_version=self.core_software_version,
134            api_version=self._robot_api_version,
135            battery_voltage=self.battery_voltage,
136        )
137
138    @property
139    def battery_voltage(self) -> float:
140        """Get the battery voltage of the mobile base.
141
142        If the mobile base is present, returns its battery voltage. Otherwise, returns a default full
143        battery value.
144        """
145        if self._mobile_base is not None:
146            # ToDo : https://github.com/pollen-robotics/mobile-base-sdk/issues/18
147            # and removing cast
148            return (float)(self._mobile_base.battery_voltage)
149        return 30.0
150
151    @property
152    def robot_serial_number(self) -> str:
153        """Returns the robot's serial number."""
154        return self._robot_serial_number
155
156    @property
157    def hardware_version(self) -> str:
158        """Returns the robot's hardware version."""
159        return self._hardware_version
160
161    @property
162    def core_software_version(self) -> str:
163        """Returns the robot's core software version."""
164        return self._core_software_version
165
166    @property
167    def mode(self) -> str:
168        """Returns the robot's core mode.
169
170        Can be either "FAKE", "REAL" or "GAZEBO".
171        """
172        return str(ReachyCoreMode.keys()[self._mode])
class ReachyInfo:
 16class ReachyInfo:
 17    """The ReachyInfo class saves information of the global robot.
 18
 19    The ReachyInfo class gives access to informations that won't be modified during the session:
 20        the robot's hardware version
 21        the robot's core software version
 22        the robot's configuration
 23        the robot's serial_number
 24    But also to the battery voltage.
 25    """
 26
 27    def __init__(self, reachy: Reachy) -> None:
 28        """Initialize the ReachyInfo instance with robot details.
 29
 30        Args:
 31            reachy: The Reachy robot object, which provides the robot's info and configuration details.
 32        """
 33        self._logger = logging.getLogger(__name__)
 34        self._robot_serial_number: str = reachy.info.serial_number
 35
 36        self._hardware_version: str = reachy.info.version_hard
 37        self._core_software_version: str = reachy.info.version_soft
 38
 39        try:
 40            self._robot_api_version: Optional[str] = reachy.info.api_version if reachy.info.api_version else None
 41            self._check_api_compatibility()
 42        except AttributeError:
 43            self._robot_api_version = None
 44            self._logger.warning(
 45                "Your local API version is below the required version for reachy2_sdk."
 46                "\nPlease update the reachy2_sdk_api package to ensure compatibility."
 47            )
 48
 49        self._enabled_parts: Dict[str, Any] = {}
 50        self._disabled_parts: List[str] = []
 51        self._mobile_base: Optional[MobileBase] = None
 52
 53        self._mode: ReachyCoreMode = reachy.info.core_mode
 54
 55        self._set_config(reachy)
 56
 57    def _check_api_compatibility(self) -> None:
 58        """Check the compatibility of the API versions between the robot and the SDK."""
 59        if self._robot_api_version is None:
 60            self._logger.warning(
 61                "The robot's API version is below your local API version."
 62                "\nSome features may not work properly."
 63                "\nPlease update the reachy2_core image on the robot to ensure compatibility."
 64                " or downgrade your local reachy2_sdk package."
 65            )
 66        elif reachy2_sdk_api.__version__ != self._robot_api_version:
 67            local_version = reachy2_sdk_api.__version__.split(".")
 68            robot_version = self._robot_api_version.split(".")
 69            for local, remote in zip(local_version, robot_version):
 70                if int(local) > int(remote):
 71                    self._logger.warning(
 72                        f"Local API version ({reachy2_sdk_api.__version__}) is different"
 73                        f" from the robot's API version ({self._robot_api_version})."
 74                        f"\nSome features may not work properly."
 75                        f"\nPlease update the reachy2_core image on the robot to ensure compatibility,"
 76                        f" or downgrade your local reachy2_sdk package."
 77                    )
 78                    break
 79                elif int(local) < int(remote):
 80                    self._logger.warning(
 81                        f"Local API version ({reachy2_sdk_api.__version__}) is different"
 82                        f" from the robot's API version ({self._robot_api_version})."
 83                        f"\nSome features may not work properly."
 84                        f"\nPlease update your local reachy2_sdk package to ensure compatibility."
 85                    )
 86                    break
 87
 88    def _set_config(self, msg: Reachy) -> None:
 89        """Determine the robot's configuration.
 90
 91        Sets the configuration string to indicate whether the robot is a full kit, starter kit
 92        (with left or right arm), or a custom configuration. Also accounts for the presence of a mobile base.
 93
 94        Args:
 95            msg: The Reachy instance containing the current configuration of the robot.
 96        """
 97        self.config: str = ""
 98
 99        mobile_base_presence = ""
100        if msg.HasField("mobile_base"):
101            mobile_base_presence = " with mobile_base"
102        if msg.HasField("head"):
103            if msg.HasField("l_arm") and msg.HasField("r_arm"):
104                self.config = "full_kit" + mobile_base_presence
105            elif msg.HasField("l_arm"):
106                self.config = "starter_kit (left arm)" + mobile_base_presence
107            else:
108                self.config = "starter_kit (right arm)" + mobile_base_presence
109        else:
110            self.config = "custom_config"
111
112    def _set_mobile_base(self, mobile_base: MobileBase) -> None:
113        """Set the mobile base for the robot.
114
115        Args:
116            mobile_base: The MobileBase instance to associate with the robot.
117        """
118        self._mobile_base = mobile_base
119
120    def __repr__(self) -> str:
121        """Clean representation of a ReachyInfo."""
122        repr_template = (
123            '<ReachyInfo mode="{mode}" \n'
124            ' robot_serial_number="{serial_number}" \n'
125            ' hardware_version="{hardware_version}" \n'
126            ' core_software_version="{software_version}" \n'
127            ' robot_api_version="{api_version}" \n'
128            " battery_voltage={battery_voltage} >"
129        )
130        return repr_template.format(
131            mode=self.mode,
132            serial_number=self.robot_serial_number,
133            hardware_version=self.hardware_version,
134            software_version=self.core_software_version,
135            api_version=self._robot_api_version,
136            battery_voltage=self.battery_voltage,
137        )
138
139    @property
140    def battery_voltage(self) -> float:
141        """Get the battery voltage of the mobile base.
142
143        If the mobile base is present, returns its battery voltage. Otherwise, returns a default full
144        battery value.
145        """
146        if self._mobile_base is not None:
147            # ToDo : https://github.com/pollen-robotics/mobile-base-sdk/issues/18
148            # and removing cast
149            return (float)(self._mobile_base.battery_voltage)
150        return 30.0
151
152    @property
153    def robot_serial_number(self) -> str:
154        """Returns the robot's serial number."""
155        return self._robot_serial_number
156
157    @property
158    def hardware_version(self) -> str:
159        """Returns the robot's hardware version."""
160        return self._hardware_version
161
162    @property
163    def core_software_version(self) -> str:
164        """Returns the robot's core software version."""
165        return self._core_software_version
166
167    @property
168    def mode(self) -> str:
169        """Returns the robot's core mode.
170
171        Can be either "FAKE", "REAL" or "GAZEBO".
172        """
173        return str(ReachyCoreMode.keys()[self._mode])

The ReachyInfo class saves information of the global robot.

The ReachyInfo class gives access to informations that won't be modified during the session: the robot's hardware version the robot's core software version the robot's configuration the robot's serial_number But also to the battery voltage.

ReachyInfo(reachy: reachy_pb2.Reachy)
27    def __init__(self, reachy: Reachy) -> None:
28        """Initialize the ReachyInfo instance with robot details.
29
30        Args:
31            reachy: The Reachy robot object, which provides the robot's info and configuration details.
32        """
33        self._logger = logging.getLogger(__name__)
34        self._robot_serial_number: str = reachy.info.serial_number
35
36        self._hardware_version: str = reachy.info.version_hard
37        self._core_software_version: str = reachy.info.version_soft
38
39        try:
40            self._robot_api_version: Optional[str] = reachy.info.api_version if reachy.info.api_version else None
41            self._check_api_compatibility()
42        except AttributeError:
43            self._robot_api_version = None
44            self._logger.warning(
45                "Your local API version is below the required version for reachy2_sdk."
46                "\nPlease update the reachy2_sdk_api package to ensure compatibility."
47            )
48
49        self._enabled_parts: Dict[str, Any] = {}
50        self._disabled_parts: List[str] = []
51        self._mobile_base: Optional[MobileBase] = None
52
53        self._mode: ReachyCoreMode = reachy.info.core_mode
54
55        self._set_config(reachy)

Initialize the ReachyInfo instance with robot details.

Arguments:
  • reachy: The Reachy robot object, which provides the robot's info and configuration details.
battery_voltage: float
139    @property
140    def battery_voltage(self) -> float:
141        """Get the battery voltage of the mobile base.
142
143        If the mobile base is present, returns its battery voltage. Otherwise, returns a default full
144        battery value.
145        """
146        if self._mobile_base is not None:
147            # ToDo : https://github.com/pollen-robotics/mobile-base-sdk/issues/18
148            # and removing cast
149            return (float)(self._mobile_base.battery_voltage)
150        return 30.0

Get the battery voltage of the mobile base.

If the mobile base is present, returns its battery voltage. Otherwise, returns a default full battery value.

robot_serial_number: str
152    @property
153    def robot_serial_number(self) -> str:
154        """Returns the robot's serial number."""
155        return self._robot_serial_number

Returns the robot's serial number.

hardware_version: str
157    @property
158    def hardware_version(self) -> str:
159        """Returns the robot's hardware version."""
160        return self._hardware_version

Returns the robot's hardware version.

core_software_version: str
162    @property
163    def core_software_version(self) -> str:
164        """Returns the robot's core software version."""
165        return self._core_software_version

Returns the robot's core software version.

mode: str
167    @property
168    def mode(self) -> str:
169        """Returns the robot's core mode.
170
171        Can be either "FAKE", "REAL" or "GAZEBO".
172        """
173        return str(ReachyCoreMode.keys()[self._mode])

Returns the robot's core mode.

Can be either "FAKE", "REAL" or "GAZEBO".