Fix soft-jump bailout logic when we don't know the current position.
authorW. Trevor King <wking@drexel.edu>
Fri, 16 Mar 2012 04:18:38 +0000 (00:18 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 16 Mar 2012 04:18:38 +0000 (00:18 -0400)
pypiezo/base.py

index 2e59e60f46bec1e5ea95964a4336d9a0d638e12c..3be164f666a1309e699843b63e65b4c746fd9e19 100644 (file)
@@ -741,7 +741,8 @@ class Piezo (object):
 
     def jump(self, axis_name, position, steps=1, sleep=None):
         "Move the output named `axis_name` to `position`."
-        _LOG.debug('jump %s to %s in %d steps' % (axis_name, position, steps))
+        _LOG.debug('jump {} to {} in {} steps'.format(
+                axis_name, position, steps))
         if steps > 1:
             try:
                 orig_pos = self.last_output[axis_name]
@@ -750,9 +751,12 @@ class Piezo (object):
                     ("cannot make a soft jump to {} because we don't have a "
                      'last-output position for {}').format(
                         position, axis_name))
-                steps = 1
+                return self.jump(axis_name=axis_name, position=position)
             else:
-                for pos in _numpy.linspace(orig_pos, position, steps+1)[1:]:
+                for i,pos in enumerate(_numpy.linspace(
+                        orig_pos, position, steps+1))[1:]:
+                    _LOG.debug('jump {} to {} ({} of {} steps)'.format(
+                            axis_name, pos, i, steps))
                     self.jump(axis_name=axis_name, position=pos)
                     if sleep:
                         _sleep(sleep)