better stepper control, endstops
This commit is contained in:
parent
7d8d301b78
commit
c10cdf3351
72
stepper.py
72
stepper.py
|
@ -4,43 +4,51 @@ from artiq.experiment import *
|
||||||
class Stepper(EnvExperiment):
|
class Stepper(EnvExperiment):
|
||||||
def build(self):
|
def build(self):
|
||||||
self.setattr_device("core")
|
self.setattr_device("core")
|
||||||
self.setattr_device("ttl0")
|
self.step_right = self.get_device("ttl0")
|
||||||
self.setattr_device("ttl1")
|
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
|
@kernel
|
||||||
def run(self):
|
def run(self):
|
||||||
self.core.reset()
|
self.core.reset()
|
||||||
while True:
|
|
||||||
delay(5*ms)
|
#full_range = self.calibrate_full_range()
|
||||||
for i in range(4000):
|
full_range = 186900
|
||||||
self.ttl0.pulse(5*us)
|
used_range = int(0.9*full_range)
|
||||||
delay(5*us)
|
self.core.break_realtime()
|
||||||
for i in range(4000):
|
self.home()
|
||||||
self.ttl0.pulse(2*us)
|
|
||||||
delay(2*us)
|
for i in range((full_range - used_range)//2):
|
||||||
for i in range(100000):
|
self.step_left.pulse(5*us)
|
||||||
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*us)
|
||||||
|
|
||||||
delay(5*ms)
|
while True:
|
||||||
for i in range(4000):
|
for i in range(full_range):
|
||||||
self.ttl1.pulse(5*us)
|
self.step_left.pulse(5*us)
|
||||||
delay(5*us)
|
delay(5*us)
|
||||||
for i in range(4000):
|
delay(50*ms)
|
||||||
self.ttl1.pulse(2*us)
|
|
||||||
delay(2*us)
|
for i in range(full_range):
|
||||||
for i in range(100000):
|
self.step_right.pulse(5*us)
|
||||||
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(5*us)
|
delay(5*us)
|
||||||
|
delay(50*ms)
|
||||||
|
|
Loading…
Reference in New Issue