better stepper control, endstops

This commit is contained in:
Sebastien Bourdeauducq 2022-08-11 15:00:43 +08:00
parent 7d8d301b78
commit c10cdf3351
1 changed files with 41 additions and 33 deletions

View File

@ -4,43 +4,51 @@ from artiq.experiment import *
class Stepper(EnvExperiment):
def build(self):
self.setattr_device("core")
self.setattr_device("ttl0")
self.setattr_device("ttl1")
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()
while True:
delay(5*ms)
for i in range(4000):
self.ttl0.pulse(5*us)
delay(5*us)
for i in range(4000):
self.ttl0.pulse(2*us)
delay(2*us)
for i in range(100000):
self.ttl0.pulse(1*us)
delay(1*us)
for i in range(4000):
self.ttl0.pulse(2*us)
delay(2*us)
for i in range(4000):
self.ttl0.pulse(5*us)
delay(5*us)
delay(5*ms)
for i in range(4000):
self.ttl1.pulse(5*us)
#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(full_range):
self.step_left.pulse(5*us)
delay(5*us)
for i in range(4000):
self.ttl1.pulse(2*us)
delay(2*us)
for i in range(100000):
self.ttl1.pulse(1*us)
delay(1*us)
for i in range(4000):
self.ttl1.pulse(2*us)
delay(2*us)
for i in range(4000):
self.ttl1.pulse(5*us)
delay(50*ms)
for i in range(full_range):
self.step_right.pulse(5*us)
delay(5*us)
delay(50*ms)