Test the success of refocusing
This commit is contained in:
parent
f2d85cb891
commit
f1c315783c
2 changed files with 50 additions and 17 deletions
|
|
@ -26,6 +26,7 @@ from pydantic import BaseModel
|
|||
|
||||
Stage = direct_thing_client_dependency(SangaboardThing, "/stage/")
|
||||
Camera = raw_thing_dependency(StreamingPiCamera2)
|
||||
WrappedCamera = direct_thing_client_dependency(StreamingPiCamera2, "/camera/")
|
||||
|
||||
### Autofocus utilities
|
||||
|
||||
|
|
@ -206,12 +207,14 @@ class AutofocusThing(Thing):
|
|||
"""
|
||||
repeat = True
|
||||
attempts = 0
|
||||
backlash = 200
|
||||
|
||||
with m.run():
|
||||
while repeat and attempts < 10:
|
||||
|
||||
if start == 'centre':
|
||||
stage.move_relative(x = 0, y = 0, z = -dz / 2)
|
||||
stage.move_relative(x = 0, y = 0, z = -(backlash + dz / 2))
|
||||
stage.move_relative(x = 0, y = 0, z = backlash)
|
||||
|
||||
i, z = m.focus_rel(dz, block_cancellation=True)
|
||||
_, heights, sizes = m.move_data(i)
|
||||
|
|
@ -226,8 +229,24 @@ class AutofocusThing(Thing):
|
|||
):
|
||||
attempts += 1
|
||||
start = 'centre'
|
||||
stage.move_absolute(z = peak_height-backlash)
|
||||
stage.move_absolute(z = peak_height)
|
||||
else:
|
||||
repeat = False
|
||||
stage.move_relative(x = 0, y = 0, z = -dz)
|
||||
stage.move_absolute(z = peak_height)
|
||||
stage.move_relative(x = 0, y = 0, z = -(dz+backlash))
|
||||
stage.move_absolute(z = peak_height)
|
||||
return heights.tolist(), sizes.tolist()
|
||||
|
||||
@thing_action
|
||||
def verify_focus_sharpness(self, sweep_sizes: list, camera: WrappedCamera, leniency: int = 1):
|
||||
'''Take the sharpness curve of the autofocus, and the size of the current frame
|
||||
to see if the autofocus completed successfully. Returns True if current sharpness
|
||||
is within "leniency" number of frames from the peak of the autofocus'''
|
||||
|
||||
current_sharpness = camera.grab_jpeg_size(stream_name='lores')
|
||||
|
||||
peak = np.argmax(sweep_sizes)
|
||||
accepted_range = [peak - leniency, peak + leniency]
|
||||
|
||||
sharpness_range = [sweep_sizes[i] for i in accepted_range]
|
||||
return current_sharpness >= min(sharpness_range)
|
||||
Loading…
Add table
Add a link
Reference in a new issue