Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
(#863) Add parameter for how to run pin tip detection
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicOram committed Jan 14, 2024
1 parent 7f9a0bc commit cbf7968
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def pin_centre_then_xray_centre_plan(
pin_tip_centring_composite,
parameters.experiment_params.tip_offset_microns,
oav_config_file,
parameters.experiment_params.use_ophyd_pin_tip_detect,
)

grid_detect_params = create_parameters_for_grid_detection(parameters)
Expand Down
17 changes: 8 additions & 9 deletions src/hyperion/experiment_plans/pin_tip_centring_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
)
from hyperion.exceptions import WarningException
from hyperion.log import LOGGER
from hyperion.parameters.constants import (
OAV_REFRESH_DELAY,
PIN_TIP_SOURCE,
PinTipSource,
)
from hyperion.parameters.constants import OAV_REFRESH_DELAY
from hyperion.utils.context import device_composite_from_context

DEFAULT_STEP_SIZE = 0.5
Expand Down Expand Up @@ -139,6 +135,7 @@ def pin_tip_centre_plan(
composite: PinTipCentringComposite,
tip_offset_microns: float,
oav_config_file: str = OAV_CONFIG_JSON,
use_ophyd_pin_tip_detect: bool = False,
):
"""Finds the tip of the pin and moves to roughly the centre based on this tip. Does
this at both the current omega angle and +90 deg from this angle so as to get a
Expand All @@ -147,17 +144,19 @@ def pin_tip_centre_plan(
Args:
tip_offset_microns (float): The x offset from the tip where the centre is assumed
to be.
use_ophyd_pin_tip_detect (bool): If true use the ophyd device to find the tip,
rather than the AD plugin.
"""
oav: OAV = composite.oav
smargon: Smargon = composite.smargon
oav_params = OAVParameters("pinTipCentring", oav_config_file)

if PIN_TIP_SOURCE == PinTipSource.AD_MXSC_PLUGIN:
pin_tip_setup = oav.mxsc
pin_tip_detect = oav.mxsc.pin_tip
else:
if use_ophyd_pin_tip_detect:
pin_tip_setup = composite.pin_tip_detection
pin_tip_detect = composite.pin_tip_detection
else:
pin_tip_setup = oav.mxsc
pin_tip_detect = oav.mxsc.pin_tip

tip_offset_px = int(tip_offset_microns / oav.parameters.micronsPerXPixel)

Expand Down
27 changes: 0 additions & 27 deletions src/hyperion/parameters/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,3 @@ class Status(Enum):
BUSY = "Busy"
ABORTING = "Aborting"
IDLE = "Idle"


class PinTipSource:
"""
Two possible sources for how to get pin-tip information from an OAV.
AD_MXSC_PLUGIN:
The calculations for pin-tip detection run in an ADPython areadetector
plugin, configured as part of the areadetector plugin chain in EPICS.
The pin tip location is being constantly calculated in the background.
OPHYD:
The calculations are done in an ophyd device, which pulls a camera frame
via PVAccess and then calculates the pin tip location locally, only when
requested.
Due to using PVAccess, this can only work on the beamline control machine,
not from a developer machine.
"""

AD_MXSC_PLUGIN = 0
OHPYD_DEVICE = 1


# Hack: currently default to using MXSC plugin.
# Eventually probably want this passed in as a parameter,
# or be confident enough in ophyd device that we can just use
# that unconditionally.
PIN_TIP_SOURCE = PinTipSource.AD_MXSC_PLUGIN
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class PinCentreThenXrayCentreParams(AbstractExperimentParameterBase):
# Whether to set the stub offsets after centering
set_stub_offsets: bool = False

# Whether to use the ophyd device for tip centring rather than the area detector
# plugin
use_ophyd_pin_tip_detect: bool = False

def get_num_images(self):
return 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class WaitForRobotLoadThenCentreParams(AbstractExperimentParameterBase):
omega_start: float
snapshot_dir: str

# Whether to use the ophyd device for tip centring rather than the area detector
# plugin
use_ophyd_pin_tip_detect: bool = False

def get_num_images(self):
return 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
},
"omega_start": {
"type": "number"
},
"use_ophyd_pin_tip_detect": {
"type": "boolean"
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"omega_start": 0.0,
"tip_offset_microns": 108.9,
"grid_width_microns": 290.6,
"oav_centring_file": "tests/test_data/test_OAVCentring.json"
"oav_centring_file": "tests/test_data/test_OAVCentring.json",
"use_ophyd_pin_tip_detect": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"omega_start": 0,
"exposure_time": 0.004,
"detector_distance": 255,
"snapshot_dir": "/tmp"
"snapshot_dir": "/tmp",
"use_ophyd_pin_tip_detect": true
}
}
2 changes: 1 addition & 1 deletion tests/unit_tests/experiment_plans/test_pin_tip_centring.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def test_when_pin_tip_centre_plan_called_then_expected_plans_called(
)
RE(pin_tip_centre_plan(composite, 50, test_config_files["oav_config_json"]))

mock_setup_oav.assert_called_once()
assert mock_setup_oav.call_count == 2

assert len(get_move.call_args_list) == 2

Expand Down

0 comments on commit cbf7968

Please sign in to comment.