     (core setPosition z-drive (first trigger))
     (core loadStageSequence z-drive (double-vector trigger))
     (core startStageSequence z-drive)
-    (core waitForDevice z-drive)
     (core startSequenceAcquisition (count trigger) 0 false)
-    (grab-images))
+    (grab-images (count trigger)))
 
 (defn run-autofocus [search-params]
   (let [z-drive (core getFocusDevice)

        trigger (make-sweep-vector current-z search-params)
        current-exposure (core getExposure)]
    (let [images (acquire-images z-drive trigger (:exposure search-params))
          scores (map #(score-image "Sum" %) images)
          best-index (apply max-key #(nth scores %) (range (count images)))
          best-z (nth trigger best-index)]
      (core setPosition z-drive best-z)
      (core setExposure current-exposure)
      best-z)))
           
(defn run-test []
  (reset! search-params
          {:range 10
           :tolerance 1.00
           :score-type "Sum"
           :exposure 10})
  (run-autofocus @search-params))
(ns zippy-focus.core
  (:import [org.micromanager.utils ImageUtils PropertyItem]
           [org.micromanager.api Autofocus]
           [ij ImagePlus])
  (:use [org.micromanager.mm
            :only (load-mm gui mmc core double-vector)])
  (:gen-class
