mirror of
https://github.com/bec-project/ophyd_devices.git
synced 2026-11-28 12:08:00 +01:00
fix(positioner): enhance tolerance checks in MoveStatusWithTolerance and update moving value logic
This commit is contained in:
1 parent
3fc249143d
commit
931076dfc1
2 files changed
+15
-12
No files matched your search
@@ -4,6 +4,7 @@ from typing import TypedDict
|
||||
|
||||
import numpy as np
|
||||
from ophyd import Component as Cpt
|
||||
from ophyd import Kind
|
||||
from ophyd.device import required_for_connection
|
||||
from ophyd.positioner import PositionerBase
|
||||
from ophyd.signal import EpicsSignalBase, Signal
|
||||
@@ -26,13 +27,15 @@ class MoveStatusWithTolerance(MoveStatus):
|
||||
self.positioner = positioner
|
||||
|
||||
def _finished(self, success: bool = True, **kwargs):
|
||||
if not success:
|
||||
|
||||
# We need user_readback, user_setpoint, and tolerance to be defined to check the final position
|
||||
if not success or any(
|
||||
sig is _OPTIONAL_SIGNAL
|
||||
for sig in (self.positioner.user_readback, self.positioner.user_setpoint)
|
||||
):
|
||||
return super()._finished(success=success, **kwargs)
|
||||
|
||||
if self.positioner.tolerance is not _OPTIONAL_SIGNAL:
|
||||
tol = self.positioner.tolerance.get()
|
||||
else:
|
||||
tol = np.inf
|
||||
tol = self.positioner.tolerance.get()
|
||||
if abs(self.positioner.user_setpoint.get() - self.positioner.user_readback.get()) > tol: # type: ignore
|
||||
exc = RuntimeError(
|
||||
f"Move to {self.positioner.user_setpoint.get()} failed, "
|
||||
@@ -107,10 +110,13 @@ class PSISimplePositionerBase(ABC, PSIDeviceBase, PositionerBase):
|
||||
velocity: EpicsSignalBase = _OPTIONAL_SIGNAL
|
||||
motor_stop: EpicsSignalBase = _OPTIONAL_SIGNAL
|
||||
motor_done_move: EpicsSignalBase = _OPTIONAL_SIGNAL
|
||||
tolerance: Signal = _OPTIONAL_SIGNAL
|
||||
tolerance = Cpt(Signal, value=np.inf, kind=Kind.config)
|
||||
|
||||
stop_value = 1 # The value to put to the stop PV (if set) to make the motor stop
|
||||
done_value = 1 # The value expected to be reported by motor_done_move when the move is done
|
||||
moving_value = int(
|
||||
not done_value
|
||||
) # The value expected to be reported by motor_done_move when the move is in progress
|
||||
use_put_complete = False # Whether to use put-completion for the setpoint for the move status
|
||||
|
||||
def __init__(
|
||||
@@ -240,7 +246,7 @@ class PSISimplePositionerBase(ABC, PSIDeviceBase, PositionerBase):
|
||||
if has_done_signal:
|
||||
# The transition status must start watching before the write.
|
||||
completion_status = self._move_completion_status = TransitionStatus(
|
||||
self.motor_done_move, transitions=[0, 1]
|
||||
self.motor_done_move, transitions=[self.moving_value, self.done_value]
|
||||
)
|
||||
|
||||
if not has_done_signal and self.use_put_complete:
|
||||
|
||||
@@ -39,10 +39,6 @@ def _caput(*args, **kwargs):
|
||||
return caput(*args, **kwargs)
|
||||
|
||||
|
||||
class TolerantSimplePositioner(PSISimplePositioner):
|
||||
tolerance = Cpt(Signal, value=0.001)
|
||||
|
||||
|
||||
def wait_for(condition, timeout: float = 5.0, interval: float = 0.05, label: str = "condition"):
|
||||
deadline = time.monotonic() + timeout
|
||||
while time.monotonic() < deadline:
|
||||
@@ -67,7 +63,8 @@ def caproto_simple_positioner_ioc():
|
||||
|
||||
@pytest.fixture()
|
||||
def live_simple_positioner(caproto_simple_positioner_ioc):
|
||||
pos = TolerantSimplePositioner(name="test", prefix=MOTOR_PREFIX, override_suffixes=SUFFIXES)
|
||||
pos = PSISimplePositioner(name="test", prefix=MOTOR_PREFIX, override_suffixes=SUFFIXES)
|
||||
pos.tolerance.put(0.001)
|
||||
pos.wait_for_connection(timeout=10)
|
||||
wait_for(
|
||||
lambda: pos.motor_done_move.get(use_monitor=False) == 1, timeout=10, label="initial DMOV=1"
|
||||
|
||||
Reference in new issue
Block a user