Skip to content

Commit fd2f34a

Browse files
committed
swift import
1 parent 0510654 commit fd2f34a

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

roboticstoolbox/backend/Swift/Swift.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,22 @@
99
import spatialmath as sm
1010
import time
1111
from queue import Queue
12-
from swift import start_servers
12+
13+
_sw = None
14+
sw = None
15+
16+
17+
def _import_swift():
18+
import importlib
19+
global sw
20+
try:
21+
sw = importlib.import_module('swift')
22+
# from swift import start_servers
23+
except ImportError:
24+
print(
25+
'\nYou must install the python package swift, see '
26+
'https://github.com/jhavl/swift\n')
27+
raise
1328

1429

1530
class Swift(Connector): # pragma nocover
@@ -59,6 +74,9 @@ def __init__(self, realtime=True, display=True):
5974
self.realtime = realtime
6075
self.display = display
6176

77+
if self.display and sw is None:
78+
_import_swift()
79+
6280
#
6381
# Basic methods to do with the state of the external program
6482
#
@@ -75,7 +93,7 @@ def launch(self):
7593
super().launch()
7694

7795
if self.display:
78-
start_servers(self.outq, self.inq)
96+
sw.start_servers(self.outq, self.inq)
7997
self.last_time = time.time()
8098

8199
def step(self, dt=50):

0 commit comments

Comments
 (0)