This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #534 from DiamondLightSource/527_528_improve_and_t…
…est_aperture 527 528 improve and test aperture
- Loading branch information
Showing
7 changed files
with
200 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
src/artemis/devices/system_tests/test_aperturescatterguard_system.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import bluesky.plan_stubs as bps | ||
import pytest | ||
from bluesky.callbacks import CallbackBase | ||
from bluesky.run_engine import RunEngine | ||
|
||
from artemis.devices.aperturescatterguard import ( | ||
AperturePositions, | ||
ApertureScatterguard, | ||
InvalidApertureMove, | ||
) | ||
from artemis.parameters import I03_BEAMLINE_PARAMETER_PATH, GDABeamlineParameters | ||
|
||
|
||
@pytest.fixture | ||
def ap_sg(): | ||
ap_sg = ApertureScatterguard(prefix="BL03S", name="ap_sg") | ||
ap_sg.load_aperture_positions( | ||
AperturePositions.from_gda_beamline_params( | ||
GDABeamlineParameters.from_file(I03_BEAMLINE_PARAMETER_PATH) | ||
) | ||
) | ||
return ap_sg | ||
|
||
|
||
@pytest.fixture | ||
def move_to_large(ap_sg: ApertureScatterguard): | ||
yield from bps.abs_set(ap_sg, ap_sg.aperture_positions.LARGE) | ||
|
||
|
||
@pytest.fixture | ||
def move_to_medium(ap_sg: ApertureScatterguard): | ||
yield from bps.abs_set(ap_sg, ap_sg.aperture_positions.MEDIUM) | ||
|
||
|
||
@pytest.fixture | ||
def move_to_small(ap_sg: ApertureScatterguard): | ||
yield from bps.abs_set(ap_sg, ap_sg.aperture_positions.SMALL) | ||
|
||
|
||
@pytest.fixture | ||
def move_to_robotload(ap_sg: ApertureScatterguard): | ||
yield from bps.abs_set(ap_sg, ap_sg.aperture_positions.ROBOT_LOAD) | ||
|
||
|
||
@pytest.mark.s03 | ||
def test_aperturescatterguard_setup(ap_sg: ApertureScatterguard): | ||
ap_sg.wait_for_connection() | ||
assert ap_sg.aperture_positions is not None | ||
|
||
|
||
@pytest.mark.s03 | ||
def test_aperturescatterguard_move_in_plan( | ||
ap_sg: ApertureScatterguard, | ||
move_to_large, | ||
move_to_medium, | ||
move_to_small, | ||
move_to_robotload, | ||
): | ||
RE = RunEngine({}) | ||
ap_sg.wait_for_connection() | ||
|
||
ap_sg.aperture.z.set(ap_sg.aperture_positions.LARGE[2], wait=True) | ||
|
||
RE(move_to_large) | ||
RE(move_to_medium) | ||
RE(move_to_small) | ||
RE(move_to_robotload) | ||
|
||
|
||
@pytest.mark.s03 | ||
def test_move_fails_when_not_in_good_starting_pos( | ||
ap_sg: ApertureScatterguard, move_to_large | ||
): | ||
RE = RunEngine({}) | ||
ap_sg.wait_for_connection() | ||
|
||
ap_sg.aperture.z.set(0, wait=True) | ||
|
||
with pytest.raises(InvalidApertureMove): | ||
RE(move_to_large) | ||
|
||
|
||
class MonitorCallback(CallbackBase): | ||
# holds on to the most recent time a motor move completed for aperture and | ||
# scatterguard y | ||
|
||
t_ap_y: float = 0 | ||
t_sg_y: float = 0 | ||
event_docs: list[dict] = [] | ||
|
||
def event(self, doc): | ||
self.event_docs.append(doc) | ||
if doc["data"].get("ap_sg_aperture_y_motor_done_move") == 1: | ||
self.t_ap_y = doc["timestamps"].get("ap_sg_aperture_y_motor_done_move") | ||
if doc["data"].get("ap_sg_scatterguard_y_motor_done_move") == 1: | ||
self.t_sg_y = doc["timestamps"].get("ap_sg_scatterguard_y_motor_done_move") | ||
|
||
|
||
@pytest.mark.s03 | ||
@pytest.mark.parametrize( | ||
"pos1,pos2,sg_first", | ||
[ | ||
("L", "M", True), | ||
("L", "S", True), | ||
("L", "R", False), | ||
("M", "L", False), | ||
("M", "S", True), | ||
("M", "R", False), | ||
("S", "L", False), | ||
("S", "M", False), | ||
("S", "R", False), | ||
("R", "L", True), | ||
("R", "M", True), | ||
("R", "S", True), | ||
], | ||
) | ||
def test_aperturescatterguard_moves_in_correct_order( | ||
pos1, pos2, sg_first, ap_sg: ApertureScatterguard | ||
): | ||
cb = MonitorCallback() | ||
positions = { | ||
"L": ap_sg.aperture_positions.LARGE, | ||
"M": ap_sg.aperture_positions.MEDIUM, | ||
"S": ap_sg.aperture_positions.SMALL, | ||
"R": ap_sg.aperture_positions.ROBOT_LOAD, | ||
} | ||
pos1 = positions[pos1] | ||
pos2 = positions[pos2] | ||
RE = RunEngine({}) | ||
RE.subscribe(cb) | ||
|
||
ap_sg.wait_for_connection() | ||
ap_sg.aperture.y.set(0, wait=True) | ||
ap_sg.scatterguard.y.set(0, wait=True) | ||
ap_sg.aperture.z.set(pos1[2], wait=True) | ||
|
||
def monitor_and_moves(): | ||
yield from bps.open_run() | ||
yield from bps.monitor(ap_sg.aperture.y.motor_done_move, name="ap_y") | ||
yield from bps.monitor(ap_sg.scatterguard.y.motor_done_move, name="sg_y") | ||
yield from bps.mv(ap_sg, pos1) | ||
yield from bps.sleep(0.05) | ||
yield from bps.mv(ap_sg, pos2) | ||
yield from bps.sleep(0.05) | ||
yield from bps.close_run() | ||
|
||
RE(monitor_and_moves()) | ||
|
||
assert (cb.t_sg_y < cb.t_ap_y) == sg_first |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from __future__ import annotations | ||
|
||
import copy | ||
from dataclasses import dataclass, field | ||
from os import environ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters