Skip to content

Commit

Permalink
Merge pull request #101 from Cephla-Lab/improve-laser-autofocus
Browse files Browse the repository at this point in the history
feat: improve laser autofocus with robust spot detection and error handling

Major changes:

Add comprehensive error handling and logging to laser autofocus
Implement robust spot detection with multiple detection modes
Add type hints and docstrings throughout
Add class constants for configuration values
Add laser autofocus testing and plotting capabilities
Technical improvements:

Move SpotDetectionMode from utils.py to _def.py
Add image cross correlation-based error detection
Improve defensive programming practices
Remove obsolete variables
  • Loading branch information
hongquanli authored Feb 15, 2025
2 parents 27a9370 + d0eb313 commit f0c5e17
Show file tree
Hide file tree
Showing 11 changed files with 725 additions and 200 deletions.
8 changes: 2 additions & 6 deletions software/configurations/configuration_HCS_v2.ini
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,8 @@ _support_laser_autofocus_options = [True, False]
main_camera_model = MER2-1220-32U3M
focus_camera_model = MER2-630-60U3M
focus_camera_exposure_time_ms = 0.8

use_glass_top = True
_use_glass_top_options = [True, False]

has_two_interfaces = True
_has_two_interfaces_options = [True, False]
laser_af_spot_detection_mode = "DUAL_LEFT"
_laser_af_spot_detection_mode_options = [SINGLE, DUAL_LEFT, DUAL_RIGHT, MULTI_RIGHT, MULTI_SECOND_RIGHT]

enable_flexible_multipoint = True
_enable_flexible_multipoint_options = [True, False]
Expand Down
8 changes: 2 additions & 6 deletions software/configurations/configuration_Squid+.ini
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,8 @@ _support_laser_autofocus_options = [True, False]
main_camera_model = MER2-1220-32U3M
focus_camera_model = MER2-630-60U3M
focus_camera_exposure_time_ms = 0.8

use_glass_top = True
_use_glass_top_options = [True, False]

has_two_interfaces = True
_has_two_interfaces_options = [True, False]
laser_af_spot_detection_mode = "DUAL_LEFT"
_laser_af_spot_detection_mode_options = [SINGLE, DUAL_LEFT, DUAL_RIGHT, MULTI_RIGHT, MULTI_SECOND_RIGHT]

enable_flexible_multipoint = True
_enable_flexible_multipoint_options = [True, False]
Expand Down
8 changes: 2 additions & 6 deletions software/configurations/configuration_Squid+_H117_ORCA.ini
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,8 @@ _support_laser_autofocus_options = [True, False]
main_camera_model = C15440-20UP
focus_camera_model = MER2-630-60U3M
focus_camera_exposure_time_ms = 0.8

use_glass_top = True
_use_glass_top_options = [True, False]

has_two_interfaces = True
_has_two_interfaces_options = [True, False]
laser_af_spot_detection_mode = "DUAL_LEFT"
_laser_af_spot_detection_mode_options = [SINGLE, DUAL_LEFT, DUAL_RIGHT, MULTI_RIGHT, MULTI_SECOND_RIGHT]

enable_flexible_multipoint = True
_enable_flexible_multipoint_options = [True, False]
Expand Down
13 changes: 6 additions & 7 deletions software/control/_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from configparser import ConfigParser
import json
import csv

from control.utils import SpotDetectionMode
import squid.logging

log = squid.logging.get_logger(__name__)
Expand Down Expand Up @@ -525,13 +525,12 @@ class SOFTWARE_POS_LIMIT:
FOCUS_CAMERA_MODEL = "MER2-630-60U3M"
FOCUS_CAMERA_EXPOSURE_TIME_MS = 2
FOCUS_CAMERA_ANALOG_GAIN = 0
LASER_AF_AVERAGING_N = 5
LASER_AF_AVERAGING_N = 3
LASER_AF_DISPLAY_SPOT_IMAGE = True
LASER_AF_CROP_WIDTH = 1536
LASER_AF_CROP_HEIGHT = 256
HAS_TWO_INTERFACES = True
LASER_AF_SPOT_DETECTION_MODE = SpotDetectionMode.DUAL_LEFT
LASER_AF_RANGE = 200
USE_GLASS_TOP = True
SHOW_LEGACY_DISPLACEMENT_MEASUREMENT_WINDOWS = False

MULTIPOINT_REFLECTION_AUTOFOCUS_ENABLE_BY_DEFAULT = False
Expand Down Expand Up @@ -731,10 +730,10 @@ def load_formats():
DEFAULT_DISPLAY_CROP = Tracking.DEFAULT_DISPLAY_CROP

USE_XERYON = False
XERYON_SERIAL_NUMBER = '95130303033351E02050'
XERYON_SERIAL_NUMBER = "95130303033351E02050"
XERYON_SPEED = 80
XERYON_OBJECTIVE_SWITCHER_POS_1 = ['4x', '10x']
XERYON_OBJECTIVE_SWITCHER_POS_2 = ['20x', '40x', '60x']
XERYON_OBJECTIVE_SWITCHER_POS_1 = ["4x", "10x"]
XERYON_OBJECTIVE_SWITCHER_POS_2 = ["20x", "40x", "60x"]
XERYON_OBJECTIVE_SWITCHER_POS_2_OFFSET_MM = 2

##########################################################
Expand Down
6 changes: 6 additions & 0 deletions software/control/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,12 @@ def send_trigger(self):

def read_frame(self):
return self.current_frame
'''
# read from disk for laser af debugging
image = cv2.imread("control/tests/data/laser_af_camera.png")[:, :, 0]
height, width = image.shape
return image + np.random.randint(0, 10, size=(height, width), dtype=np.uint8)
'''

def _on_frame_callback(self, user_param, raw_image):
pass
Expand Down
Loading

0 comments on commit f0c5e17

Please sign in to comment.