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

Commit

Permalink
Merge pull request #1285 from DiamondLightSource/fix_occasional_panda…
Browse files Browse the repository at this point in the history
…_error

Fix occasional panda error
  • Loading branch information
olliesilvester authored Apr 8, 2024
2 parents 34e404b + 3871f0f commit cf1bec6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/hyperion/device_setup_plans/setup_panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,18 @@ def setup_panda_for_flyscan(

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

LOGGER.info(f"Setting PandA clock to period {time_between_x_steps_ms}")

yield from bps.abs_set(panda.clock[1].period, time_between_x_steps_ms, group="panda-config") # type: ignore
yield from bps.abs_set(
panda.clock[1].period, # type: ignore
time_between_x_steps_ms,
group="panda-config",
)

yield from bps.abs_set(
panda.pulse[1].width, DETECTOR_TRIGGER_WIDTH, group="panda-config"
Expand All @@ -159,19 +165,24 @@ def setup_panda_for_flyscan(

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
38 changes: 38 additions & 0 deletions tests/unit_tests/device_setup_plans/test_setup_panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import numpy as np
import pytest
from bluesky.plan_stubs import null
from bluesky.run_engine import RunEngine
from dodal.devices.panda_fast_grid_scan import PandAGridScanParams
from ophyd_async.panda import SeqTrigger

Expand Down Expand Up @@ -159,6 +161,42 @@ def test_setup_panda_correctly_configures_table(
np.testing.assert_array_equal(table["outa2"], np.array([0, 1, 0, 0, 1, 0]))


def test_wait_between_setting_table_and_arming_panda(RE: RunEngine):
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 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.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(
MagicMock(),
"path",
PandAGridScanParams(),
1,
1,
1,
get_smargon_speed(0.1, 1),
)
)


# 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():
Expand Down

0 comments on commit cf1bec6

Please sign in to comment.