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 #1281 from DiamondLightSource/1265_rebase_prepare_…
Browse files Browse the repository at this point in the history
…for_robot_load

Prepare for robot load
  • Loading branch information
DominicOram authored Mar 27, 2024
2 parents 2a303e9 + b697bd2 commit 6c251a6
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 31 deletions.
28 changes: 26 additions & 2 deletions src/hyperion/experiment_plans/robot_load_then_centre_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import bluesky.plan_stubs as bps
from blueapi.core import BlueskyContext, MsgGenerator
from dodal.devices.aperturescatterguard import ApertureScatterguard
from dodal.devices.aperturescatterguard import AperturePositions, ApertureScatterguard
from dodal.devices.attenuator import Attenuator
from dodal.devices.backlight import Backlight
from dodal.devices.DCM import DCM
Expand All @@ -21,7 +21,7 @@
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.smargon import Smargon, StubPosition
from dodal.devices.synchrotron import Synchrotron
from dodal.devices.undulator import Undulator
from dodal.devices.undulator_dcm import UndulatorDCM
Expand Down Expand Up @@ -113,10 +113,34 @@ def wait_for_smargon_not_disabled(smargon: Smargon, timeout=60):
)


def prepare_for_robot_load(composite: RobotLoadThenCentreComposite):
yield from bps.abs_set(
composite.aperture_scatterguard,
AperturePositions.ROBOT_LOAD,
group="prepare_robot_load",
)

yield from bps.mv(composite.smargon.stub_offsets, StubPosition.RESET_TO_ROBOT_LOAD)

# fmt: off
yield from bps.mv(composite.smargon.x, 0,
composite.smargon.y, 0,
composite.smargon.z, 0,
composite.smargon.omega, 0,
composite.smargon.chi, 0,

composite.smargon.phi, 0)
# fmt: on

yield from bps.wait("prepare_robot_load")


def robot_load_then_centre_plan(
composite: RobotLoadThenCentreComposite,
parameters: RobotLoadThenCentreInternalParameters,
):
yield from prepare_for_robot_load(composite)

yield from bps.abs_set(
composite.robot,
SampleLocation(
Expand Down
56 changes: 31 additions & 25 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from bluesky.run_engine import RunEngine
from bluesky.utils import Msg
from dodal.beamlines import beamline_utils, i03
from dodal.beamlines.beamline_parameters import GDABeamlineParameters
from dodal.beamlines.beamline_parameters import (
GDABeamlineParameters,
)
from dodal.devices.aperturescatterguard import (
ApertureFiveDimensionalLocation,
AperturePositions,
Expand Down Expand Up @@ -367,33 +369,37 @@ def undulator_dcm():

@pytest.fixture
def aperture_scatterguard(done_status):
AperturePositions.LARGE = SingleAperturePosition(
location=ApertureFiveDimensionalLocation(0, 1, 2, 3, 4),
name="Large",
GDA_name="LARGE_APERTURE",
radius_microns=100,
)
AperturePositions.MEDIUM = SingleAperturePosition(
location=ApertureFiveDimensionalLocation(5, 6, 2, 8, 9),
name="Medium",
GDA_name="MEDIUM_APERTURE",
radius_microns=50,
)
AperturePositions.SMALL = SingleAperturePosition(
location=ApertureFiveDimensionalLocation(10, 11, 2, 13, 14),
name="Small",
GDA_name="SMALL_APERTURE",
radius_microns=20,
)
AperturePositions.ROBOT_LOAD = SingleAperturePosition(
location=ApertureFiveDimensionalLocation(15, 16, 2, 18, 19),
name="Robot_load",
GDA_name="ROBOT_LOAD",
radius_microns=None,
)
ap_sg = i03.aperture_scatterguard(
fake_with_ophyd_sim=True,
aperture_positions=AperturePositions(
SingleAperturePosition(
location=ApertureFiveDimensionalLocation(0, 1, 2, 3, 4),
name="Large",
GDA_name="LARGE_APERTURE",
radius_microns=100,
),
SingleAperturePosition(
location=ApertureFiveDimensionalLocation(5, 6, 2, 8, 9),
name="Medium",
GDA_name="MEDIUM_APERTURE",
radius_microns=50,
),
SingleAperturePosition(
location=ApertureFiveDimensionalLocation(10, 11, 2, 13, 14),
name="Small",
GDA_name="SMALL_APERTURE",
radius_microns=20,
),
SingleAperturePosition(
location=ApertureFiveDimensionalLocation(15, 16, 2, 18, 19),
name="Robot_load",
GDA_name="ROBOT_LOAD",
radius_microns=None,
),
AperturePositions.LARGE,
AperturePositions.MEDIUM,
AperturePositions.SMALL,
AperturePositions.ROBOT_LOAD,
),
)
ap_sg.aperture.z.user_setpoint.sim_put(2) # type: ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import pytest
from bluesky.run_engine import RunEngine
from bluesky.utils import Msg
from dodal.devices.aperturescatterguard import AperturePositions
from dodal.devices.eiger import EigerDetector
from dodal.devices.smargon import Smargon
from dodal.devices.smargon import Smargon, StubPosition
from numpy import isclose
from ophyd.sim import instantiate_fake_device
from ophyd.sim import NullStatus, instantiate_fake_device

from hyperion.experiment_plans.robot_load_then_centre_plan import (
RobotLoadThenCentreComposite,
prepare_for_robot_load,
robot_load_then_centre,
)
from hyperion.parameters.external_parameters import from_file as raw_params_from_file
Expand All @@ -22,12 +24,17 @@


@pytest.fixture
def robot_load_composite(smargon, dcm, robot) -> RobotLoadThenCentreComposite:
def robot_load_composite(
smargon, dcm, robot, aperture_scatterguard
) -> RobotLoadThenCentreComposite:
composite: RobotLoadThenCentreComposite = MagicMock()
composite.smargon = smargon
composite.dcm = dcm
composite.dcm.energy_in_kev.user_readback.sim_put(11.105)
composite.robot = robot
composite.aperture_scatterguard = aperture_scatterguard
composite.smargon.stub_offsets.set = MagicMock(return_value=NullStatus())
composite.aperture_scatterguard.set = MagicMock(return_value=NullStatus())
return composite


Expand Down Expand Up @@ -78,7 +85,8 @@ def test_when_plan_run_then_centring_plan_run_with_expected_parameters(
assert params_passed.hyperion_params.detector_params.expected_energy_ev == 11100
assert params_passed.hyperion_params.ispyb_params.current_energy_ev == 11105
assert isclose(
params_passed.hyperion_params.ispyb_params.resolution, 2.11338 # type: ignore
params_passed.hyperion_params.ispyb_params.resolution, # type: ignore
2.11338,
)


Expand Down Expand Up @@ -269,3 +277,24 @@ def test_when_plan_run_then_detector_arm_started_before_wait_on_robot_load(
idx_of_first_read_disabled_message = messages.index(list(read_disabled_messages)[0])

assert idx_of_arm_message < idx_of_first_read_disabled_message


def test_when_prepare_for_robot_load_called_then_moves_as_expected(
robot_load_composite: RobotLoadThenCentreComposite,
):
smargon = robot_load_composite.smargon
aperture_scatterguard = robot_load_composite.aperture_scatterguard

smargon.x.user_readback.sim_put(10) # type: ignore
smargon.z.user_readback.sim_put(5) # type: ignore
smargon.omega.user_readback.sim_put(90) # type: ignore

RE = RunEngine()
RE(prepare_for_robot_load(robot_load_composite))

assert smargon.x.user_readback.get() == 0
assert smargon.z.user_readback.get() == 0
assert smargon.omega.user_readback.get() == 0

smargon.stub_offsets.set.assert_called_once_with(StubPosition.RESET_TO_ROBOT_LOAD) # type: ignore
aperture_scatterguard.set.assert_called_once_with(AperturePositions.ROBOT_LOAD) # type: ignore

0 comments on commit 6c251a6

Please sign in to comment.