diff --git a/src/dodal/beamlines/i24.py b/src/dodal/beamlines/i24.py index 353eab6063..c24bd4ccde 100644 --- a/src/dodal/beamlines/i24.py +++ b/src/dodal/beamlines/i24.py @@ -11,8 +11,8 @@ from dodal.devices.i24.dcm import DCM from dodal.devices.i24.dual_backlight import DualBacklight from dodal.devices.i24.i24_detector_motion import DetectorMotion -from dodal.devices.i24.i24_vgonio import VGonio from dodal.devices.i24.pmac import PMAC +from dodal.devices.i24.vgonio import VerticalGoniometer from dodal.devices.oav.oav_detector import OAV from dodal.devices.oav.oav_parameters import OAVConfig from dodal.devices.zebra import Zebra @@ -154,12 +154,12 @@ def oav(wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False) -> @skip_device(lambda: BL == "s24") def vgonio( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False -) -> VGonio: - """Get the i24 vgonio device, instantiate it if it hasn't already been. +) -> VerticalGoniometer: + """Get the i24 vertical goniometer device, instantiate it if it hasn't already been. If this is called when already instantiated, it will return the existing object. """ return device_instantiation( - VGonio, + VerticalGoniometer, "vgonio", "-MO-VGON-01:", wait_for_connection, diff --git a/src/dodal/devices/i24/i24_vgonio.py b/src/dodal/devices/i24/i24_vgonio.py deleted file mode 100644 index bf066f9e4e..0000000000 --- a/src/dodal/devices/i24/i24_vgonio.py +++ /dev/null @@ -1,17 +0,0 @@ -from ophyd import Component as Cpt -from ophyd import EpicsMotor -from ophyd.epics_motor import MotorBundle - - -class VGonio(MotorBundle): - x = Cpt(EpicsMotor, "PINX") - z = Cpt(EpicsMotor, "PINZ") - yh = Cpt(EpicsMotor, "PINYH") - omega = Cpt(EpicsMotor, "OMEGA") - kappa = Cpt(EpicsMotor, "KAPPA") - phi = Cpt(EpicsMotor, "PHI") - - # Real motors - xs = Cpt(EpicsMotor, "PINXS") - ys = Cpt(EpicsMotor, "PINXS") - zs = Cpt(EpicsMotor, "PINZS") diff --git a/src/dodal/devices/i24/vgonio.py b/src/dodal/devices/i24/vgonio.py new file mode 100644 index 0000000000..3e4c3b68ae --- /dev/null +++ b/src/dodal/devices/i24/vgonio.py @@ -0,0 +1,16 @@ +from ophyd_async.core import StandardReadable +from ophyd_async.epics.motor import Motor + + +class VerticalGoniometer(StandardReadable): + def __init__(self, prefix: str, name: str = "") -> None: + self.x = Motor(prefix + "PINX") + self.z = Motor(prefix + "PINZ") + self.yh = Motor(prefix + "PINYH") + self.omega = Motor(prefix + "OMEGA") + + self.real_x = Motor(prefix + "PINXS") + self.real_z = Motor(prefix + "PINZS") + self.fast_y = Motor(prefix + "PINYS") + + super().__init__(name) diff --git a/tests/beamlines/unit_tests/test_i24.py b/tests/beamlines/unit_tests/test_i24.py index 4736e3d69f..01f2ee91ab 100644 --- a/tests/beamlines/unit_tests/test_i24.py +++ b/tests/beamlines/unit_tests/test_i24.py @@ -1,12 +1,27 @@ import pytest -from dodal.devices.i24.i24_vgonio import VGonio +from dodal.beamlines import i24 +from dodal.common.beamlines import beamline_utils +from dodal.devices.i24.vgonio import VerticalGoniometer + + +def test_list(): + beamline_utils.clear_devices() + i24.zebra(wait_for_connection=False, fake_with_ophyd_sim=True) + i24.pmac(wait_for_connection=False, fake_with_ophyd_sim=True) + i24.vgonio(wait_for_connection=False, fake_with_ophyd_sim=True) + assert beamline_utils.list_active_devices() == [ + "zebra", + "pmac", + "vgonio", + ] @pytest.mark.parametrize("module_and_devices_for_beamline", ["i24"], indirect=True) def test_device_creation(RE, module_and_devices_for_beamline): _, devices, exceptions = module_and_devices_for_beamline assert not exceptions - vgonio: VGonio = devices["vgonio"] # type: ignore - assert vgonio.prefix == "BL24I-MO-VGON-01:" - assert vgonio.kappa.prefix == "BL24I-MO-VGON-01:KAPPA" + vgonio: VerticalGoniometer = devices["vgonio"] # type: ignore + + assert vgonio._name == "vgonio" + assert vgonio.omega._name == "vgonio-omega" diff --git a/tests/devices/unit_tests/i24/test_vgonio.py b/tests/devices/unit_tests/i24/test_vgonio.py new file mode 100644 index 0000000000..a3583a28cd --- /dev/null +++ b/tests/devices/unit_tests/i24/test_vgonio.py @@ -0,0 +1,25 @@ +import bluesky.plan_stubs as bps +import pytest + +from dodal.devices.i24.vgonio import VerticalGoniometer +from dodal.devices.util.test_utils import patch_motor + + +@pytest.fixture +async def vgonio(RE): + vgonio = VerticalGoniometer("", name="fake_vgonio") + await vgonio.connect(mock=True) + with patch_motor(vgonio.x), patch_motor(vgonio.yh), patch_motor(vgonio.z): + yield vgonio + + +def test_vertical_gonio_device_can_be_created(vgonio: VerticalGoniometer): + assert isinstance(vgonio, VerticalGoniometer) + + +async def test_vgonio_motor_move(vgonio: VerticalGoniometer, RE): + pos = (1.0, 1.5) + RE(bps.mv(vgonio.x, pos[0], vgonio.yh, pos[1])) # type:ignore + + assert await vgonio.x.user_readback.get_value() == 1.0 + assert await vgonio.yh.user_readback.get_value() == 1.5