From 215bdfe9a05a0a864323a7382c8b78201fe70a60 Mon Sep 17 00:00:00 2001 From: Mathieu De Coster Date: Tue, 8 Oct 2024 13:42:01 +0200 Subject: [PATCH 1/2] Retry RTDE connection multiple times upon failure --- CHANGELOG.md | 1 + .../manipulators/hardware/ur_rtde.py | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) 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..a320328 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,20 @@ 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) + 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?" + ) self.default_linear_acceleration = 1.2 # m/s^2 self.default_leading_axis_joint_acceleration = 1.2 # rad/s^2 From 701dc708d7d804024375e555352ba148bcc0d25d Mon Sep 17 00:00:00 2001 From: Mathieu De Coster Date: Fri, 25 Oct 2024 10:51:28 +0200 Subject: [PATCH 2/2] Break from loop on successful connection Sleep on failure, to give connection attempt some time to reset --- airo-robots/airo_robots/manipulators/hardware/ur_rtde.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/airo-robots/airo_robots/manipulators/hardware/ur_rtde.py b/airo-robots/airo_robots/manipulators/hardware/ur_rtde.py index a320328..4b857cb 100644 --- a/airo-robots/airo_robots/manipulators/hardware/ur_rtde.py +++ b/airo-robots/airo_robots/manipulators/hardware/ur_rtde.py @@ -51,6 +51,7 @@ def __init__( 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}" @@ -59,6 +60,8 @@ def __init__( 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