Pages

Saturday, June 01, 2013

Moving 2 motors at the same time OK

So I changed the function from moving 1 motor to 2 motors.  It took me 5 minutes to debug.  Now 2 motors move together.


def Test2StepMotors(stepSequence, stepAngle, stepTime, direction, degrees):

    ftprint.PrintDoubleSpaceLine("*** Start testing stepping motor ***")    

    print "Step sequence = ", stepSequence
    print "Step angle = ", stepAngle
    print "Step time = ", stepTime
    print "Direction = ", direction
    print "Degrees = ", degrees

    spiChannel = spidev.SpiDev() 
    spiChannel.open(0, 0) 

    stepCount = int((degrees / stepAngle) * 32) # why not /64 ???

    if (direction == Clockwise):
        for i in range(stepCount):
            for stepPattern in stepSequence:
       stepPattern1 = stepPattern
stepPattern2 = stepPattern << 4
stepPattern3 = stepPattern1 | stepPattern2
spiChannel.xfer2([stepPattern3])
                time.sleep(stepTime)
    else:
        for i in range(stepCount):
            for stepPattern in reversed(stepSequence):
                stepPattern1 = stepPattern
stepPattern2 = stepPattern << 4
stepPattern3 = stepPattern1 | stepPattern2
                spiChannel.xfer2([stepPattern3])
                time.sleep(stepTime)

    spiChannel.close() 

    ftprint.PrintDoubleSpaceLine("*** Stop testing stepping motor ***")

.END

No comments:

Post a Comment