Skip to content

Use hardware scan for fine focus instead of step-and-capture #12

Description

@pskeshu

Problem

The current fine_focus implementation in gently/agent/tools/focus_tools.py uses a software-controlled step-and-capture approach:

for i, pos in enumerate(positions):
    result = await client.capture_lightsheet_image(
        piezo_position=float(pos),
        galvo_position=float(galvo_position)
    )

This is slow because each iteration requires:

  1. Send piezo move command
  2. Wait for piezo to settle
  3. Trigger camera acquisition
  4. Wait for exposure + readout
  5. Transfer image data
  6. Repeat

For a typical 21-position sweep (±10μm at 1μm steps), this adds significant overhead from communication latency and settle times.

Proposed Solution

Use hardware-triggered scanning where:

  • Galvo stays constant at the specified position
  • Piezo scans continuously through the range
  • Camera acquires a stack triggered by piezo controller

This would use the existing volume acquisition infrastructure but with:

  • Galvo held at a single position (not scanning)
  • Piezo providing the Z movement
  • Camera in triggered/streaming mode

Benefits

  • Much faster acquisition (single trigger starts entire sweep)
  • Piezo controller handles precise timing
  • Reduced communication overhead
  • More consistent timing between frames

Implementation Notes

  • May need a new client method like capture_piezo_stack() or modify acquire_volume() to support galvo-constant mode
  • Focus score calculation remains the same (analyze returned stack)
  • Consider if existing acquire_volume can be parameterized for this use case

Related Code

  • gently/agent/tools/focus_tools.py - fine_focus() function
  • gently/plans.py - existing volume acquisition plans

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions