Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi.GPIO as GPIO
- from time import sleep
- class Bipolar_Stepper_Motor:
- def __init__(self,step_pin,dir_pin,limit_pin,backlash=0): #initializing some basic stuff to keep track of things
- GPIO.setmode(GPIO.BOARD)
- self.position=0
- self.step_pin=step_pin
- self.dir_pin=dir_pin
- GPIO.setup(self.step_pin,GPIO.OUT)
- GPIO.setup(self.dir_pin,GPIO.OUT)
- self.limit_pin=limit_pin
- self.backlash=backlash
- def move(self,steps,direction,duration):
- if steps==0: #don't do anything!
- return 0
- else:
- interval=duration/(steps*1.0) #divide time into time in between step
- if direction==1: #change int direction to EasyDriver direction input
- GPIO.output(self.dir_pin,0)
- elif direction==-1:
- GPIO.output(self.dir_pin,1)
- else:
- print "Bipolar Stepper Motor class move function got a bad direction value!"
- for step in xrange(steps):#xrange is leaner and meaner for # iterations than range
- GPIO.output(self.step_pin,1)#do a step
- sleep(interval/2.0) #wait half the time
- GPIO.output(self.step_pin,0)#the step is done
- self.position+=direction
- sleep(interval/2.0)#finish sleeping - this is the time between low and high pulse
- def correctBacklash(self,new_dir):
- if new_dir==1:#change int direction to EasyDriver-friendly direction
- GPIO.output(self.dir_pin,0)
- elif new_dir==-1:
- GPIO.output(self.dir_pin,1)
- else:
- print "Bipolar Stepper Motor class correctBacklash function got a bad direction value!"
- for step in range(self.backlash):#do steps, but don't update position - the axis hasn't moved
- GPIO.output(self.step_pin,1)
- sleep(0.00005)
- GPIO.output(self.step_pin,0)
- sleep(0.00005)
- print "Corrected for some axis backlash."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement