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

Commit

Permalink
Merge pull request #1250 from DiamondLightSource/1234_robot_load
Browse files Browse the repository at this point in the history
Added initial robot load code
  • Loading branch information
DominicOram authored Mar 24, 2024
2 parents 882329e + c09df27 commit 242b283
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 115 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ install_requires =
xarray
doct
databroker
dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@288697d744a1d745dc865889960063e575c59b21
dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@a8034f3e170720cb7078a2d08871c5cb06b8cc54
pydantic<2.0 # See https://github.com/DiamondLightSource/hyperion/issues/774
scipy
pyzmq<25 # See https://github.com/DiamondLightSource/hyperion/issues/1103
Expand Down
8 changes: 4 additions & 4 deletions src/hyperion/experiment_plans/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
from hyperion.experiment_plans.pin_centre_then_xray_centre_plan import (
pin_tip_centre_then_xray_centre,
)
from hyperion.experiment_plans.rotation_scan_plan import rotation_scan
from hyperion.experiment_plans.wait_for_robot_load_then_centre_plan import (
wait_for_robot_load_then_centre,
from hyperion.experiment_plans.robot_load_then_centre_plan import (
robot_load_then_centre,
)
from hyperion.experiment_plans.rotation_scan_plan import rotation_scan

__all__ = [
"flyscan_xray_centre",
"grid_detect_then_xray_centre",
"rotation_scan",
"pin_tip_centre_then_xray_centre",
"wait_for_robot_load_then_centre",
"robot_load_then_centre",
"panda_flyscan_xray_centre",
]
20 changes: 10 additions & 10 deletions src/hyperion/experiment_plans/experiment_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from hyperion.experiment_plans import (
grid_detect_then_xray_centre_plan,
pin_centre_then_xray_centre_plan,
wait_for_robot_load_then_centre_plan,
robot_load_then_centre_plan,
)
from hyperion.external_interaction.callbacks.common.callback_util import (
CallbacksFactory,
Expand All @@ -33,14 +33,14 @@
PinCentreThenXrayCentreInternalParameters,
PinCentreThenXrayCentreParams,
)
from hyperion.parameters.plan_specific.robot_load_then_center_params import (
RobotLoadThenCentreInternalParameters,
RobotLoadThenCentreParams,
)
from hyperion.parameters.plan_specific.rotation_scan_internal_params import (
RotationInternalParameters,
RotationScanParams,
)
from hyperion.parameters.plan_specific.wait_for_robot_load_then_center_params import (
WaitForRobotLoadThenCentreInternalParameters,
WaitForRobotLoadThenCentreParams,
)


def not_implemented():
Expand All @@ -58,7 +58,7 @@ class ExperimentRegistryEntry(TypedDict):
| GridScanWithEdgeDetectInternalParameters
| RotationInternalParameters
| PinCentreThenXrayCentreInternalParameters
| WaitForRobotLoadThenCentreInternalParameters
| RobotLoadThenCentreInternalParameters
| PandAGridscanInternalParameters
]
experiment_param_type: type[AbstractExperimentParameterBase]
Expand Down Expand Up @@ -97,10 +97,10 @@ class ExperimentRegistryEntry(TypedDict):
"experiment_param_type": PinCentreThenXrayCentreParams,
"callbacks_factory": create_gridscan_callbacks,
},
"wait_for_robot_load_then_centre": {
"setup": wait_for_robot_load_then_centre_plan.create_devices,
"internal_param_type": WaitForRobotLoadThenCentreInternalParameters,
"experiment_param_type": WaitForRobotLoadThenCentreParams,
"robot_load_then_centre": {
"setup": robot_load_then_centre_plan.create_devices,
"internal_param_type": RobotLoadThenCentreInternalParameters,
"experiment_param_type": RobotLoadThenCentreParams,
"callbacks_factory": create_gridscan_callbacks,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from dodal.devices.oav.oav_detector import OAV
from dodal.devices.oav.pin_image_recognition import PinTipDetection
from dodal.devices.panda_fast_grid_scan import PandAFastGridScan
from dodal.devices.robot import BartRobot, SampleLocation
from dodal.devices.s4_slit_gaps import S4SlitGaps
from dodal.devices.smargon import Smargon
from dodal.devices.synchrotron import Synchrotron
Expand Down Expand Up @@ -47,14 +48,14 @@
from hyperion.parameters.plan_specific.pin_centre_then_xray_centre_params import (
PinCentreThenXrayCentreInternalParameters,
)
from hyperion.parameters.plan_specific.wait_for_robot_load_then_center_params import (
WaitForRobotLoadThenCentreInternalParameters,
from hyperion.parameters.plan_specific.robot_load_then_center_params import (
RobotLoadThenCentreInternalParameters,
)
from hyperion.utils.utils import convert_eV_to_angstrom


@dataclasses.dataclass
class WaitForRobotLoadThenCentreComposite:
class RobotLoadThenCentreComposite:
# common fields
xbpm_feedback: XBPMFeedback
attenuator: Attenuator
Expand Down Expand Up @@ -83,11 +84,14 @@ class WaitForRobotLoadThenCentreComposite:
dcm: DCM
undulator_dcm: UndulatorDCM

# RobotLoad fields
robot: BartRobot

def create_devices(context: BlueskyContext) -> WaitForRobotLoadThenCentreComposite:

def create_devices(context: BlueskyContext) -> RobotLoadThenCentreComposite:
from hyperion.utils.context import device_composite_from_context

return device_composite_from_context(context, WaitForRobotLoadThenCentreComposite)
return device_composite_from_context(context, RobotLoadThenCentreComposite)


def wait_for_smargon_not_disabled(smargon: Smargon, timeout=60):
Expand All @@ -109,16 +113,27 @@ def wait_for_smargon_not_disabled(smargon: Smargon, timeout=60):
)


def wait_for_robot_load_then_centre_plan(
composite: WaitForRobotLoadThenCentreComposite,
parameters: WaitForRobotLoadThenCentreInternalParameters,
def robot_load_then_centre_plan(
composite: RobotLoadThenCentreComposite,
parameters: RobotLoadThenCentreInternalParameters,
):
yield from bps.abs_set(
composite.robot,
SampleLocation(
parameters.experiment_params.sample_puck,
parameters.experiment_params.sample_pin,
),
group="robot_load",
)

if parameters.experiment_params.requested_energy_kev:
yield from set_energy_plan(
parameters.experiment_params.requested_energy_kev,
cast(SetEnergyComposite, composite),
)

yield from bps.wait("robot_load")

yield from wait_for_smargon_not_disabled(composite.smargon)

params_json = json.loads(parameters.json())
Expand All @@ -129,9 +144,9 @@ def wait_for_robot_load_then_centre_plan(
)


def wait_for_robot_load_then_centre(
composite: WaitForRobotLoadThenCentreComposite,
parameters: WaitForRobotLoadThenCentreInternalParameters,
def robot_load_then_centre(
composite: RobotLoadThenCentreComposite,
parameters: RobotLoadThenCentreInternalParameters,
) -> MsgGenerator:
eiger: EigerDetector = composite.eiger

Expand Down Expand Up @@ -160,5 +175,5 @@ def wait_for_robot_load_then_centre(
eiger,
composite.detector_motion,
parameters.experiment_params.detector_distance,
wait_for_robot_load_then_centre_plan(composite, parameters),
robot_load_then_centre_plan(composite, parameters),
)
4 changes: 2 additions & 2 deletions src/hyperion/external_interaction/ispyb/ispyb_dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ class IspybParams(BaseModel):
position: np.ndarray

transmission_fraction: float
# populated by wait_for_robot_load_then_centre
# populated by robot_load_then_centre
current_energy_ev: Optional[float]
beam_size_x: float
beam_size_y: float
focal_spot_size_x: float
focal_spot_size_y: float
comment: str
# populated by wait_for_robot_load_then_centre
# populated by robot_load_then_centre
resolution: Optional[float]

sample_id: Optional[str] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
)


class WaitForRobotLoadThenCentreHyperionParameters(HyperionParameters):
ispyb_params: RobotLoadIspybParams = RobotLoadIspybParams(
class RobotLoadThenCentreHyperionParameters(HyperionParameters):
ispyb_params: RobotLoadIspybParams = RobotLoadIspybParams( # type: ignore
**GRIDSCAN_ISPYB_PARAM_DEFAULTS
)

Expand All @@ -34,7 +34,7 @@ class Config:


@dataclass
class WaitForRobotLoadThenCentreParams(AbstractExperimentParameterBase):
class RobotLoadThenCentreParams(AbstractExperimentParameterBase):
"""
Holder class for the parameters of a plan that waits for robot load then does a
centre.
Expand All @@ -44,6 +44,10 @@ class WaitForRobotLoadThenCentreParams(AbstractExperimentParameterBase):
detector_distance: float
omega_start: float
snapshot_dir: str

sample_puck: int
sample_pin: int

requested_energy_kev: Optional[float] = None

# Distance for the smargon to accelerate into the grid and decelerate out of the grid when using the panda
Expand All @@ -60,9 +64,9 @@ def get_num_images(self):
return 0


class WaitForRobotLoadThenCentreInternalParameters(InternalParameters):
experiment_params: WaitForRobotLoadThenCentreParams
hyperion_params: WaitForRobotLoadThenCentreHyperionParameters
class RobotLoadThenCentreInternalParameters(InternalParameters):
experiment_params: RobotLoadThenCentreParams
hyperion_params: RobotLoadThenCentreHyperionParameters

class Config:
arbitrary_types_allowed = True
Expand All @@ -85,19 +89,17 @@ def _preprocess_experiment_params(
cls,
experiment_params: dict[str, Any],
):
return WaitForRobotLoadThenCentreParams(
return RobotLoadThenCentreParams(
**extract_experiment_params_from_flat_dict(
WaitForRobotLoadThenCentreParams, experiment_params
RobotLoadThenCentreParams, experiment_params
)
)

@validator("hyperion_params", pre=True)
def _preprocess_hyperion_params(
cls, all_params: dict[str, Any], values: dict[str, Any]
):
experiment_params: WaitForRobotLoadThenCentreParams = values[
"experiment_params"
]
experiment_params: RobotLoadThenCentreParams = values["experiment_params"]
all_params["num_images"] = 0
all_params["exposure_time"] = experiment_params.exposure_time
all_params["position"] = np.array(all_params["position"])
Expand All @@ -107,7 +109,7 @@ def _preprocess_hyperion_params(
all_params["trigger_mode"] = TriggerMode.FREE_RUN
all_params["upper_left"] = np.zeros(3, dtype=np.int32)
all_params["expected_energy_ev"] = None
return WaitForRobotLoadThenCentreHyperionParameters(
return RobotLoadThenCentreHyperionParameters(
**extract_hyperion_params_from_flat_dict(
all_params, cls._hyperion_param_key_definitions()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"$ref": "experiment_schemas/grid_scan_with_edge_detect_params_schema.json"
},
{
"$ref": "experiment_schemas/wait_for_robot_load_then_centre_schema.json"
"$ref": "experiment_schemas/robot_load_then_centre_schema.json"
}
]
}
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,11 @@ def ophyd_pin_tip_detection():


@pytest.fixture
def robot():
def robot(done_status):
RunEngine() # A RE is needed to start the bluesky loop
robot = i03.robot(fake_with_ophyd_sim=True)
set_sim_value(robot.barcode.bare_signal, ["BARCODE"])
robot.set = MagicMock(return_value=done_status)
return robot


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"zocalo_environment": "artemis",
"beamline": "BL03I",
"insertion_prefix": "SR03S",
"experiment_type": "wait_for_robot_load_then_centre",
"experiment_type": "robot_load_then_centre",
"detector_params": {
"directory": "/tmp/",
"prefix": "file_name",
Expand Down Expand Up @@ -38,6 +38,8 @@
"detector_distance": 255,
"snapshot_dir": "/tmp",
"use_ophyd_pin_tip_detect": true,
"requested_energy_kev": 11.1
"requested_energy_kev": 11.1,
"sample_puck": 40,
"sample_pin": 3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"zocalo_environment": "artemis",
"beamline": "BL03I",
"insertion_prefix": "SR03S",
"experiment_type": "wait_for_robot_load_then_centre",
"experiment_type": "robot_load_then_centre",
"detector_params": {
"directory": "/tmp/",
"prefix": "file_name",
Expand Down Expand Up @@ -37,6 +37,8 @@
"omega_start": 0,
"exposure_time": 0.004,
"detector_distance": 255,
"snapshot_dir": "/tmp"
"snapshot_dir": "/tmp",
"sample_puck": 40,
"sample_pin": 3
}
}
Loading

0 comments on commit 242b283

Please sign in to comment.