Add backlash_safe to step_relative().'
authorW. Trevor King <wking@drexel.edu>
Thu, 31 Mar 2011 20:55:59 +0000 (16:55 -0400)
committerW. Trevor King <wking@drexel.edu>
Thu, 31 Mar 2011 20:55:59 +0000 (16:55 -0400)
stepper.py

index 05325fe7c5ec7a07882044e26f0f5b3894cae6d9..36b52ee79c049e2b65abbe92e5459660ebffea03 100644 (file)
@@ -212,5 +212,18 @@ class Stepper (object):
             LOG.debug('stepping %s -> %s (%s)' % (target_position, self.position, direction))
             self.single_step(direction)
 
-    def step_relative(self, relative_target_position):
-        return self.step_to(self.position + relative_target_position)
+    def step_relative(self, relative_target_position, backlash_safe=False):
+        """Step relative to the current position.
+
+        If `backlash_safe` is `True` and `relative_target_position` is
+        negative, step back an additional `.backlash` half-steps and
+        then come back to the target position.  This takes the slack
+        out of the drive chain and ensures that you actually do move
+        back to the target location.  Note that as the drive chain
+        loosens up after the motion completes, the stepper position
+        will creep forward again.
+        """
+        target = self.position + relative_target_position
+        if backlash_safe and relative_target_position < 0:
+            self.step_to(target - self.backlash)
+        self.step_to(target)