From 73241d31fa558cba3713db92ba07d11b6dc130b0 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 23 Jan 2012 16:31:02 -0500 Subject: [PATCH] Move position and deflection initialization before step direction check. Otherwise, if position is not specified, step would always end up being negative, and position would always end up as zero. Now position will end up being the extreme in the initial step direction, as advertised. --- pypiezo/afm.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pypiezo/afm.py b/pypiezo/afm.py index 76ee928..c3fc14b 100644 --- a/pypiezo/afm.py +++ b/pypiezo/afm.py @@ -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)) -- 2.26.2