fix: initialize setpoint to 0.0 and update from readback after connection #187

Merged
appel_c merged 1 commits from fix/setpoint_init into main 2026-04-22 17:30:21 +02:00
12 changed files with 93 additions and 8 deletions
+11 -1
View File
@@ -346,7 +346,9 @@ class NpointSetpointSignal(NpointSignalBase):
Signal to set the target position of an nPoint piezo stage.
"""
setpoint = 0
def __init__(self, signal_name, **kwargs):
super().__init__(signal_name, **kwargs)
self.setpoint = 0.0
@threadlocked
def _socket_get(self):
@@ -444,6 +446,14 @@ class NPointAxis(Device, PositionerBase):
def wait_for_connection(self, timeout: float = 30.0) -> bool:
self.controller.on(timeout=timeout)
self._update_setpoint_from_readback()
def _update_setpoint_from_readback(self):
"""
The setpoint is only stored locally. After a restart,
we need to update it to match the current readback value.
"""
self.user_setpoint.setpoint = self.readback.get()
def destroy(self):
"""Make sure to turn off the controller socket on destroy."""
@@ -214,6 +214,14 @@ class FlomniGalilMotor(Device, PositionerBase):
def wait_for_connection(self, timeout: float = 30.0) -> bool:
self.controller.on(timeout=timeout)
self._update_setpoint_from_readback()
def _update_setpoint_from_readback(self):
"""
The setpoint is only stored locally. After a restart,
we need to update it to match the current readback value.
"""
self.user_setpoint.setpoint = self.readback.get()
def destroy(self):
"""Make sure to turn off the controller socket on destroy."""
@@ -187,6 +187,14 @@ class FuprGalilMotor(Device, PositionerBase):
def wait_for_connection(self, timeout: float = 30.0) -> bool:
self.controller.on(timeout=timeout)
self._update_setpoint_from_readback()
def _update_setpoint_from_readback(self):
"""
The setpoint is only stored locally. After a restart,
we need to update it to match the current readback value.
"""
self.user_setpoint.setpoint = self.readback.get()
def destroy(self):
"""Make sure to turn off the controller socket on destroy."""
+4 -1
View File
@@ -381,7 +381,10 @@ class GalilReadbackSignal(GalilSignalRO):
class GalilSetpointSignal(GalilSignalBase):
setpoint = 0
def __init__(self, signal_name, **kwargs):
super().__init__(signal_name, **kwargs)
self.setpoint = 0.0
def _socket_get(self) -> float:
"""Get command for receiving the setpoint / target value.
@@ -262,6 +262,14 @@ class LamniGalilMotor(Device, PositionerBase):
def wait_for_connection(self, timeout: float = 30.0) -> bool:
self.controller.on(timeout=timeout)
self._update_setpoint_from_readback()
def _update_setpoint_from_readback(self):
"""
The setpoint is only stored locally. After a restart,
we need to update it to match the current readback value.
"""
self.user_setpoint.setpoint = self.readback.get()
def destroy(self):
"""Make sure to turn off the controller socket on destroy."""
@@ -326,6 +326,14 @@ class OMNYGalilMotor(Device, PositionerBase):
def wait_for_connection(self, timeout: float = 30.0) -> bool:
self.controller.on(timeout=timeout)
self._update_setpoint_from_readback()
def _update_setpoint_from_readback(self):
"""
The setpoint is only stored locally. After a restart,
we need to update it to match the current readback value.
"""
self.user_setpoint.setpoint = self.readback.get()
def destroy(self):
"""Make sure to turn off the controller socket on destroy."""
+12 -1
View File
@@ -388,7 +388,10 @@ class GalilReadbackSignal(GalilSignalRO):
class GalilSetpointSignal(GalilSignalBase):
setpoint = 0
def __init__(self, signal_name, **kwargs):
super().__init__(signal_name, **kwargs)
self.setpoint = 0.0
def _socket_get(self) -> float:
"""Get command for receiving the setpoint / target value.
@@ -532,6 +535,14 @@ class SGalilMotor(Device, PositionerBase):
def wait_for_connection(self, timeout: float = 30.0) -> bool:
self.controller.on(timeout=timeout)
self._update_setpoint_from_readback()
def _update_setpoint_from_readback(self):
"""
The setpoint is only stored locally. After a restart,
we need to update it to match the current readback value.
"""
self.user_setpoint.setpoint = self.readback.get()
def destroy(self):
"""Make sure to turn off the controller socket on destroy."""
+8 -1
View File
@@ -490,7 +490,6 @@ class RtFlomniReadbackSignal(RtReadbackSignal):
class RtFlomniSetpointSignal(RtSetpointSignal):
setpoint = 0
@retry_once
@threadlocked
@@ -605,6 +604,14 @@ class RtFlomniMotor(Device, PositionerBase):
def wait_for_connection(self, timeout: float = 30.0) -> bool:
self.controller.on(timeout=timeout)
self._update_setpoint_from_readback()
def _update_setpoint_from_readback(self):
"""
The setpoint is only stored locally. After a restart,
we need to update it to match the current readback value.
"""
self.user_setpoint.setpoint = self.readback.get()
def destroy(self):
"""Make sure to turn off the controller socket on destroy."""
+12 -1
View File
@@ -441,7 +441,10 @@ class RtLamniReadbackSignal(RtLamniSignalRO):
class RtLamniSetpointSignal(RtLamniSignalBase):
setpoint = 0
def __init__(self, signal_name, **kwargs):
super().__init__(signal_name, **kwargs)
self.setpoint = 0.0
def _socket_get(self) -> float:
"""Get command for receiving the setpoint / target value.
@@ -563,6 +566,14 @@ class RtLamniMotor(Device, PositionerBase):
def wait_for_connection(self, timeout: float = 30.0) -> bool:
self.controller.on(timeout=timeout)
self._update_setpoint_from_readback()
def _update_setpoint_from_readback(self):
"""
The setpoint is only stored locally. After a restart,
we need to update it to match the current readback value.
"""
self.user_setpoint.setpoint = self.readback.get()
def destroy(self):
"""Make sure to turn off the controller socket on destroy."""
+8 -1
View File
@@ -901,7 +901,6 @@ class RtOMNYReadbackSignal(RtReadbackSignal):
class RtOMNYSetpointSignal(RtSetpointSignal):
setpoint = 0
@retry_once
@threadlocked
@@ -1002,6 +1001,14 @@ class RtOMNYMotor(Device, PositionerBase):
def wait_for_connection(self, timeout: float = 30.0) -> bool:
self.controller.on(timeout=timeout)
self._update_setpoint_from_readback()
def _update_setpoint_from_readback(self):
"""
The setpoint is only stored locally. After a restart,
we need to update it to match the current readback value.
"""
self.user_setpoint.setpoint = self.readback.get()
def destroy(self):
"""Make sure to turn off the controller socket on destroy."""
+4 -1
View File
@@ -81,7 +81,10 @@ class RtReadbackSignal(RtSignalRO):
class RtSetpointSignal(RtSignalBase):
setpoint = 0
def __init__(self, signal_name, **kwargs):
super().__init__(signal_name, **kwargs)
self.setpoint = 0.0
def _socket_get(self) -> float:
"""Get command for receiving the setpoint / target value.
+2 -1
View File
@@ -217,7 +217,8 @@ def test_wait_for_connection_called(dm_with_devices):
}
motor = motor_cls(*args, **kwargs)
with mock.patch.object(motor.controller, "on") as mock_on:
motor.controller.get_position = mock.MagicMock(return_value=0)
if motor_cls != GalilRIO: # galilrio does not have a proper setpoint
motor._update_setpoint_from_readback = mock.MagicMock()
motor.wait_for_connection(timeout=5.0)
assert mock_on.call_args_list[-1] == mock.call(timeout=5.0)