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)