Skip to content

Commit

Permalink
Merge pull request #371 from DiamondLightSource/hyperion_818_system_t…
Browse files Browse the repository at this point in the history
…ests

Add raw set method to aperturescatterguard
  • Loading branch information
DominicOram authored Mar 13, 2024
2 parents 62453cc + d68a609 commit e427767
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/dodal/devices/aperturescatterguard.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import operator
from collections import namedtuple
from dataclasses import dataclass
from typing import List, Optional
from functools import reduce
from typing import List, Optional, Sequence

import numpy as np
from ophyd import Component as Cpt
from ophyd import SignalRO
from ophyd.epics_motor import EpicsMotor
from ophyd.status import AndStatus, Status, StatusBase

from dodal.devices.aperture import Aperture
Expand Down Expand Up @@ -105,6 +108,21 @@ def set(self, pos: SingleAperturePosition) -> StatusBase:

return self._safe_move_within_datacollection_range(pos.location)

def _get_motor_list(self):
return [
self.aperture.x,
self.aperture.y,
self.aperture.z,
self.scatterguard.x,
self.scatterguard.y,
]

def _set_raw_unsafe(self, positions: ApertureFiveDimensionalLocation) -> AndStatus:
motors: Sequence[EpicsMotor] = self._get_motor_list()
return reduce(
operator.and_, [motor.set(pos) for motor, pos in zip(motors, positions)]
)

def _get_closest_position_to_current(self) -> SingleAperturePosition:
"""
Returns the closest valid position to current position within {TOLERANCE_STEPS}.
Expand All @@ -113,13 +131,7 @@ def _get_closest_position_to_current(self) -> SingleAperturePosition:
assert isinstance(self.aperture_positions, AperturePositions)
for aperture in self.aperture_positions.as_list():
aperture_in_tolerence = []
motors = [
self.aperture.x,
self.aperture.y,
self.aperture.z,
self.scatterguard.x,
self.scatterguard.y,
]
motors = self._get_motor_list()
for motor, test_position in zip(motors, list(aperture.location)):
current_position = motor.user_readback.get()
tolerance = self.TOLERANCE_STEPS * motor.motor_resolution.get()
Expand Down
20 changes: 20 additions & 0 deletions tests/devices/unit_tests/test_aperture_scatterguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ def test_aperture_scatterguard_select_bottom_moves_sg_down_then_assembly_up(
)


def test_aperture_unsafe_move(
aperture_positions: AperturePositions,
aperture_in_medium_pos: ApertureScatterguard,
):
(a, b, c, d, e) = (0.2, 3.4, 5.6, 7.8, 9.0)
aperture_scatterguard = aperture_in_medium_pos
call_logger = install_logger_for_aperture_and_scatterguard(aperture_scatterguard)
aperture_scatterguard._set_raw_unsafe((a, b, c, d, e)) # type: ignore

call_logger.assert_has_calls(
[
call._mock_ap_x(a),
call._mock_ap_y(b),
call._mock_ap_z(c),
call._mock_sg_x(d),
call._mock_sg_y(e),
]
)


def test_aperture_scatterguard_select_top_moves_assembly_down_then_sg_up(
aperture_positions: AperturePositions, aperture_in_medium_pos: ApertureScatterguard
):
Expand Down

0 comments on commit e427767

Please sign in to comment.