From 97baf5a702d603fa0c1304c459cc1263ed7c2e8f Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 31 Mar 2011 16:55:59 -0400 Subject: [PATCH] Add backlash_safe to step_relative().' --- stepper.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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) -- 2.26.2