From: W. Trevor King Date: Thu, 31 Mar 2011 20:55:59 +0000 (-0400) Subject: Add backlash_safe to step_relative().' X-Git-Tag: v0.4~8 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=97baf5a702d603fa0c1304c459cc1263ed7c2e8f;p=stepper.git Add backlash_safe to step_relative().' --- diff --git a/stepper.py b/stepper.py index 05325fe..36b52ee 100644 --- a/stepper.py +++ b/stepper.py @@ -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)