Fix objectivecontroller#201
Merged
beniroquai merged 13 commits intomasterfrom Dec 16, 2025
Merged
Conversation
ObjectiveController now manages all runtime state and motor movements using ESP32StageManager axis A, decoupling from ObjectiveManager which is now only responsible for configuration persistence. ObjectiveManager is simplified to provide read/write access to setup JSON parameters, including new zPositions for Z focus offsets. The controller caches config values, updates detector pixel size, and provides new API methods for Z calibration and position saving. Legacy hardware interface and state management in ObjectiveManager are removed.
Corrects the calculation of scan positions in AutofocusController by replacing integer division with float division. Updates the copyright year in ObjectiveManager to 2026.
Objective movement now runs in a separate thread via moveToObjectiveThread for improved responsiveness. Z focus adjustment is applied asynchronously, and logic for updating the current objective and pixel size has been reorganized for clarity.
Introduced debug plotting in FocusLockController for visualizing focus metric results and current images when is_debug is enabled. Updated focus metric computation to allow passing a debug flag, adjusted peak distance parameter, and refactored PeakMetric1D for simplified 1D peak finding. Also fixed focus offset calculation and stage movement logic, and improved calibration plot labeling.
Rewrote the PeakMetric class to focus exclusively on robust left-dot peak detection, adding ROI logic, improved tracking, and fallback mechanisms. Enhanced peak selection, baseline removal, and noise scaling, and added detailed reporting fields. Updated subpixel fitting and error handling for 2D grayscale input. No changes to CenterOfMassFocusMetric.
Introduces parameters for specifying autofocus target focus setpoint and maximum attempts in ExperimentController, FocusLockController, and experiment_normal_mode. Updates autofocus methods to accept and propagate these parameters, and adds background threading support for hardware autofocus. Also adds a method to stop focus calibration. Binary files updated.
Replaces usage of 'safeDistanceZHoming' with 'safePositionZHoming' for Z axis movements during homing procedures. This change clarifies intent and ensures the Z axis moves to a defined safe position rather than a relative distance.
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request refactors the objective control system and focus lock functionality in ImSwitch. The main changes include decoupling hardware interface from state management, improving focus metric computation, and enhancing autofocus capabilities.
Key changes:
- Refactored ObjectiveController to be the single source of truth for objective state, removing direct hardware dependencies
- Unified focus computation logic in FocusLockController through a single
_captureAndComputeFocusmethod - Enhanced PeakMetric focus algorithms with left-dot-only tracking to prevent peak jumping
Reviewed changes
Copilot reviewed 10 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test.png | Binary test image added (PNG file) |
| calibration_plot.png | Binary calibration plot image added (PNG file) |
| PositionerManager.py | Removed saveStageOffset method, delegating persistence to controller |
| ESP32StageManager.py | Added frame homing procedure and fixed safe position homing logic |
| ObjectiveManager.py | Simplified to configuration-only manager, removed runtime state |
| ObjectiveController.py | Refactored as single source of truth for objective state and motor control |
| focusmetrics.py | Enhanced PeakMetric with left-dot tracking and added PeakMetric1D |
| experiment_normal_mode.py | Added autofocus parameters (max_attempts, target_focus_setpoint) |
| PositionerController.py | Implemented saveStageOffset for config persistence |
| FocusLockController.py | Unified focus computation and enhanced calibration threading |
| ExperimentController.py | Added autofocus parameter forwarding and logging improvements |
| AutofocusController.py | Fixed integer division bug in scan position calculation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "final_error_um": None | ||
| } | ||
|
|
||
| performOneStepAutofocus = self.currentZPosition |
There was a problem hiding this comment.
Variable performOneStepAutofocus is not used.
Suggested change
| performOneStepAutofocus = self.currentZPosition |
|
|
||
| # Update manager state with 0-based index (will emit signal) | ||
| self._manager.setCurrentObjective(internal_slot) | ||
| if False and slot == self._currentObjective: |
There was a problem hiding this comment.
This statement is unreachable.
Suggested change
| if False and slot == self._currentObjective: | |
| if slot == self._currentObjective: |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces several improvements to the project's CI/CD workflows, dependency management, and repository hygiene. The main changes include the addition of automated version bumping and PyPI release workflows, enhancements to Docker build and publish processes, and updates to testing and dependency management configurations.
CI/CD and Release Automation:
.github/workflows/auto-version-bump.ymlto automatically bump the patch version and publish releases to PyPI when changes are pushed tomaster. This streamlines the release process and reduces manual intervention..github/workflows/imswitch-pypi.ymlto use more recent GitHub Actions and simplified steps for building and publishing packages.Docker Build and Publish Improvements:
.github/workflows/imswitch-docker-multiarch-noqt.yamlwith a new, more robust workflow.github/workflows/imswitch-docker-noqt.yaml. The new workflow supports multi-platform builds, improved tagging, and better handling of GitHub Container Registry edge cases. [1] [2]Dependency Management:
dependabot.ymlconfiguration to automate dependency updates for GitHub Actions, pip, and Docker, scheduled monthly..flake8to exclude theImToolsdirectory from linting.Testing and Build Process Updates:
.github/workflows/imswitch-test.ymlto use Python 3.11 and 3.12, and adjusted test commands to run only relevant test directories, improving efficiency and compatibility. [1] [2] [3]uvfor dependency installation, replacing pip for potentially faster and more reproducible installs.Repository Hygiene:
.dockerignoreand.gitignorefiles to.arkitekt_nextto prevent committing sensitive or unnecessary files such as credentials and caches.Let me know if you want to dive deeper into any of these changes!