Skip to content

Laser AF: fix autofocus live-view freeze + add Restore Full FOV button#588

Open
hongquanli wants to merge 1 commit into
masterfrom
feat/laser-af-full-fov-and-antifreeze
Open

Laser AF: fix autofocus live-view freeze + add Restore Full FOV button#588
hongquanli wants to merge 1 commit into
masterfrom
feat/laser-af-full-fov-and-antifreeze

Conversation

@hongquanli

Copy link
Copy Markdown
Contributor

Two laser-autofocus live-view improvements (independent of the V-308 work in #569).

1. Fix autofocus live-view freeze (core_displacement_measurement.py)

DisplacementMeasurementController.update_measurement runs on the main GUI thread for every focus-camera frame. It:

  • rebuilt the coordinate meshgrid on every frame (the bulk of the per-frame CPU), and
  • appended to t_array / x_array / y_array without ever trimming, so both memory and the per-frame plot payload grew without bound.

After the focus camera streamed for a while (~10k frames), the UI thread saturated and the GUI froze whenever you sat in the autofocus live view. (Diagnosed with py-spy: MainThread stuck in update_measurement, all other threads idle.)

Fix:

  • Cache the meshgrid across same-size frames.
  • Bound the arrays to the last N samples.
  • Guard the centroid division so a blank/uniform frame doesn't produce 0/0 NaNs.

Behaviour is otherwise unchanged (same centroid, offsets/scaling, plot of last N, readings averaged over N_average).

2. Add "Restore Full FOV" button (LaserAutofocusSettingWidget)

Adds a button to the laser-AF live-control group that resets the focus camera ROI to the full sensor via camera.set_region_of_interest(0, 0, *camera.get_resolution()) — undoing the laser-AF spot crop so the whole sensor is visible again (handy for re-locating the spot before re-initializing). Portable (no hardcoded sensor size); failures are logged, not raised.

Testing

  • Verified on real hardware (Toupcam + focus camera): GUI launches with the button present and constructs without error; the fix compiles and preserves existing behaviour.

🤖 Generated with Claude Code

… button

Two laser-autofocus live-view improvements:

- core_displacement_measurement: the displacement update runs on the GUI thread per
  focus-camera frame and (1) rebuilt the coordinate meshgrid every frame and (2) appended
  to t/x/y_array without ever trimming, so per-frame work and memory grew unbounded and the
  UI eventually froze (~10k frames). Cache the meshgrid across same-size frames, bound the
  arrays to the last N samples, and guard the centroid division against a blank frame
  (0/0 NaN). Behaviour is otherwise unchanged.

- LaserAutofocusSettingWidget: add a "Restore Full FOV" button that resets the focus
  camera ROI to the full sensor (camera.set_region_of_interest(0, 0, *get_resolution())),
  undoing the laser-AF spot crop so the whole sensor is visible when re-locating the spot.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant