1
- import asyncio
2
1
import datetime
3
2
import enum
4
3
import functools
@@ -7541,14 +7540,33 @@ async def get_channels_y_positions(self) -> Dict[int, float]:
7541
7540
command = "RY" ,
7542
7541
fmt = "ry#### (n)" ,
7543
7542
)
7544
- return {channel_idx : round (y / 10 , 2 ) for channel_idx , y in enumerate (resp ["ry" ])}
7543
+ y_positions = [round (y / 10 , 2 ) for y in resp ["ry" ]]
7544
+
7545
+ # sometimes there is (likely) a floating point error and channels are reported to be
7546
+ # less than 9mm apart. (When you set channels using position_channels_in_y_direction,
7547
+ # it will raise an error.) The minimum y is 6mm, so we fix that first (in case that
7548
+ # values is misreported). Then, we traverse the list in reverse and set the min_diff.
7549
+ if y_positions [- 1 ] < 5.8 :
7550
+ raise RuntimeError (
7551
+ "Channels are reported to be too close to the front of the machine. "
7552
+ "The known minimum is 6, which will be fixed automatically for 5.8<y<6. "
7553
+ f"Reported values: { y_positions } ."
7554
+ )
7555
+ elif 5.8 <= y_positions [- 1 ] < 6 :
7556
+ y_positions [- 1 ] = 6.0
7557
+
7558
+ min_diff = 9.0
7559
+ for i in range (len (y_positions ) - 2 , - 1 , - 1 ):
7560
+ if y_positions [i ] - y_positions [i + 1 ] < min_diff :
7561
+ y_positions [i ] = y_positions [i + 1 ] + min_diff
7562
+
7563
+ return {channel_idx : y for channel_idx , y in enumerate (y_positions )}
7545
7564
7546
7565
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.
7566
+ """position all channels simultaneously in the Y direction.
7549
7567
7550
7568
Args:
7551
- ys: A dictionary mapping channel index to the desired Y position in mm. The channel index is
7569
+ ys: A dictionary mapping channel index to the desired Y position in mm. The channel index is
7552
7570
0-indexed from the back.
7553
7571
"""
7554
7572
@@ -7564,20 +7582,11 @@ async def position_channels_in_y_direction(self, ys: Dict[int, float]):
7564
7582
):
7565
7583
raise ValueError ("Channels must be at least 9mm apart and in descending order" )
7566
7584
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
- )
7585
+ yp = " " .join ([f"{ round (y * 10 ):04} " for y in channel_locations .values ()])
7586
+ return await self .send_command (
7587
+ module = "C0" ,
7588
+ command = "JY" ,
7589
+ yp = yp ,
7581
7590
)
7582
7591
7583
7592
async def get_channels_z_positions (self ) -> Dict [int , float ]:
@@ -7668,7 +7677,7 @@ async def step_off_foil(
7668
7677
# Quick checks before movement.
7669
7678
assert channel_locations [0 ] <= 650 , "Channel 0 would hit the back of the robot"
7670
7679
assert (
7671
- channel_locations [self .num_channels - 1 ] >= 0
7680
+ channel_locations [self .num_channels - 1 ] >= 6
7672
7681
), "Channel N would hit the front of the robot"
7673
7682
7674
7683
try :
0 commit comments