Skip to content

Commit

Permalink
Still fixing small bugs in stepper, now tested
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgao committed Oct 18, 2014
1 parent 2a216d4 commit 0d30eb0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions kiln/stepper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import time
import atexit
import threading
import warnings
import Queue

from RPi import GPIO
Expand Down Expand Up @@ -78,7 +79,7 @@ def _step_noblock(self, step, speed):
target = self.phase + step
while self.phase != target:
now = time.time()
self.phase += 1 if target > self.phase else 1
self.phase += 1 if target > self.phase else -1
output = self.pattern[self.phase%len(self.pattern)]
for pin, out in zip(self.pins, output):
GPIO.output(pin, out)
Expand All @@ -89,6 +90,7 @@ def _step_noblock(self, step, speed):
target += step
if block:
self._step(target - self.phase, speed)
self.finished.set()

diff = ispeed - (time.time() - now)
if (diff) > 0:
Expand Down Expand Up @@ -117,7 +119,7 @@ def _step(self, step, speed):


class Regulator(object):
def __init__(self, maxsteps=4500, minsteps=2500, speed=200, ignite_pin=26):
def __init__(self, maxsteps=4500, minsteps=2500, speed=150, ignite_pin=26):
"""Set up a stepper-controlled regulator. Implement some safety measures
to make sure everything gets shut off at the end
Expand Down Expand Up @@ -163,7 +165,7 @@ def off(self, block=True):
self.current = 0

def set(self, value, block=False):
if not 0 < value < 1:
if not 0 <= value <= 1:
raise ValueError("Must give fraction between 0 and 1")
target = int(value * (self.max - self.min) + self.min)
nsteps = target - self.current
Expand Down
4 changes: 2 additions & 2 deletions kiln/test_stepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import stepper

def test_noblock():
reg = Regulator(ignite_pin=None)
reg = stepper.Regulator(ignite_pin=None)

reg.ignite()
reg.set(.5)
time.sleep(.5)
reg.set(.1)
time.sleep(.5)
reg.set(.5, block=True)
return reg
return reg

0 comments on commit 0d30eb0

Please sign in to comment.