Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Wait in parallel before arming panda
Browse files Browse the repository at this point in the history
  • Loading branch information
olliesilvester committed Apr 8, 2024
1 parent fee00a8 commit 3871f0f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
16 changes: 10 additions & 6 deletions src/hyperion/device_setup_plans/setup_panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,22 +163,26 @@ def setup_panda_for_flyscan(

LOGGER.info(f"Setting PandA sequencer values: {str(table)}")

# Wait here since table values should be set before we arm the sequencer block
yield from bps.abs_set(panda.seq[1].table, table, wait=True)
yield from bps.abs_set(panda.seq[1].table, table, group="panda-config")

# Wait here since we need PCAP to be enabled before armed
yield from bps.abs_set(panda.pcap.enable, Enabled.ENABLED.value, wait=True) # type: ignore

yield from arm_panda_for_gridscan(panda, group="panda-config")
yield from bps.abs_set(
panda.pcap.enable, # type: ignore
Enabled.ENABLED.value,
group="panda-config",
)

# Values need to be set before blocks are enabled, so wait here
yield from bps.wait(group="panda-config", timeout=GENERAL_TIMEOUT)

yield from arm_panda_for_gridscan(panda)


def arm_panda_for_gridscan(panda: PandA, group="arm_panda_gridscan"):
yield from bps.abs_set(panda.seq[1].enable, Enabled.ENABLED.value, group=group) # type: ignore
yield from bps.abs_set(panda.pulse[1].enable, Enabled.ENABLED.value, group=group) # type: ignore
yield from bps.abs_set(panda.counter[1].enable, Enabled.ENABLED.value, group=group) # type: ignore
yield from bps.abs_set(panda.pcap.arm, PcapArm.ARMED.value, group=group) # type: ignore
yield from bps.wait(group=group, timeout=GENERAL_TIMEOUT)


def disarm_panda_for_gridscan(panda, group="disarm_panda_gridscan") -> MsgGenerator:
Expand Down
23 changes: 11 additions & 12 deletions tests/unit_tests/device_setup_plans/test_setup_panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_setup_panda_performs_correct_plans(mock_load_device):
)
mock_load_device.assert_called_once()
assert num_of_sets == 9
assert num_of_waits == 4
assert num_of_waits == 3


@pytest.mark.parametrize(
Expand Down Expand Up @@ -155,28 +155,27 @@ def test_setup_panda_correctly_configures_table(


def test_wait_between_setting_table_and_arming_panda(RE: RunEngine):
wait_for_set_table = False

def handle_set(*args, **kwargs):
nonlocal wait_for_set_table
if "wait" in kwargs.keys() and isinstance(args[1], dict):
# Check that sequencer table has been set and waited on
if kwargs["wait"] and "outa2" in args[1].keys():
wait_for_set_table = True
bps_wait_done = False

def handle_wait(*args, **kwargs):
nonlocal bps_wait_done
bps_wait_done = True
yield from null()

def assert_set_table_has_been_waited_on(*args, **kwargs):
assert wait_for_set_table
assert bps_wait_done
yield from null()

with patch(
"hyperion.device_setup_plans.setup_panda.arm_panda_for_gridscan",
MagicMock(side_effect=assert_set_table_has_been_waited_on),
), patch(
"hyperion.device_setup_plans.setup_panda.bps.abs_set",
MagicMock(side_effect=handle_set),
"hyperion.device_setup_plans.setup_panda.bps.wait",
MagicMock(side_effect=handle_wait),
), patch(
"hyperion.device_setup_plans.setup_panda.load_device"
), patch(
"hyperion.device_setup_plans.setup_panda.bps.abs_set"
):
RE(
setup_panda_for_flyscan(
Expand Down

0 comments on commit 3871f0f

Please sign in to comment.