Pages

Thursday, May 30, 2013

GPi motor moving function writing notes

Now I have added a "direction" parameter to the stepper motor function.

# *****************************************************************************
# Function - Stepping motor
# Description - 
# P1 pin assignment ***
#   P1-01 = Winding 1 (A-)
#   P1-02 = Winding 2 (A+)
#   P1-03 = Winding 3 (B-)
#   P1-04 = Winding 4 (B+) 
# Activation sequences
#   WaveSequence = [1, 3, 2, 4]
#   FullStepSequence =  [[1, 3], [1, 4], [2, 4], [2, 3]]
#   HalfStepSequence =  [[1], [1,4], [4], [2,4], [2], [2,3], [3]] 
# Unipolar Stepping Motor Switching Sequence 
#   Wave sequence = 1 - 3 - 2 - 4 (A-, B-, A+, B+)
#   Full step sequence = 13 - 14 - 24 - 23 (A-B-, A-B+, A+B+, A+B-)
#   Half step sequence  = 13 - 1 - 14 - 4 - 24 - 2 - 23 - 3 
#   One step swing = 1 - 3 - 1 - 3 (A-, B-, A-, B-)
# Motor windings list
#   Winding        A-(1)    A+(2)    B-(3)   B+(4)    COM (+5V)
#   28BYJ48        Pink     Orange   Blue    Yellow   Red  
#   NPM PF35       Black    Yellow   Brown   Orange   Red
#   PX245          Black    Green    Blue    Red      Yelow/White
# Sample call - 
# ftguzuntypi.TestSteppingMotor(direction = ftguzuntypi.Clockwise, 
#                               stepSequence = ftguzuntypi.WaveStepSequence, 
#        sequenceCount = 100, 
#        stepTime = 0.05)
# *****************************************************************************

WaveStepSequence = [0x1, 0x4, 0x2, 0x8]
Clockwise = 0
CounterClockwise = 1

def TestSteppingMotor(direction, stepSequence, sequenceCount, stepTime):

    ftprint.PrintDoubleSpaceLine("*** Start testing stepping motor ***")    
    print "Direction = ", direction
    print "Step sequence = ", stepSequence
    print "SequenceCount = ", sequenceCount
    print "Step time = ", stepTime

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

    for count in range(sequenceCount):
        if (direction == Clockwise):
            for stepPattern in reversed(stepSequence):
                spiChannel.xfer2([stepPattern])
       time.sleep(stepTime)
        else:
            for stepPattern in stepSequence:
                spiChannel.xfer2([stepPattern])
       time.sleep(stepTime)

    spiChannel.close() 

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

No comments:

Post a Comment