Monsterjoy.py with 2 thunderborg motorcontrollers?

Hello, i have a question about the monsterjoy.py file. Is there a program with two Thunderborgs?

With kind regards
Thieu

piborg's picture

We do not have an example, but it is fairly easy to make the changes.

First you need to initialise both boards at the top of the script.

# Setup the ThunderBorgs
TB1 = ThunderBorg.ThunderBorg()
TB2 = ThunderBorg.ThunderBorg()
TB1.i2cAddress = 10
TB2.i2cAddress = 11
TB1.Init()
TB2.Init()
if not TB1.foundChip or not TB2.foundChip:
    boards = ThunderBorg.ScanForThunderBorg()
    if len(boards) == 0:
        print 'No ThunderBorg found, check you are attached :)'
    else:
        print 'ThunderBorg missing at address %02X or %02X, but we did find boards:' % (TB1.i2cAddress, TB2.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 'TB1.i2cAddress = 0x%02X' % (boards[0])
    sys.exit()
# Ensure the communications failsafes have been enabled!
failsafe1 = False
failsafe2 = False
for i in range(5):
    TB1.SetCommsFailsafe(True)
    TB2.SetCommsFailsafe(True)
    failsafe1 = TB1.GetCommsFailsafe()
    failsafe2 = TB2.GetCommsFailsafe()
    if failsafe1 and failsafe2:
        break
if not failsafe1:
    print 'Board %02X failed to report in failsafe mode!' % (TB1.i2cAddress)
    sys.exit()
if not failsafe2:
    print 'Board %02X failed to report in failsafe mode!' % (TB2.i2cAddress)
    sys.exit()

Make sure the i2cAddress values match what the boards were set to.

Next you will need to change the motor outputs. Assuming the first ThunderBorg is connected to both right side motors and the second to both left side motors change these lines:

TB.SetMotor1(driveRight * maxPower)
TB.SetMotor2(driveLeft * maxPower)

to:

TB1.SetMotors(driveRight * maxPower)
TB2.SetMotors(driveLeft * maxPower)

Next change the drive fault check so that it includes all four outputs. Change:

if TB.GetDriveFault1() or TB.GetDriveFault2():

to

if TB1.GetDriveFault1() or TB1.GetDriveFault2() or TB2.GetDriveFault1() or TB2.GetDriveFault2():

Now all that needs to be done is to change all of the remaining calls to TB to both TB1 and TB2. For example:

TB.SetLeds(1,0,1)

becomes:

TB1.SetLeds(1,0,1)
TB2.SetLeds(1,0,1)

After all the changes the script should behave like it did before, but using two motor outputs per side ^_^

Thankyou very much, it works perfectly

Subscribe to Comments for "Monsterjoy.py with 2 thunderborg motorcontrollers?"