From: W. Trevor King Date: Mon, 23 Jan 2012 21:31:02 +0000 (-0500) Subject: Move position and deflection initialization before step direction check. X-Git-Tag: 0.6~27 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=73241d31fa558cba3713db92ba07d11b6dc130b0;p=pypiezo.git 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. --- 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))