Skip to content

Commit

Permalink
Merge branch 'main' into 271_nothing_in_relative_tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
shihab-dls authored Jan 8, 2025
2 parents 81aa21c + 31e360a commit e43c875
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
23 changes: 20 additions & 3 deletions src/mx_bluesky/hyperion/device_setup_plans/setup_panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from bluesky.utils import MsgGenerator
from dodal.common.beamlines.beamline_utils import get_path_provider
from dodal.devices.fast_grid_scan import PandAGridScanParams
from dodal.devices.smargon import Smargon
from ophyd_async.core import load_device
from ophyd_async.fastcs.panda import (
HDFPanda,
Expand Down Expand Up @@ -114,7 +115,7 @@ def _get_seq_table(
def setup_panda_for_flyscan(
panda: HDFPanda,
parameters: PandAGridScanParams,
initial_x: float,
smargon: Smargon,
exposure_time_s: float,
time_between_x_steps_ms: float,
sample_velocity_mm_per_s: float,
Expand All @@ -127,7 +128,7 @@ def setup_panda_for_flyscan(
Args:
panda (HDFPanda): The PandA Ophyd device
parameters (PandAGridScanParams): Grid parameters
initial_x (float): Motor positions at time of PandA setup
smargon (Smargon): The Smargon Ophyd device
exposure_time_s (float): Detector exposure time per trigger
time_between_x_steps_ms (float): Time, in ms, between each trigger. Equal to deadtime + exposure time
sample_velocity_mm_per_s (float): Velocity of the sample in mm/s = x_step_size_mm * 1000 /
Expand All @@ -149,13 +150,29 @@ def setup_panda_for_flyscan(
) as config_yaml_path:
yield from load_device(panda, str(config_yaml_path))

# Home the PandA X encoder using current motor position
initial_x = yield from bps.rd(smargon.x.user_readback)
initial_y = yield from bps.rd(smargon.y.user_readback)
initial_z = yield from bps.rd(smargon.z.user_readback)

# Home the PandA X, Y, and Z encoders using current motor position
yield from bps.abs_set(
panda.inenc[1].setp, # type: ignore
initial_x * MM_TO_ENCODER_COUNTS,
wait=True,
)

yield from bps.abs_set(
panda.inenc[2].setp, # type: ignore
initial_y * MM_TO_ENCODER_COUNTS,
wait=True,
)

yield from bps.abs_set(
panda.inenc[3].setp, # type: ignore
initial_z * MM_TO_ENCODER_COUNTS,
wait=True,
)

yield from bps.abs_set(panda.pulse[1].width, exposure_time_s, group="panda-config")

exposure_distance_mm = sample_velocity_mm_per_s * exposure_time_s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,6 @@ def _panda_triggering_setup(

time_between_x_steps_ms = (DEADTIME_S + parameters.exposure_time_s) * 1e3

current_x = yield from bps.rd(fgs_composite.smargon.x.user_readback)

smargon_speed_limit_mm_per_s = yield from bps.rd(
fgs_composite.smargon.x.max_velocity
)
Expand Down Expand Up @@ -507,7 +505,7 @@ def _panda_triggering_setup(
yield from setup_panda_for_flyscan(
fgs_composite.panda,
parameters.panda_FGS_params,
current_x,
fgs_composite.smargon,
parameters.exposure_time_s,
time_between_x_steps_ms,
sample_velocity_mm_per_s,
Expand Down
25 changes: 15 additions & 10 deletions tests/unit_tests/hyperion/device_setup_plans/test_setup_panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from bluesky.simulators import RunEngineSimulator, assert_message_and_return_remaining
from dodal.common.types import UpdatingPathProvider
from dodal.devices.fast_grid_scan import PandAGridScanParams
from dodal.devices.smargon import Smargon
from ophyd_async.fastcs.panda import HDFPanda, SeqTable, SeqTrigger

from mx_bluesky.hyperion.device_setup_plans.setup_panda import (
Expand All @@ -26,6 +27,7 @@ def get_smargon_speed(x_step_size_mm: float, time_between_x_steps_ms: float) ->
def run_simulating_setup_panda_functions(
plan: str,
panda: HDFPanda,
smargon: Smargon,
sim_run_engine: RunEngineSimulator,
mock_load_device=MagicMock,
):
Expand All @@ -49,7 +51,7 @@ def count_commands(msg):
setup_panda_for_flyscan(
panda,
PandAGridScanParams(transmission_fraction=0.01),
1,
smargon,
0.1,
100.1,
smargon_speed,
Expand All @@ -62,13 +64,15 @@ def count_commands(msg):


@patch("mx_bluesky.hyperion.device_setup_plans.setup_panda.load_device")
def test_setup_panda_performs_correct_plans(mock_load_device, sim_run_engine, panda):
def test_setup_panda_performs_correct_plans(
mock_load_device, sim_run_engine, panda, smargon
):
num_of_sets, num_of_waits = run_simulating_setup_panda_functions(
"setup", panda, sim_run_engine, mock_load_device
"setup", panda, smargon, sim_run_engine, mock_load_device
)
mock_load_device.assert_called_once()
assert num_of_sets == 8
assert num_of_waits == 3
assert num_of_sets == 10
assert num_of_waits == 5


@pytest.mark.parametrize(
Expand All @@ -89,6 +93,7 @@ def test_setup_panda_correctly_configures_table(
exposure_time_s: float,
sim_run_engine: RunEngineSimulator,
panda,
smargon,
):
sample_velocity_mm_per_s = get_smargon_speed(x_step_size, time_between_x_steps_ms)
params = PandAGridScanParams(
Expand All @@ -105,7 +110,7 @@ def test_setup_panda_correctly_configures_table(
setup_panda_for_flyscan(
panda,
params,
0,
smargon,
exposure_time_s,
time_between_x_steps_ms,
sample_velocity_mm_per_s,
Expand Down Expand Up @@ -183,7 +188,7 @@ def test_setup_panda_correctly_configures_table(
)


def test_wait_between_setting_table_and_arming_panda(RE: RunEngine, panda):
def test_wait_between_setting_table_and_arming_panda(RE: RunEngine, panda, smargon):
bps_wait_done = False

def handle_wait(*args, **kwargs):
Expand Down Expand Up @@ -211,7 +216,7 @@ def assert_set_table_has_been_waited_on(*args, **kwargs):
setup_panda_for_flyscan(
panda,
PandAGridScanParams(transmission_fraction=0.01),
1,
smargon,
0.1,
101.1,
get_smargon_speed(0.1, 1),
Expand All @@ -223,9 +228,9 @@ def assert_set_table_has_been_waited_on(*args, **kwargs):

# It also would be useful to have some system tests which check that (at least)
# all the blocks which were enabled on setup are also disabled on tidyup
def test_disarm_panda_disables_correct_blocks(sim_run_engine, panda):
def test_disarm_panda_disables_correct_blocks(sim_run_engine, panda, smargon):
num_of_sets, num_of_waits = run_simulating_setup_panda_functions(
"disarm", panda, sim_run_engine
"disarm", panda, sim_run_engine, smargon
)
assert num_of_sets == 5
assert num_of_waits == 1
Expand Down

0 comments on commit e43c875

Please sign in to comment.