def TB_Startup(): # Setup the ThunderBorg TB = ThunderBorg.ThunderBorg() # TB.i2cAddress = 0x15 # Uncomment and change the value if you have changed the board address TB.Init() if not TB.foundChip: boards = ThunderBorg.ScanForThunderBorg() if len(boards) == 0: print 'No ThunderBorg found, check you are attached :)' else: print 'No ThunderBorg at address %02X, but we did find boards:' % TB.i2cAddress for board in boards: print ' %02X (%d)' % (board, board) print 'If you need to change the I²C address change the setup line so it is correct, e.g.' print 'TB.i2cAddress = 0x%02X' % (boards[0]) sys.exit() # Ensure the communications failsafe has been enabled! failsafe = False for i in range(5): TB.SetCommsFailsafe(True) failsafe = TB.GetCommsFailsafe() if failsafe: break if not failsafe: print 'Board %02X failed to report in failsafe mode!' % TB.i2cAddress sys.exit() return TB
def init(self): # Init ThunderBorg self.TB = ThunderBorg.ThunderBorg() self.TB.Init() if not self.TB.foundChip: boards = ThunderBorg.ScanForThunderBorg() if len(boards) == 0: print('No ThunderBorg found, check you are attached :)') else: print( 'No ThunderBorg at address %02X, but we did find boards:' % (TB.i2cAddress)) for board in boards: print(' %02X (%d)' % (board, board)) print( 'If you need to change the IC address change the setup line so it is correct, e.g.' ) print('TB.i2cAddress = 0x%02X' % (boards[0])) sys.exit() self.TB.SetCommsFailsafe(False) # Disable the communications failsafe self.TB.SetLedShowBattery(False) # Init action values self.Forward = False self.Backward = False self.Left = False self.Right = False # Init the Camera self.camera = cv2.VideoCapture(0)
def __init__(self): self.TB = ThunderBorg.ThunderBorg() self.TB.i2cAddress = 10 self.motorControlEnabled = False self.TB.Init() if not self.TB.foundChip: boards = ThunderBorg.ScanForThunderBorg() if len(boards) == 0: print 'no ThunderBorg found. check you are attached..' else: print 'no ThunderBorg at address %02X. but we did find boards:' % ( TB.i2cAddress) for board in boards: print ' %02X (%d)' % (board, board) print 'if you need to change the I2C address change the setup line so it is correct, e.g.' print 'TB.i2cAddress = 0x%02X' % (boards[0]) raise Exception('init motor control failed') self.enable()
def __init__(self, i2cAddress, maxPower, holdingPower, stepDelay): # Order for stepping when moving self.sequence = [ [+maxPower, +maxPower], [+maxPower, -maxPower], [-maxPower, -maxPower], [-maxPower, +maxPower]] # Order for stepping when holding self.sequenceHold = [ [+holdingPower, +holdingPower], [+holdingPower, -holdingPower], [-holdingPower, -holdingPower], [-holdingPower, +holdingPower]] # Init motor self.motor = ThunderBorg.ThunderBorg() self.motor.i2cAddress = i2cAddress self.motor.Init() # Exit if motor initialization failed if not self.motor.foundChip: boards = ThunderBorg.ScanForThunderBorg() if len(boards) == 0: print 'No ThunderBorg found, check you are attached :)' else: print 'No ThunderBorg at address %02X, but we did find boards:' % (self.motor.i2cAddress) for board in boards: print ' %02X (%d)' % (board, board) print 'If you need to change the IC address change the setup line so it is correct, e.g.' print 'TB.i2cAddress = 0x%02X' % (boards[0]) sys.exit(-1) # Init rest variables self.degPerStep = 1.8 self.stepDelay = stepDelay self.step = -1
#!/usr/bin/env python # coding: latin-1 # Import library functions we need import ThunderBorg import Tkinter import sys # Setup the ThunderBorg global TB TB = ThunderBorg.ThunderBorg() # Create a new ThunderBorg object #TB.i2cAddress = 0x15 # Uncomment and change the value if you have changed the board address TB.Init() # Set the board up (checks the board is connected) if not TB.foundChip: boards = ThunderBorg.ScanForThunderBorg() if len(boards) == 0: print 'No ThunderBorg found, check you are attached :)' else: print 'No ThunderBorg at address %02X, but we did find boards:' % ( TB.i2cAddress) for board in boards: print ' %02X (%d)' % (board, board) print 'If you need to change the I²C address change the setup line so it is correct, e.g.' print 'TB.i2cAddress = 0x%02X' % (boards[0]) sys.exit() # Class representing the GUI dialog class ThunderBorg_tk(Tkinter.Tk): # Constructor (called when the object is first created) def __init__(self, parent):
def setupTB(address=0x15): """Function for setting up a thunderborg. Tries to setup a TB instance from the given I2C address, informs if set up failed""" # Setup a thunderborg instance TB = ThunderBorg.ThunderBorg() # Set the I2C address TB.i2cAddress = address # Initialize TB.Init() # Inform if no board at address if not TB.foundChip: boards = ThunderBorg.ScanForThunderBorg() if len(boards) == 0: print 'No ThunderBorg found, check you are attached' else: print 'No ThunderBorg at address %02X, but we did find boards:' % ( TB.i2cAddress) for board in boards: print ' %02X (%d)' % (board, board) print 'If you need to change the I²C address change the setup line so it is correct, e.g.' print 'TB.i2cAddress = 0x%02X' % (boards[0]) sys.exit() # Ensure the communcations failsafe had been enabled failsafe = False for i in range(5): TB.SetCommsFailsafe(True) failsafe = TB.GetCommsFailsafe() if failsafe: break if not failsafe: print 'Board %02X failed to report in failsafe mode!' % ( ThunderBorg.i2cAddress) sys.exit() # # Power settings # voltageIn = 1.2 * 10 # Total battery voltage to the ThunderBorg # voltageOut = 12.0 * 0.95 # Maximum motor voltage, we limit it to 95% to allow the RPi to get uninterrupted power # # # Setup the power limits # if voltageOut > voltageIn: # maxPower = 1.0 # else: # maxPower = voltageOut / float(voltageIn) # # Show battery monitoring settings # battMin, battMax = TB.GetBatteryMonitoringLimits() # print 'Battery monitoring settings:' # print ' Minimum (red) %02.2f V' % (battMin) # print ' Half-way (yellow) %02.2f V' % ((battMin + battMax) / 2) # print ' Maximum (green) %02.2f V' % (battMax) # print battCurrent = TB.GetBatteryReading() print ' Current voltage %02.2f V' % (battCurrent) print # Turn off battery mode for leds TB.SetLedShowBattery(False) TB.SetLeds(0, 0, 1) # Make sure the motors are off TB.MotorsOff() return TB