aq6140/stepper.py

55 lines
1.5 KiB
Python
Raw Normal View History

2022-08-04 13:56:13 +08:00
from artiq.experiment import *
class Stepper(EnvExperiment):
def build(self):
self.setattr_device("core")
2022-08-11 15:00:43 +08:00
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
2022-08-04 13:56:13 +08:00
@kernel
def run(self):
self.core.reset()
2022-08-11 15:00:43 +08:00
#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)
2022-08-04 13:56:13 +08:00
while True:
2022-08-11 15:13:56 +08:00
for i in range(used_range):
2022-08-11 15:00:43 +08:00
self.step_left.pulse(5*us)
2022-08-04 13:56:13 +08:00
delay(5*us)
2022-08-11 15:00:43 +08:00
delay(50*ms)
2022-08-04 13:56:13 +08:00
2022-08-11 15:13:56 +08:00
for i in range(used_range):
2022-08-11 15:00:43 +08:00
self.step_right.pulse(5*us)
2022-08-04 13:56:13 +08:00
delay(5*us)
2022-08-11 15:00:43 +08:00
delay(50*ms)