From: W. Trevor King Date: Tue, 17 Jan 2012 18:47:15 +0000 (-0500) Subject: Add frequency option to AFMPiezo.move_to_pos_or_def. X-Git-Tag: 0.6~29 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=14897eacf30f61cac759cda25fbd839471ef5a41;p=pypiezo.git Add frequency option to AFMPiezo.move_to_pos_or_def. --- diff --git a/pypiezo/afm.py b/pypiezo/afm.py index bfc9585..76ee928 100644 --- a/pypiezo/afm.py +++ b/pypiezo/afm.py @@ -17,12 +17,13 @@ "Control of a piezo-based atomic force microscope." +import time as _time + import numpy as _numpy try: import matplotlib as _matplotlib import matplotlib.pyplot as _matplotlib_pyplot - import time as _time # for timestamping lines on plots except (ImportError, RuntimeError), e: _matplotlib = None _matplotlib_import_error = e @@ -168,12 +169,17 @@ class AFMPiezo (_base.Piezo): return self._deflection_channel().subdevice.get_dtype() def move_to_pos_or_def(self, axis_name, position=None, deflection=None, - step=1, return_data=False, pre_move_steps=0): + step=1, return_data=False, pre_move_steps=0, + frequency=None): """TODO pre_move_steps : int number of 'null' steps to take before moving (confirming a stable input deflection). + frequency : float + The target step frequency in hertz. If `Null`, go as fast + as possible. Note that this is software timing, so it + should not be relied upon for precise results. """ if position is None and deflection is None: raise ValueError('must specify position, deflection, or both') @@ -220,6 +226,9 @@ class AFMPiezo (_base.Piezo): if aquire_data: def_array.append(current_deflection) pos_array.append(self.last_output[axis_name]) + if frequency is not None: + time_step = 1./frequency + next_time = _time.time() + time_step # step in until we hit our target position or exceed our target deflection while (self.last_output[axis_name] != position and current_deflection < deflection): @@ -237,6 +246,11 @@ class AFMPiezo (_base.Piezo): if aquire_data: def_array.append(current_deflection) pos_array.append(self.last_output[axis_name]) + if frequency is not None: + now = _time.time() + if now < next_time: + _time.sleep(next_time - now) + next_time += time_step log_string = ( 'move to position %d or deflection %g on axis %s complete'