web analytics

Servo Widget Example Code 2

Another example using the Servo Widget Class


import servoWidget
import time
import random

master = servoWidget.MasterController("COM5")

random.seed()

while(True):
    # move some servos
    for j in range(0, 8):       # slaves 0 thru 8
        for i in range(0, 6):   # servos 0 thru 6 on each slave
            master.setServoPosition(j, i, random.randint(950, 1000))

    time.sleep(2)
    print "*******************************"

    # get the data returned by the slaves, the first 4 words have packet info
    # the next 3 contain the analog data
    
    for j in range(0, 8):
        data = master.getSlaveData(j)
        for d in data:
            print ord(d),
        print

    # and move the servos again
    for j in range(0, 8):
        for i in range(0, 6):
            master.setServoPosition(j, i, random.randint(1700, 2200))

    time.sleep(2)

master.closeMaster()