Move position and deflection initialization before step direction check.
[pypiezo.git] / pypiezo / afm.py
index 76ee928efd74f0eaf4923d379e3983d9d5154d82..c3fc14b44a88ebe31b3e164bdef2ae0ee0934d9a 100644 (file)
@@ -189,13 +189,6 @@ class AFMPiezo (_base.Piezo):
         else:
             aquire_data = False
 
-        if step == 0:
-            raise ValueError('must have non-zero step size')
-        elif step < 0 and position > self.last_output[axis_name]:
-            step = -step
-        elif step > 0 and position < self.last_output[axis_name]:
-            step = -step
-
         if position is None:
             # default to the extreme value in the step direction
             if step > 0:
@@ -208,6 +201,13 @@ class AFMPiezo (_base.Piezo):
             channel = self._deflection_channel(self)
             deflection = channel.get_maxdata()
 
+        if step == 0:
+            raise ValueError('must have non-zero step size')
+        elif step < 0 and position > self.last_output[axis_name]:
+            step = -step
+        elif step > 0 and position < self.last_output[axis_name]:
+            step = -step
+
         log_string = (
             'move to position %d or deflection %g on axis %s in steps of %d'
             % (position, deflection, axis_name, step))