Update unfold_protein to use the new pyafm.storage._load_afm.
[unfold-protein.git] / unfold_protein / scan.py
index 426c09e2a1a110d7c23661db26ab90e608d8ecf3..d0d4183bb055ae032694bdcb24ae395edfe78dc3 100644 (file)
@@ -20,7 +20,6 @@
 
 import signal as _signal
 
-from calibcant.calibrate import move_far_from_surface as _move_far_from_surface
 import pypiezo.base as _pypiezo_base
 
 from . import LOG as _LOG
@@ -46,7 +45,7 @@ class UnfoldScanner (object):
                 except _ExceptionTooFar:
                     self.stepper_approach()
                 except _ExceptionTooClose:
-                    self.move_far_from_surface()
+                    self.afm.move_far_from_surface()
                     self.stepper_approach()
                 else:
                     self.position_scan_step()
@@ -54,13 +53,6 @@ class UnfoldScanner (object):
     def _handle_stop_signal(self, signal, frame):
         self._stop = True
 
-    def move_far_from_surface(self):
-        _LOG.info('retract with the stepper motor by {} m'.format(
-                self.unfolder.config['approach']['far']))
-        _move_far_from_surface(
-            stepper=self.unfolder.afm.stepper,
-            distance=self.unfolder.config['approach']['far'])
-
     def stepper_approach(self):
         config = self.unfolder.config['approach']
         deflection = self.unfolder.read_deflection()
@@ -75,18 +67,25 @@ class UnfoldScanner (object):
         axis_name = 'x'
         config = self.config['position'] 
         axis_config = self.unfolder.afm.piezo.config.select_config(
-                'axes', self.unfolder.afm.axis_name,
+                'axes', self.unfolder.afm.config['main-axis'],
                 get_attribute=_pypiezo_base.get_axis_name
                 )
         pos = self.unfolder.afm.piezo.last_output[axis_name]
         pos_m = _pypiezo_base.convert_bits_to_meters(axis_config, pos)
-        next_pos_m = pos_m + self._state['x direction']*config['x step']
+        # HACK
+        try:
+            step = float(open('/home/wking/x-step', 'r').read())
+            _LOG.info('read step from file: {}'.format(step))
+        except Exception, e:
+            _LOG.warn('could not read step from file: {}'.format(e))
+            step = config['x step']
+        next_pos_m = pos_m + self._state['x direction']*step
         if next_pos_m > config['x max']:
             self._state['x direction'] = -1
-            next_pos_m = pos_m + self._state['x direction']*config['x step']
+            next_pos_m = pos_m + self._state['x direction']*step
         elif next_pos_m < config['x min']:
             self._state['x direction'] = 1
-            next_pos_m = pos_m + self._state['x direction']*config['x step']
+            next_pos_m = pos_m + self._state['x direction']*step
         next_pos = _pypiezo_base.convert_meters_to_bits(
             axis_config, next_pos_m)
         _LOG.info('move {} from {:g} to {:g} bits'.format(