diff --git a/pyproject.toml b/pyproject.toml index 0b4d50da6..86bc0e2f1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,7 @@ dependencies = [ "ophyd == 1.9.0", "ophyd-async >= 0.3a5", "bluesky >= 1.13.0a4", - "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@040a72885deaca1055a930f09eccef4acca812f5", + "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@94adbaa5f3860baa1831c0e236232e5275364a84", ] diff --git a/src/mx_bluesky/beamlines/i04/thawing_plan.py b/src/mx_bluesky/beamlines/i04/thawing_plan.py index 0ee2097e7..aab664f34 100644 --- a/src/mx_bluesky/beamlines/i04/thawing_plan.py +++ b/src/mx_bluesky/beamlines/i04/thawing_plan.py @@ -5,7 +5,7 @@ from dodal.beamlines.i04 import MURKO_REDIS_DB, REDIS_HOST, REDIS_PASSWORD from dodal.common import inject from dodal.devices.oav.oav_detector import OAV -from dodal.devices.oav.oav_to_redis_forwarder import OAVToRedisForwarder +from dodal.devices.oav.oav_to_redis_forwarder import OAVToRedisForwarder, Source from dodal.devices.robot import BartRobot from dodal.devices.smargon import Smargon from dodal.devices.thawer import Thawer, ThawerStates @@ -25,8 +25,14 @@ def thaw_and_stream_to_redis( zoom_percentage = yield from bps.rd(oav.zoom_controller.percentage) sample_id = yield from bps.rd(robot.sample_id) - yield from bps.abs_set(oav.zoom_controller.level, "1.0x", wait=True) - yield from bps.abs_set(oav_to_redis_forwarder.sample_id, sample_id) + yield from bps.mv(oav.zoom_controller.level, "1.0x") + yield from bps.mv(oav_to_redis_forwarder.sample_id, sample_id) + yield from bps.mv(oav_to_redis_forwarder.selected_source, Source.FULL_SCREEN) + + def switch_forwarder_to_ROI(): + yield from bps.complete(oav_to_redis_forwarder) + yield from bps.mv(oav_to_redis_forwarder.selected_source, Source.ROI) + yield from bps.kickoff(oav_to_redis_forwarder, wait=True) @subs_decorator(MurkoCallback(REDIS_HOST, REDIS_PASSWORD, MURKO_REDIS_DB)) @run_decorator( @@ -43,7 +49,9 @@ def _thaw_and_stream_to_redis(): yield from bps.kickoff(oav_to_redis_forwarder, wait=True) yield from bps.monitor(smargon.omega.user_readback, name="smargon") yield from bps.monitor(oav_to_redis_forwarder.uuid, name="oav") - yield from thaw(time_to_thaw, rotation, thawer, smargon) + yield from thaw( + time_to_thaw, rotation, thawer, smargon, switch_forwarder_to_ROI + ) yield from bps.complete(oav_to_redis_forwarder) yield from _thaw_and_stream_to_redis() @@ -54,6 +62,7 @@ def thaw( rotation: float = 360, thawer: Thawer = inject("thawer"), smargon: Smargon = inject("smargon"), + plan_between_rotations=None, ) -> MsgGenerator: """Rotates the sample and thaws it at the same time. @@ -64,6 +73,8 @@ def thaw( thawer (Thawer, optional): The thawing device. Defaults to inject("thawer"). smargon (Smargon, optional): The smargon used to rotate. Defaults to inject("smargon") + plan_between_rotations (MsgGenerator, optional): A plan to run between rotations + of the smargon. Defaults to no plan. """ inital_velocity = yield from bps.rd(smargon.omega.velocity) new_velocity = abs(rotation / time_to_thaw) * 2.0 @@ -72,6 +83,8 @@ def do_thaw(): yield from bps.abs_set(smargon.omega.velocity, new_velocity, wait=True) yield from bps.abs_set(thawer.control, ThawerStates.ON, wait=True) yield from bps.rel_set(smargon.omega, rotation, wait=True) + if plan_between_rotations: + yield from plan_between_rotations() yield from bps.rel_set(smargon.omega, -rotation, wait=True) def cleanup(): diff --git a/tests/unit_tests/beamlines/i04/test_thawing.py b/tests/unit_tests/beamlines/i04/test_thawing.py index 32f7df699..e9b26a5ff 100644 --- a/tests/unit_tests/beamlines/i04/test_thawing.py +++ b/tests/unit_tests/beamlines/i04/test_thawing.py @@ -4,9 +4,10 @@ import pytest from _pytest.python_api import ApproxBase from bluesky.run_engine import RunEngine +from bluesky.simulators import assert_message_and_return_remaining from dodal.beamlines import i04 from dodal.devices.oav.oav_detector import OAV -from dodal.devices.oav.oav_to_redis_forwarder import OAVToRedisForwarder +from dodal.devices.oav.oav_to_redis_forwarder import OAVToRedisForwarder, Source from dodal.devices.robot import BartRobot from dodal.devices.smargon import Smargon from dodal.devices.thawer import Thawer, ThawerStates @@ -195,8 +196,8 @@ async def test_thaw_and_stream_sets_sample_id_and_kicks_off_forwarder( ) ) assert await oav_forwarder.sample_id.get_value() == 100 - oav_forwarder.kickoff.assert_called_once() # type: ignore - oav_forwarder.complete.assert_called_once() # type: ignore + oav_forwarder.kickoff.assert_called() # type: ignore + oav_forwarder.complete.assert_called() # type: ignore @patch("mx_bluesky.beamlines.i04.thawing_plan.MurkoCallback") @@ -255,3 +256,37 @@ def test_thaw_and_stream_will_produce_events_that_call_murko( ) ) patch_murko_call.assert_called() + + +def test_thaw_and_stream_will_switch_murko_source_half_way_through_thaw( + sim_run_engine, + smargon: Smargon, + thawer: Thawer, + oav_forwarder: OAVToRedisForwarder, + oav: OAV, + robot: BartRobot, +): + msgs = sim_run_engine.simulate_plan( + thaw_and_stream_to_redis(10, 360, robot, thawer, smargon, oav, oav_forwarder) + ) + for source in [Source.FULL_SCREEN, Source.ROI]: + msgs = assert_message_and_return_remaining( + msgs, + lambda msg: msg.command == "set" + and msg.obj.name == "oav_to_redis_forwarder-selected_source" + and msg.args[0] == source, + ) + msgs = assert_message_and_return_remaining( + msgs, + lambda msg: msg.command == "kickoff" + and msg.obj.name == "oav_to_redis_forwarder", + ) + msgs = assert_message_and_return_remaining( + msgs, + lambda msg: msg.command == "set" and msg.obj.name == "smargon-omega", + ) + msgs = assert_message_and_return_remaining( + msgs, + lambda msg: msg.command == "complete" + and msg.obj.name == "oav_to_redis_forwarder", + )