diff --git a/CHANGELOG.md b/CHANGELOG.md index ca5bdf1..e6e2a67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ This project uses a [CalVer](https://calver.org/) versioning scheme with monthly - `coco-to-yolo` conversion now creates a single polygon of all disconnected parts of the mask instead of simply taking the first polygon of the list. - Dropped support for python 3.8 and added 3.11 to the testing matrix [#103](https://github.com/airo-ugent/airo-mono/issues/103). - Set python version to 3.10 because of an issue with the `ur_rtde` wheels [#121](https://github.com/airo-ugent/airo-mono/issues/121). Updated README.md to reflect this change. +- `URrtde` will now try connecting to do control interface up to 3 times before raising a `RuntimeError`. ### Fixed - Fixed bug in `get_colored_point_cloud()` that removed some points see issue #25. diff --git a/airo-robots/airo_robots/manipulators/hardware/ur_rtde.py b/airo-robots/airo_robots/manipulators/hardware/ur_rtde.py index 18500f9..4b857cb 100644 --- a/airo-robots/airo_robots/manipulators/hardware/ur_rtde.py +++ b/airo-robots/airo_robots/manipulators/hardware/ur_rtde.py @@ -7,6 +7,7 @@ from airo_robots.manipulators.position_manipulator import ManipulatorSpecs, PositionManipulator from airo_spatial_algebra import SE3Container from airo_typing import HomogeneousMatrixType, JointConfigurationType +from loguru import logger from rtde_control import RTDEControlInterface from rtde_receive import RTDEReceiveInterface @@ -44,14 +45,23 @@ def __init__( ) -> None: super().__init__(manipulator_specs, gripper) self.ip_address = ip_address - try: - self.rtde_control = RTDEControlInterface(self.ip_address) - self.rtde_receive = RTDEReceiveInterface(self.ip_address) - except RuntimeError: - raise RuntimeError( - "Could not connect to the robot. Is the robot in remote control? Is the IP correct? Is the network connection ok?" - ) + max_connection_attempts = 3 + for connection_attempt in range(max_connection_attempts): + try: + self.rtde_control = RTDEControlInterface(self.ip_address) + self.rtde_receive = RTDEReceiveInterface(self.ip_address) + break + except RuntimeError as e: + logger.warning( + f"Failed to connect to RTDE. Retrying... (Attempt {connection_attempt + 1}/{max_connection_attempts}). Error:\n{e}" + ) + if connection_attempt == max_connection_attempts - 1: + raise RuntimeError( + "Could not connect to the robot. Is the robot in remote control? Is the IP correct? Is the network connection ok?" + ) + else: + time.sleep(1.0) self.default_linear_acceleration = 1.2 # m/s^2 self.default_leading_axis_joint_acceleration = 1.2 # rad/s^2