Skip to content

Commit

Permalink
Update Vertical Goniometer of i24 (DiamondLightSource#891)
Browse files Browse the repository at this point in the history
* Convert to ophyd_async, remove old axes and rename

* Rename

* Add a couple of small tests

* Update beamlines test

* Fix linting
  • Loading branch information
noemifrisina authored Nov 6, 2024
1 parent bcd40a3 commit c5b9bc6
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/dodal/beamlines/i24.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 0 additions & 17 deletions src/dodal/devices/i24/i24_vgonio.py

This file was deleted.

16 changes: 16 additions & 0 deletions src/dodal/devices/i24/vgonio.py
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 19 additions & 4 deletions tests/beamlines/unit_tests/test_i24.py
Original file line number Diff line number Diff line change
@@ -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"
25 changes: 25 additions & 0 deletions tests/devices/unit_tests/i24/test_vgonio.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c5b9bc6

Please sign in to comment.