Skip to content

Commit

Permalink
Change PMAC string signals to Movable devices
Browse files Browse the repository at this point in the history
  • Loading branch information
rtuck99 committed Oct 23, 2024
1 parent 4626e65 commit 9b8109d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 41 deletions.
62 changes: 24 additions & 38 deletions src/dodal/devices/i24/pmac.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from asyncio import sleep
from enum import Enum, IntEnum

from bluesky.protocols import Flyable, Triggerable
from bluesky.protocols import Flyable, Movable, Triggerable
from ophyd_async.core import (
CALCULATE_TIMEOUT,
DEFAULT_TIMEOUT,
AsyncStatus,
SignalBackend,
Device,
SignalR,
SignalRW,
SoftSignalBackend,
StandardReadable,
soft_signal_rw,
wait_for_value,
Expand Down Expand Up @@ -72,53 +70,45 @@ async def trigger(self):
await self.signal.set(self.cmd_string, wait=True)


class PMACStringLaser(SignalRW):
class PMACStringLaser(Device, Movable):
"""Set the pmac_string to control the laser."""

def __init__(
self,
pmac_str_sig: SignalRW,
backend: SignalBackend,
timeout: float | None = DEFAULT_TIMEOUT,
name: str = "",
) -> None:
self.signal = pmac_str_sig
super().__init__(backend, timeout, name)
self._signal = pmac_str_sig
super().__init__(name)

@AsyncStatus.wrap
async def set(
self,
value: LaserSettings,
wait=True,
timeout=CALCULATE_TIMEOUT,
):
await self.signal.set(value.value, wait, timeout)
await self._signal.set(value.value)


class PMACStringEncReset(SignalRW):
class PMACStringEncReset(Device, Movable):
"""Set a pmac_string to control the encoder channels in the controller."""

def __init__(
self,
pmac_str_sig: SignalRW,
backend: SignalBackend,
timeout: float | None = DEFAULT_TIMEOUT,
name: str = "",
) -> None:
self.signal = pmac_str_sig
super().__init__(backend, timeout, name)
self._signal = pmac_str_sig
super().__init__(name)

@AsyncStatus.wrap
async def set(
self,
value: EncReset,
wait=True,
timeout=CALCULATE_TIMEOUT,
):
await self.signal.set(value.value, wait, timeout)
await self._signal.set(value.value)


class ProgramRunner(SignalRW, Flyable):
class ProgramRunner(Device, Flyable):
"""Run the collection by setting the program number on the PMAC string.
Once the program number has been set, wait for the collection to be complete.
Expand All @@ -131,21 +121,18 @@ def __init__(
status_sig: SignalR,
prog_num_sig: SignalRW,
collection_time_sig: SignalRW,
backend: SignalBackend,
timeout: float | None = DEFAULT_TIMEOUT,
name: str = "",
) -> None:
self.signal = pmac_str_sig
self.status = status_sig
self.prog_num = prog_num_sig
self._signal = pmac_str_sig
self._status = status_sig
self._prog_num = prog_num_sig

self.collection_time = collection_time_sig
self.KICKOFF_TIMEOUT = timeout
self._collection_time = collection_time_sig

super().__init__(backend, timeout, name)
super().__init__(name)

async def _get_prog_number_string(self) -> str:
prog_num = await self.prog_num.get_value()
prog_num = await self._prog_num.get_value()
return f"&2b{prog_num}r"

@AsyncStatus.wrap
Expand All @@ -154,11 +141,11 @@ async def kickoff(self):
wait for the scan status PV to go to 1.
"""
prog_num_str = await self._get_prog_number_string()
await self.signal.set(prog_num_str, wait=True)
await self._signal.set(prog_num_str, wait=True)
await wait_for_value(
self.status,
self._status,
ScanState.RUNNING,
timeout=self.KICKOFF_TIMEOUT,
timeout=DEFAULT_TIMEOUT,
)

@AsyncStatus.wrap
Expand All @@ -169,8 +156,8 @@ async def complete(self):
complete_time (float): total time required by the collection to \
finish correctly.
"""
scan_complete_time = await self.collection_time.get_value()
await wait_for_value(self.status, ScanState.DONE, timeout=scan_complete_time)
scan_complete_time = await self._collection_time.get_value()
await wait_for_value(self._status, ScanState.DONE, timeout=scan_complete_time)


class ProgramAbort(Triggerable):
Expand Down Expand Up @@ -209,10 +196,10 @@ def __init__(self, prefix: str, name: str = "") -> None:
)
self.to_xyz_zero = PMACStringMove(self.pmac_string, ZERO_STR)

self.laser = PMACStringLaser(self.pmac_string, backend=SoftSignalBackend(str))
self.laser = PMACStringLaser(self.pmac_string)

self.enc_reset = PMACStringEncReset(
self.pmac_string, backend=SoftSignalBackend(str)
self.pmac_string,
)

self.x = Motor(prefix + "X")
Expand All @@ -234,7 +221,6 @@ def __init__(self, prefix: str, name: str = "") -> None:
self.scanstatus,
self.program_number,
self.collection_time,
backend=SoftSignalBackend(str),
)
self.abort_program = ProgramAbort(self.pmac_string, self.scanstatus)

Expand Down
6 changes: 3 additions & 3 deletions tests/devices/unit_tests/i24/test_pmac.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from unittest.mock import ANY, call, patch
from unittest.mock import call, patch

import bluesky.plan_stubs as bps
import pytest
Expand Down Expand Up @@ -98,7 +98,7 @@ async def test_abort_program(mock_sleep, fake_pmac: PMAC, RE):
mock_pmac_string = get_mock_put(fake_pmac.pmac_string)
mock_pmac_string.assert_has_calls(
[
call("A", wait=True, timeout=ANY),
call("P2401=0", wait=True, timeout=ANY),
call("A", wait=True),
call("P2401=0", wait=True),
]
)

0 comments on commit 9b8109d

Please sign in to comment.