Skip to content

Commit 67fa60a

Browse files
teoching0705DominicOramoliwenmandiamond
authored
Ophyd async motor limit check in smargon (#1511)
* Wait for motors to start moving when doing deferred moves * Fix tests and linting * Check setpoints rather than dmov * Fix test * Fix typing * Fix tests * Add motor limit checking from ophyd_async * Add mock values for motor limit * Add test for MotorLimitsException to be correctly raised * Fix linting * move patch_motors to dodal.testing * Fix wrong comparision between signal and float * Change ophyd-async requirement to test motor limit * Revert "Change ophyd-async requirement to test motor limit" This reverts commit 0a064f2. * Add dev-requirements.txt * Try changing pyproject.toml * Revert "Try changing pyproject.toml" This reverts commit e8fa65f. * Move dev-requirements.txt around * Revert "Move dev-requirements.txt around" This reverts commit 9d3dd24. * Test * Fix spelling * Chnge pyproject.toml * test * test * Changed pyproject.toml for ophyd-async * Fix typo * Added arguments for default values with doc string * Updated docs * Changing test * Fix test in i10apple2 * Test * Fixed i10 id and undulator_dcm tests * test * test * test * Add mock value for mock_id_pgm * Add mock value for slits in bimorph mirror * Fix bimorph test high limit sign typo * Fix typo * fixed bimorph test * Removed unused import * Update more tests to use proper motor patch * Change test value due to change in mock limit * Change limit for testing outside limit * Remove test_utils.py in the wrong place * Remove motor limit setting in test in i10apple2 * Removing the pin to ophyd-async as there is new release * Removing the pin to ophyd-async as there is new release * set mock value in test outside motor limit in smaron * Revert "Change limit for testing outside limit" This reverts commit c97e07e. --------- Co-authored-by: Dominic Oram <[email protected]> Co-authored-by: Oli Wenman <[email protected]> Co-authored-by: oliwenmandiamond <[email protected]>
1 parent 2d55753 commit 67fa60a

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ description = "Ophyd devices and other utils that could be used across DLS beaml
1414
dependencies = [
1515
"click",
1616
"ophyd",
17-
"ophyd-async[ca,pva]>=0.13.0",
17+
"ophyd-async[ca,pva]>=0.13.2",
1818
"bluesky==1.14.2", # https://github.com/bluesky/bluesky/issues/1938
1919
"pyepics",
2020
"dataclasses-json",

src/dodal/devices/smargon.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ async def set(self, value: CombinedMove):
177177
for motor_name, new_setpoint in value.items():
178178
if new_setpoint is not None and isinstance(new_setpoint, int | float):
179179
axis: Motor = getattr(self, motor_name)
180+
await axis.check_motor_limit(
181+
await axis.user_setpoint.get_value(), new_setpoint
182+
)
180183
put_completion = await set_and_wait_for_value(
181184
axis.user_setpoint,
182185
new_setpoint,

tests/devices/test_smargon.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from bluesky import plan_stubs as bps
66
from bluesky.run_engine import RunEngine
77
from ophyd_async.core import init_devices, observe_value
8+
from ophyd_async.epics.motor import MotorLimitsException
89
from ophyd_async.testing import get_mock_put, set_mock_value
910

1011
from dodal.devices.smargon import CombinedMove, DeferMoves, Smargon, StubPosition
@@ -87,6 +88,52 @@ async def test_given_center_disp_low_when_stub_offsets_set_to_center_and_moved_t
8788
assert await smargon.stub_offsets.to_robot_load.proc.get_value() == 0
8889

8990

91+
@pytest.mark.parametrize(
92+
"test_x, test_y, test_z, test_omega, test_chi, test_phi",
93+
[
94+
(2000, 20, 30, 5, 15, 25), # x goes beyond upper limit
95+
(-2000, 20, 30, 5, 15, 25), # x goes beyond lower limit
96+
(10, 2000, 30, 5, 15, 25), # y goes beyond upper limit
97+
(10, -2000, 30, 5, 15, 25), # y goes beyond lower limit
98+
(10, 20, 2000, 5, 15, 25), # z goes beyond upper limit
99+
(10, 20, -2000, 5, 15, 25), # z goes beyond lower limit
100+
(10, 20, 30, 2000, 15, 25), # omega goes beyond upper limit
101+
(10, 20, 30, -2000, 15, 25), # omega goes beyond lower limit
102+
(10, 20, 30, 5, 2000, 25), # chi goes beyond upper limit
103+
(10, 20, 30, 5, -2000, 25), # chi goes beyond lower limit
104+
(10, 20, 30, 5, 15, 2000), # phi goes beyond upper limit
105+
(10, 20, 30, 5, 15, -2000), # phi goes beyond lower limit
106+
],
107+
)
108+
async def test_given_set_with_value_outside_motor_limit(
109+
smargon: Smargon, test_x, test_y, test_z, test_omega, test_chi, test_phi
110+
):
111+
set_mock_value(smargon.x.low_limit_travel, -1999)
112+
set_mock_value(smargon.y.low_limit_travel, -1999)
113+
set_mock_value(smargon.z.low_limit_travel, -1999)
114+
set_mock_value(smargon.omega.low_limit_travel, -1999)
115+
set_mock_value(smargon.chi.low_limit_travel, -1999)
116+
set_mock_value(smargon.phi.low_limit_travel, -1999)
117+
set_mock_value(smargon.x.high_limit_travel, 1999)
118+
set_mock_value(smargon.y.high_limit_travel, 1999)
119+
set_mock_value(smargon.z.high_limit_travel, 1999)
120+
set_mock_value(smargon.omega.high_limit_travel, 1999)
121+
set_mock_value(smargon.chi.high_limit_travel, 1999)
122+
set_mock_value(smargon.phi.high_limit_travel, 1999)
123+
124+
with pytest.raises(MotorLimitsException):
125+
await smargon.set(
126+
CombinedMove(
127+
x=test_x,
128+
y=test_y,
129+
z=test_z,
130+
omega=test_omega,
131+
chi=test_chi,
132+
phi=test_phi,
133+
)
134+
)
135+
136+
90137
async def test_given_set_with_single_value_then_that_motor_moves(smargon: Smargon):
91138
await smargon.set(CombinedMove(x=10))
92139

0 commit comments

Comments
 (0)