Skip to content

Commit 4c115d0

Browse files
authored
Merge pull request #52 from CleoQc/master
import libraries on a computer that doesn't have the hardware
2 parents 31ec446 + 03e5624 commit 4c115d0

File tree

2 files changed

+26
-40
lines changed

2 files changed

+26
-40
lines changed

Software/Python/easygopigo3.py

+12-33
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@
77
# import tty
88
# import select
99
import time
10-
import gopigo3
10+
hardware_connected = True
11+
try:
12+
import gopigo3
13+
except ImportError:
14+
hardware_connected = False
15+
print("Cannot import gopigo3 library")
16+
except Exception as e:
17+
hardware_connected = False
18+
print("Unknown issue while importing gopigo3")
19+
print(e)
20+
1121

1222
# from datetime import datetime
1323

@@ -290,40 +300,9 @@ def turn_degrees(self, degrees, blocking=False):
290300
StartPositionRight - WheelTurnDegrees) is False:
291301
time.sleep(0.1)
292302

293-
# the following functions may be redundant
294-
my_gpg = EasyGoPiGo3()
295-
296-
297-
# these functions are here because we need direct access to these
298-
# for the Drive functionality in Sam
299-
# they do not need locking as the fct they call handles that.
300-
def volt():
301-
return_value = my_gpg.volt()
302-
return return_value
303-
304-
305-
def stop():
306-
my_gpg.stop()
307-
308-
309-
def forward():
310-
my_gpg.forward()
311-
312-
313-
def backward():
314-
my_gpg.backward()
315-
316-
317-
def left():
318-
my_gpg.left()
319-
320-
321-
def right():
322-
my_gpg.right()
323-
324303

325304
#############################################################
326-
#
305+
# SENSORS
327306
#############################################################
328307

329308

Software/Python/gopigo3.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,27 @@
1010
from __future__ import print_function
1111
from __future__ import division
1212
#from builtins import input
13+
hardware_connected = True
1314

1415
import subprocess # for executing system calls
15-
import spidev
16+
try:
17+
import spidev
18+
import fcntl # for lockf mutex support
19+
except:
20+
hardware_connected = False
21+
print ("Can't import spidev or fcntl")
22+
1623
import math # import math for math.pi constant
17-
import fcntl # for lockf mutex support
1824
import time
1925

2026
FIRMWARE_VERSION_REQUIRED = "0.3.x" # Make sure the top 2 of 3 numbers match
2127

22-
GPG_SPI = spidev.SpiDev()
23-
GPG_SPI.open(0, 1)
24-
GPG_SPI.max_speed_hz = 500000
25-
GPG_SPI.mode = 0b00
26-
GPG_SPI.bits_per_word = 8
28+
if hardware_connected:
29+
GPG_SPI = spidev.SpiDev()
30+
GPG_SPI.open(0, 1)
31+
GPG_SPI.max_speed_hz = 500000
32+
GPG_SPI.mode = 0b00
33+
GPG_SPI.bits_per_word = 8
2734

2835

2936
class Enumeration(object):

0 commit comments

Comments
 (0)