Browse Source

refactor error handling in cell processing; fix endeffector logic

Silas Gruen 10 months ago
parent
commit
ba49e1efd1
2 changed files with 12 additions and 9 deletions
  1. 6 2
      robot-control/src/main.py
  2. 6 7
      robot-control/src/robot/controller.py

+ 6 - 2
robot-control/src/main.py

@@ -32,8 +32,12 @@ class LoaderSystem:
                     break
                 self.logger.info(f"Processing cell {cell_id}")
                 cell = Cell(cell_id)
-                await self.controller.pick_cell_from_feeder()
-                await self.controller.insert_cell_to_slot(cell, slot)
+                try:
+                    await self.controller.pick_cell_from_feeder()
+                    await self.controller.insert_cell_to_slot(cell, slot)
+                except Exception as e:
+                    self.logger.error(f"Failed to process cell {cell_id}: {str(e)}")
+                    # TODO [SG]: do a break here?
             
             # Check for completed measurements
             if self.controller.work_queue:

+ 6 - 7
robot-control/src/robot/controller.py

@@ -86,8 +86,7 @@ class RobotController:
             # Move to pickup position
             await self.movement.move_to_position(x, y, z)
             # Grip cell
-            if await self.movement.activate_endeffector():
-                raise RuntimeError("Failed to grip cell")
+            await self.movement.activate_endeffector()
             self.gripper_occupied = True
 
             # Move back to safe height
@@ -98,7 +97,7 @@ class RobotController:
             logger.error(f"Failed to pick cell from feeder: {str(e)}")
             await self.movement.deactivate_endeffector() # TODO [SG]: Should deactivate here?
             self.gripper_occupied = False
-            return False
+            raise e
 
     def get_next_free_slot(self):
         for device in self.devices:
@@ -136,11 +135,11 @@ class RobotController:
             # Move down to insertion position
             await self.movement.move_to_position(x, y, z)
             # Release cell
-            if not await self.movement.deactivate_gripper():
+            if not await self.movement.deactivate_endeffector():
                 raise RuntimeError("Failed to release cell")     
         except Exception as e:
             logger.error(f"Failed to insert cell: {str(e)}")
-            return False   
+            raise e  
             
         slot.occupied = True
         slot.cell_id = cell.id
@@ -186,7 +185,7 @@ class RobotController:
             return cell_id
         except Exception as e:
             logger.error(f"Failed to collect cell: {str(e)}")
-            await self.movement.deactivate_gripper() # Try to deactivate to avoid stuck gripper
+            await self.movement.deactivate_endeffector() # Try to deactivate to avoid stuck gripper
             self.gripper_occupied = False
             return None
 
@@ -219,7 +218,7 @@ class RobotController:
             # Move to dropoff position
             await self.movement.move_to_position(x, y, z)
             # Release cell
-            if not await self.movement.deactivate_gripper():
+            if not await self.movement.deactivate_endeffector():
                 raise RuntimeError("Failed to release cell")
             self.gripper_occupied = False