Catch FlatFit errors from all .get_surface_position calls.
authorW. Trevor King <wking@drexel.edu>
Wed, 20 Apr 2011 18:34:43 +0000 (14:34 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 20 Apr 2011 18:35:26 +0000 (14:35 -0400)
pyafm.py

index c46e47b7e6f7e9904836da1a87c9e3f0569cb197..1d359de81289516f880321268a17252749f7fee0 100644 (file)
--- a/pyafm.py
+++ b/pyafm.py
@@ -109,8 +109,12 @@ class AFM (object):
         while pos_m < -stepper_tolerance:  # step back if we need to
             LOG.debug('step back')
             self.stepper.step_relative(-1, backlash_safe=True)
-            pos = self.piezo.get_surface_position(
-                axis_name=self.axis_name, max_deflection=target_def)
+            try:
+                pos = self.piezo.get_surface_position(
+                    axis_name=self.axis_name, max_deflection=target_def)
+            except _FlatFit, e:
+                LOG.debug(e)
+                continue
             pos_m = _convert_bits_to_meters(
                 axis.axis_channel_config, axis.axis_config, pos)
             LOG.debug('located surface at stepper %d, piezo %d (%g m)'
@@ -118,8 +122,12 @@ class AFM (object):
         while pos_m > stepper_tolerance:  # step forward if we need to
             LOG.debug('step forward')
             self.stepper.step_relative(1)
-            pos = self.piezo.get_surface_position(
-                axis_name=self.axis_name, max_deflection=target_def)
+            try:
+                pos = self.piezo.get_surface_position(
+                    axis_name=self.axis_name, max_deflection=target_def)
+            except _FlatFit, e:
+                LOG.debug(e)
+                continue
             pos_m = _convert_bits_to_meters(
                 axis.axis_channel_config, axis.axis_config, pos)
             LOG.debug('located surface at stepper %d, piezo %d (%g m)'