Fix soft jump handling for unknown `last_output`.
authorW. Trevor King <wking@drexel.edu>
Thu, 15 Mar 2012 11:51:55 +0000 (07:51 -0400)
committerW. Trevor King <wking@drexel.edu>
Thu, 15 Mar 2012 11:51:55 +0000 (07:51 -0400)
Also return after a successful soft jump.  The previous implementation
duplicated the final step.

pypiezo/base.py

index 5fecd642f0a93194d4edf178d362b899ab661f17..3e5a07918aef74047ab480790e5e7bf7e2030f0e 100644 (file)
@@ -524,11 +524,20 @@ class Piezo (object):
         "Move the output named `axis_name` to `position`."
         _LOG.debug('jump %s to %s in %d steps' % (axis_name, position, steps))
         if steps > 1:
-            orig_pos = self.last_output[axis_name]
-            for pos in _numpy.linspace(orig_pos, position, steps+1)[1:]:
-                self.jump(axis_name=axis_name, position=pos)
-                if sleep:
-                    _sleep(sleep)
+            try:
+                orig_pos = self.last_output[axis_name]
+            except KeyError, e:
+                _LOG.warn(
+                    ("cannot make a soft jump to {} because we don't have a "
+                     'last-output position for {}').format(
+                        position, axis_name))
+                steps = 1
+            else:
+                for pos in _numpy.linspace(orig_pos, position, steps+1)[1:]:
+                    self.jump(axis_name=axis_name, position=pos)
+                    if sleep:
+                        _sleep(sleep)
+                return
         position = int(position)
         channel = self.channel_by_name(name=axis_name)
         channel.data_write(position)