|
| 1 | +import math |
| 2 | + |
| 3 | +import pytest |
| 4 | +from bluesky.run_engine import RunEngine |
| 5 | +from ophyd_async.core import init_devices |
| 6 | + |
| 7 | +from dodal.beamlines import aithre |
| 8 | +from dodal.devices.aithre_lasershaping.goniometer import Goniometer |
| 9 | +from dodal.devices.util.test_utils import patch_motor |
| 10 | + |
| 11 | + |
| 12 | +@pytest.fixture |
| 13 | +def goniometer(RE: RunEngine) -> Goniometer: |
| 14 | + with init_devices(mock=True): |
| 15 | + gonio = aithre.goniometer(connect_immediately=True, mock=True) |
| 16 | + patch_motor(gonio.omega) |
| 17 | + patch_motor(gonio.sampy) |
| 18 | + patch_motor(gonio.sampz) |
| 19 | + return gonio |
| 20 | + |
| 21 | + |
| 22 | +@pytest.mark.parametrize( |
| 23 | + "vertical_set_value, omega_set_value, expected_horz, expected_vert", |
| 24 | + [ |
| 25 | + [2, 60, 1, math.sqrt(3)], |
| 26 | + [-10, 390, -5 * math.sqrt(3), -5], |
| 27 | + [0.5, -135, -math.sqrt(2) / 4, -math.sqrt(2) / 4], |
| 28 | + [1, 0, 1, 0], |
| 29 | + [-1.5, 90, 0, -1.5], |
| 30 | + ], |
| 31 | +) |
| 32 | +async def test_vertical_signal_set( |
| 33 | + goniometer: Goniometer, |
| 34 | + vertical_set_value: float, |
| 35 | + omega_set_value: float, |
| 36 | + expected_horz: float, |
| 37 | + expected_vert: float, |
| 38 | +): |
| 39 | + await goniometer.omega.set(omega_set_value) |
| 40 | + await goniometer.vertical_position.set(vertical_set_value) |
| 41 | + |
| 42 | + assert await goniometer.sampz.user_readback.get_value() == pytest.approx( |
| 43 | + expected_horz |
| 44 | + ) |
| 45 | + assert await goniometer.sampy.user_readback.get_value() == pytest.approx( |
| 46 | + expected_vert |
| 47 | + ) |
| 48 | + |
| 49 | + await goniometer.vertical_position.set(vertical_set_value * 2) |
| 50 | + assert await goniometer.sampz.user_readback.get_value() == pytest.approx( |
| 51 | + expected_horz * 2 |
| 52 | + ) |
| 53 | + assert await goniometer.sampy.user_readback.get_value() == pytest.approx( |
| 54 | + expected_vert * 2 |
| 55 | + ) |
| 56 | + |
| 57 | + |
| 58 | +@pytest.mark.parametrize("set_value", [-5, 2.7, 0]) |
| 59 | +async def test_vertical_position_get(goniometer: Goniometer, set_value: float): |
| 60 | + await goniometer.vertical_position.set(set_value) |
| 61 | + assert await goniometer.vertical_position.get_value() == set_value |
0 commit comments