Skip to content

Commit 3dcc7d2

Browse files
committed
Refactor RTDE import and installation logic into scoped UR class
1 parent cc53711 commit 3dcc7d2

1 file changed

Lines changed: 25 additions & 23 deletions

File tree

armctl/universal_robots/universal_robots.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,35 @@
22
from armctl.templates import SocketController as SCT
33
from armctl.templates.logger import logger
44

5-
try:
6-
from armctl.universal_robots.protocols.rtde import RTDE
7-
except ImportError:
8-
from subprocess import run
9-
import sys
10-
11-
logger.warning(
12-
"RTDE Python Client Library not found. Installing from GitHub..."
13-
)
14-
run(
15-
[
16-
sys.executable,
17-
"-m",
18-
"pip",
19-
"install",
20-
"--quiet",
21-
"git+https://github.com/UniversalRobots/RTDE_Python_Client_Library.git@main",
22-
],
23-
check=True,
24-
)
25-
from armctl.universal_robots.protocols.rtde import RTDE
26-
275
import math
286
from time import sleep as _sleep
297

30-
318
class UniversalRobots(SCT, Commands):
9+
def _check_rtde(self):
10+
try:
11+
from .protocols.rtde import RTDE
12+
except ImportError:
13+
from subprocess import run
14+
import sys
15+
16+
logger.warning(
17+
"RTDE Python Client Library not found. Installing from GitHub..."
18+
)
19+
run(
20+
[
21+
sys.executable,
22+
"-m",
23+
"pip",
24+
"install",
25+
"--quiet",
26+
"git+https://github.com/UniversalRobots/RTDE_Python_Client_Library.git@main",
27+
],
28+
check=True,
29+
)
30+
from .protocols.rtde import RTDE
31+
3232
def __init__(self, ip: str, port: int | tuple[int, int] = 30_002):
33+
self._check_rtde()
3334
super().__init__(ip, port)
3435
self.JOINT_RANGES = [
3536
(-math.pi, math.pi),
@@ -47,6 +48,7 @@ def __init__(self, ip: str, port: int | tuple[int, int] = 30_002):
4748

4849
def connect(self):
4950
super().connect()
51+
from .protocols.rtde import RTDE
5052
self.rtde = RTDE(self.ip) # Initialize RTDE connection
5153

5254
def disconnect(self):

0 commit comments

Comments
 (0)