diff --git a/Software/Python/easygopigo3.py b/Software/Python/easygopigo3.py index ac103217..99434b68 100644 --- a/Software/Python/easygopigo3.py +++ b/Software/Python/easygopigo3.py @@ -7,7 +7,17 @@ # import tty # import select import time -import gopigo3 +hardware_connected = True +try: + import gopigo3 +except ImportError: + hardware_connected = False + print("Cannot import gopigo3 library") +except Exception as e: + hardware_connected = False + print("Unknown issue while importing gopigo3") + print(e) + # from datetime import datetime @@ -290,40 +300,9 @@ def turn_degrees(self, degrees, blocking=False): StartPositionRight - WheelTurnDegrees) is False: time.sleep(0.1) -# the following functions may be redundant -my_gpg = EasyGoPiGo3() - - -# these functions are here because we need direct access to these -# for the Drive functionality in Sam -# they do not need locking as the fct they call handles that. -def volt(): - return_value = my_gpg.volt() - return return_value - - -def stop(): - my_gpg.stop() - - -def forward(): - my_gpg.forward() - - -def backward(): - my_gpg.backward() - - -def left(): - my_gpg.left() - - -def right(): - my_gpg.right() - ############################################################# -# +# SENSORS ############################################################# diff --git a/Software/Python/gopigo3.py b/Software/Python/gopigo3.py index 593cd4ba..fe6c13ae 100644 --- a/Software/Python/gopigo3.py +++ b/Software/Python/gopigo3.py @@ -10,20 +10,27 @@ from __future__ import print_function from __future__ import division #from builtins import input +hardware_connected = True import subprocess # for executing system calls -import spidev +try: + import spidev + import fcntl # for lockf mutex support +except: + hardware_connected = False + print ("Can't import spidev or fcntl") + import math # import math for math.pi constant -import fcntl # for lockf mutex support import time FIRMWARE_VERSION_REQUIRED = "0.3.x" # Make sure the top 2 of 3 numbers match -GPG_SPI = spidev.SpiDev() -GPG_SPI.open(0, 1) -GPG_SPI.max_speed_hz = 500000 -GPG_SPI.mode = 0b00 -GPG_SPI.bits_per_word = 8 +if hardware_connected: + GPG_SPI = spidev.SpiDev() + GPG_SPI.open(0, 1) + GPG_SPI.max_speed_hz = 500000 + GPG_SPI.mode = 0b00 + GPG_SPI.bits_per_word = 8 class Enumeration(object):