@@ -7541,14 +7541,33 @@ async def get_channels_y_positions(self) -> Dict[int, float]:
7541
7541
command = "RY" ,
7542
7542
fmt = "ry#### (n)" ,
7543
7543
)
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 )}
7545
7565
7546
7566
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.
7549
7568
7550
7569
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
7552
7571
0-indexed from the back.
7553
7572
"""
7554
7573
@@ -7564,20 +7583,9 @@ async def position_channels_in_y_direction(self, ys: Dict[int, float]):
7564
7583
):
7565
7584
raise ValueError ("Channels must be at least 9mm apart and in descending order" )
7566
7585
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 ,
7581
7589
)
7582
7590
7583
7591
async def get_channels_z_positions (self ) -> Dict [int , float ]:
@@ -7668,7 +7676,7 @@ async def step_off_foil(
7668
7676
# Quick checks before movement.
7669
7677
assert channel_locations [0 ] <= 650 , "Channel 0 would hit the back of the robot"
7670
7678
assert (
7671
- channel_locations [self .num_channels - 1 ] >= 0
7679
+ channel_locations [self .num_channels - 1 ] >= 6
7672
7680
), "Channel N would hit the front of the robot"
7673
7681
7674
7682
try :
0 commit comments