Skip to content

Commit 32f7437

Browse files
committed
fix get_channels_y_positions, use C0 in position_channels_in_y_direction
1 parent cc0b9d2 commit 32f7437

File tree

1 file changed

+27
-19
lines changed
  • pylabrobot/liquid_handling/backends/hamilton

1 file changed

+27
-19
lines changed

pylabrobot/liquid_handling/backends/hamilton/STAR.py

+27-19
Original file line numberDiff line numberDiff line change
@@ -7541,14 +7541,33 @@ async def get_channels_y_positions(self) -> Dict[int, float]:
75417541
command="RY",
75427542
fmt="ry#### (n)",
75437543
)
7544-
return {channel_idx: round(y / 10, 2) for channel_idx, y in enumerate(resp["ry"])}
7544+
y_positions = [round(y / 10, 2) for y in resp["ry"]]
7545+
7546+
# sometimes there is (likely) a floating point error and channels are reported to be
7547+
# less than 9mm apart. (When you set channels using position_channels_in_y_direction,
7548+
# it will raise an error.) The minimum y is 6mm, so we fix that first (in case that
7549+
# values is misreported). Then, we traverse the list in reverse and set the min_diff.
7550+
if y_positions[-1] < 5.8:
7551+
raise RuntimeError(
7552+
"Channels are reported to be too close to the front of the machine. "
7553+
"The known minimum is 6, which will be fixed automatically for 5.8<y<6. "
7554+
f"Reported values: {y_positions}."
7555+
)
7556+
elif 5.8 <= y_positions[-1] < 6:
7557+
y_positions[-1] = 6.0
7558+
7559+
min_diff = 9.0
7560+
for i in range(len(y_positions) - 2, -1, -1):
7561+
if y_positions[i] - y_positions[i + 1] < min_diff:
7562+
y_positions[i] = y_positions[i + 1] + min_diff
7563+
7564+
return {channel_idx: y for channel_idx, y in enumerate(y_positions)}
75457565

75467566
async def position_channels_in_y_direction(self, ys: Dict[int, float]):
7547-
"""position all channels simultaneously in the Y direction. There is a command for this (C0OY),
7548-
but I couldn't get it to work, so this sends commands to the individual channels instead.
7567+
"""position all channels simultaneously in the Y direction.
75497568
75507569
Args:
7551-
ys: A dictionary mapping channel index to the desired Y position in mm. The channel index is
7570+
ys: A dictionary mapping channel index to the desired Y position in mm. The channel index is
75527571
0-indexed from the back.
75537572
"""
75547573

@@ -7564,20 +7583,9 @@ async def position_channels_in_y_direction(self, ys: Dict[int, float]):
75647583
):
75657584
raise ValueError("Channels must be at least 9mm apart and in descending order")
75667585

7567-
def _channel_y_to_steps(y: float) -> int:
7568-
# for PX modules
7569-
mm_per_step = 0.046302083
7570-
return round(y / mm_per_step)
7571-
7572-
await asyncio.gather(
7573-
*(
7574-
self.send_command(
7575-
module=f"P{STAR.channel_id(channel_idx)}",
7576-
command="YA",
7577-
ya=f"{_channel_y_to_steps(y):05}",
7578-
)
7579-
for channel_idx, y in channel_locations.items()
7580-
)
7586+
yp = " ".join([f"{round(y*10):04}" for y in channel_locations.values()])
7587+
return await self.send_command(
7588+
module="C0", command="JY", yp=yp,
75817589
)
75827590

75837591
async def get_channels_z_positions(self) -> Dict[int, float]:
@@ -7668,7 +7676,7 @@ async def step_off_foil(
76687676
# Quick checks before movement.
76697677
assert channel_locations[0] <= 650, "Channel 0 would hit the back of the robot"
76707678
assert (
7671-
channel_locations[self.num_channels - 1] >= 0
7679+
channel_locations[self.num_channels - 1] >= 6
76727680
), "Channel N would hit the front of the robot"
76737681

76747682
try:

0 commit comments

Comments
 (0)