aq6140/stepper.py

55 lines
1.5 KiB
Python

from artiq.experiment import *
class Stepper(EnvExperiment):
def build(self):
self.setattr_device("core")
self.step_right = self.get_device("ttl0")
self.step_left = self.get_device("ttl1")
self.endstop_right = self.get_device("ttl4")
self.endstop_left = self.get_device("ttl5")
@kernel
def home(self):
while not self.endstop_right.sample_get_nonrt():
delay(5*ms)
for i in range(4000):
self.step_right.pulse(5*us)
delay(5*us)
while self.endstop_right.sample_get_nonrt():
self.step_left.pulse(5*us)
@kernel
def calibrate_full_range(self):
self.home()
full_range = 0
while not self.endstop_left.sample_get_nonrt():
self.step_left.pulse(5*us)
full_range += 1
return full_range
@kernel
def run(self):
self.core.reset()
#full_range = self.calibrate_full_range()
full_range = 186900
used_range = int(0.9*full_range)
self.core.break_realtime()
self.home()
for i in range((full_range - used_range)//2):
self.step_left.pulse(5*us)
delay(5*us)
while True:
for i in range(used_range):
self.step_left.pulse(5*us)
delay(5*us)
delay(50*ms)
for i in range(used_range):
self.step_right.pulse(5*us)
delay(5*us)
delay(50*ms)