Recentre using RangeOfMotionThing methods

This MR takes a different approach to !427 (closed) to combine recentre and and range of motion. Rather than copying in the old method, it is building a recentre algorithm using the methods of the existing RangeOfMotionThing.

By using the methods from ROM for moving and correlating the movements, we can detect any parasitic motion that indicate the end of travel was reached during movement. Currently it aborts the attempt, in future it may want to reverse its initial direction and try again.

The current algorithm makes no assumptions on the direction of the z motor. I.e. if the sphere cap is positive or negative. In future it can warn if it is detected to be upside down

Closes #499 (closed) #573 (closed)

This MR contains the following

  • Add convert_image_to_stage_coordinates action to camera stage mapping
  • Convert the ROM data to use a np.polyfit and np.poly1d for fitting quadratics, and provide method to estimate position of turning point.
  • Add perform_recentre action to Range of Motion which loops twice over _recentre_axis
  • Add _recentre_axis method which follows the algorithm below
  • Add helper functions _img_dir_from_stage_coords and _distance_in_img_percentage to calculate the direction to move in image coordinates and the distance required in fields of view.

Algorithm

Somewhat interestingly formatted graph of alggorithm (Use edit to see mermaid text, formats better in https://mermaid.live)

graph
s([Start])
er([Error])
CiD[/Choose initial direction on\nassumption 0, 0 is centre/]
Ti[/Take image/]
Mi[/Move 50% of FOV.\nAutofocus and\ntake another image/]
CC{Cross correlate\nlast two images}
Bm[/Move 200% of FOV with z correction/]
Ti2[/Take image/]
Mi2[/Move 50% of FOV.\nAutofocus and\ntake another image/]
CC2{Cross correlate\nlast two images}
EC[/Estimate centre location/]
CiC{Center is less\nthan a big move away?}
MC[/Move to centre/]
AD[/Adjust travel direction if needed/]
e([End])

  s --> CiD --> Ti
  subgraph Initial Moves
    Ti --> Mi --> CC 
  end
  CC -->| Too much parasitic motion | er
  CC -.->| < 5 correlations| Mi
  CC --> | 5 correlations | EC

  subgraph Following moves
    Bm --> Ti2
    Ti2 --> Mi2 --> CC2 
    CC2 -.->| < 2 correlations| Mi2
    CC2 -->| 2 correlations| EC
    EC --> CiC
    CiC --> |yes| MC
    CiC --> |no| AD --> Bm
  end
  CC2 -->| Too much parasitic motion | er
  MC --> e

Algorithm strengths

  • No assumptions about sphere cap directions
  • Aborts if hits edge of ROM

Algorithm weaknesses

  • Not super accurate as it doesn't overshoot the the apex. Overshooting would enable more robust turning point estimation.

Merge checklist:

  • All new/changed functions have up to date typehints and docstrings
  • Any UI updates have a before and after screenshot in the MR description
  • Unit testing of new functionality has similar or better coverage than similar existing code
  • This code has been tested on a microscope
    • Webapp has been recompiled, with aesthetic changes checked in light and dark mode (if changed)
    • With updated settings JSON (if changed)
    • SmartScan and live stitching work
Edited by Julian Stirling

Merge request reports

Loading