Skip to content

Commit 3d45d05

Browse files
committed
[cytation] don't update position when already set
1 parent 239c0cb commit 3d45d05

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

pylabrobot/plate_reading/biotek_backend.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ def __init__(
158158
self._column: Optional[int] = None
159159
self._auto_focus_search_range: Tuple[float, float] = (1.8, 2.5)
160160
self._shaking = False
161-
self._pos_x, self._pos_y = 0.0, 0.0
161+
self._pos_x: Optional[float] = None
162+
self._pos_y: Optional[float] = None
162163
self._objective: Optional[Objective] = None
163164
self._slow_mode: Optional[bool] = None
164165

@@ -941,6 +942,10 @@ async def set_position(self, x: float, y: float):
941942
if self._imaging_mode is None:
942943
raise ValueError("Imaging mode not set. Run set_imaging_mode() first.")
943944

945+
if x == self._pos_x and y == self._pos_y:
946+
logger.debug("Position is already set to (%s, %s)", x, y)
947+
return
948+
944949
# firmware is in (10/0.984 (10/0.984))um units. plr is mm. To convert
945950
x_str, y_str = (
946951
str(round(x * 100 * 0.984)).zfill(6),
@@ -961,16 +966,16 @@ async def set_position(self, x: float, y: float):
961966
"Y", f"Z{objective_code}{imaging_mode_code}6{row_str}{column_str}{y_str}{x_str}"
962967
)
963968

964-
relative_x, relative_y = x - self._pos_x, y - self._pos_y
969+
relative_x, relative_y = x - (self._pos_x or 0), y - (self._pos_y or 0)
965970
if relative_x != 0:
966971
relative_x_str = str(round(relative_x * 100 * 0.984)).zfill(6)
967972
await self.send_command("Y", f"O00{relative_x_str}")
968973
if relative_y != 0:
969974
relative_y_str = str(round(relative_y * 100 * 0.984)).zfill(6)
970975
await self.send_command("Y", f"O01{relative_y_str}")
971976

972-
if relative_x != 0 or relative_y != 0:
973-
await asyncio.sleep(0.1)
977+
self._pos_x, self._pos_y = x, y
978+
await asyncio.sleep(0.1)
974979

975980
def set_auto_focus_search_range(self, min_focal_height: float, max_focal_height: float):
976981
self._auto_focus_search_range = (min_focal_height, max_focal_height)
@@ -1098,7 +1103,7 @@ async def select(self, row: int, column: int):
10981103
row_str, column_str = str(row).zfill(2), str(column).zfill(2)
10991104
await self.send_command("Y", f"W6{row_str}{column_str}")
11001105
self._row, self._column = row, column
1101-
self._pos_x, self._pos_y = 0, 0
1106+
self._pos_x, self._pos_y = None, None
11021107
await self.set_position(0, 0)
11031108

11041109
async def set_gain(self, gain: Gain):

0 commit comments

Comments
 (0)