Advertisement
silver2row

Trying to Understand MotorBridge.py and the Stepper Motor...

Oct 14th, 2020
2,601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.82 KB | None | 0 0
  1. # from: Jiankia Li on MotorBridge.py from Github.com '18 and '15.
  2.  
  3. # Trying to understand my source, their source, and updating it '20.
  4.  
  5. ...
  6.  
  7. # init stepper motor A
  8.     def StepperMotorAInit(self):
  9.         WriteByte(TB_1A_MODE,TB_SPM) #Stepper
  10.         time.sleep(DelayTime)
  11.         WriteHalfWord(TB_1A_DUTY,1000)    # voltage
  12.         time.sleep(DelayTime)
  13.        
  14.     # MoveSteps > 0 CW
  15.     # MoveSteps < 0 CCW
  16.     # StepDelayTime : delay time for every step. uint us
  17.     def StepperMotorAMove(self,MoveSteps,StepDelayTime):
  18.         if MoveSteps > 0:
  19.             WriteByte(TB_1A_DIR,TB_CW)   #CW
  20.         else:
  21.             WriteByte(TB_1A_DIR,TB_CCW)   #CW
  22.             MoveSteps = -MoveSteps
  23.         time.sleep(DelayTime)    
  24.         WriteOneWord(TB_1A_SPM_SPEED,StepDelayTime)  # unit us
  25.         time.sleep(DelayTime)
  26.         WriteOneWord(TB_1A_SPM_STEP,MoveSteps)
  27.         time.sleep(DelayTime)
  28.  
  29. ...
  30.  
  31. # from Jiankia Li on the Stepper.py source '15.
  32.  
  33. # And...again! Me trying to understand the source to make my ball screw move in accordance with my thinking...'20.
  34.  
  35. import MotorBridge
  36. import time
  37.  
  38. # def StepperMotorATest():
  39.     # print 'Hello From MotorBridge'
  40.     # motor.StepperMotorAInit()
  41.     # motor.StepperMotorAMove(1000,1000) # 1000 steppers  1000us every step
  42.     # time.sleep(1)
  43.     # motor.StepperMotorAMove(-1000,1000) # 1000 steppers  1000us every step
  44.     # time.sleep(1)
  45.    
  46. def StepperMotorBTest():
  47.     print('Movement!')
  48.     motor.StepperMotorBInit()
  49.     motor.StepperMotorBMove(1000,1000) # 1000 steppers  1000us every step
  50.     time.sleep(1)
  51.     motor.StepperMotorBMove(-1000,1000) # 1000 steppers  1000us every step
  52.     time.sleep(1)
  53.  
  54.    
  55. if __name__=="__main__":
  56.     motor = MotorBridge.MotorBridgeCape()
  57.     while True:
  58.         #StepperMotorATest()
  59.         StepperMotorBTest()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement