|
|
@@ -78,14 +78,15 @@ class RobotController:
|
|
|
logger.error("Gripper already occupied")
|
|
|
return False
|
|
|
|
|
|
+ logger.info("Move to save position and pick cell from feeder...")
|
|
|
+ feeder_pos = self.feeder.approach_position
|
|
|
+ x, y, z = feeder_pos
|
|
|
+ # Move to safe height first
|
|
|
+ await self.movement.move_to_position(x, y, self.system_settings.safe_height)
|
|
|
+ # Move to pickup position
|
|
|
+ await self.movement.move_to_position(x, y, z)
|
|
|
+ # Grip cell
|
|
|
try:
|
|
|
- feeder_pos = self.feeder.approach_position
|
|
|
- x, y, z = feeder_pos
|
|
|
- # Move to safe height first
|
|
|
- await self.movement.move_to_position(x, y, self.system_settings.safe_height)
|
|
|
- # Move to pickup position
|
|
|
- await self.movement.move_to_position(x, y, z)
|
|
|
- # Grip cell
|
|
|
await self.movement.activate_endeffector()
|
|
|
self.gripper_occupied = True
|
|
|
|
|
|
@@ -103,7 +104,7 @@ class RobotController:
|
|
|
for device in self.devices:
|
|
|
for slot in device.slots:
|
|
|
if not slot.occupied:
|
|
|
- logger.info(f"Next free slot found at position {slot.position}")
|
|
|
+ logger.info(f"Next free slot is {slot}")
|
|
|
return slot
|
|
|
|
|
|
logger.error("No free slots available")
|
|
|
@@ -119,26 +120,21 @@ class RobotController:
|
|
|
await self.insert_cell_to_slot(cell, slot)
|
|
|
|
|
|
async def insert_cell_to_slot(self, cell: Cell, slot: SlotConfig):
|
|
|
+ logger.info(f"Inserting cell {cell.id} to {slot}...")
|
|
|
if slot.occupied:
|
|
|
- logger.error(f"Slot at position {slot.position} is already occupied")
|
|
|
- return False
|
|
|
+ raise RuntimeError(f"{slot} is already occupied")
|
|
|
if not self.gripper_occupied:
|
|
|
- logger.error("Gripper not occupied")
|
|
|
- return False
|
|
|
+ raise RuntimeError("Gripper not occupied")
|
|
|
|
|
|
# Move to slot position
|
|
|
- try:
|
|
|
- x, y, z = slot.position
|
|
|
- # Move to safe height first
|
|
|
- await self.movement.move_to_position(x, y, self.system_settings.safe_height)
|
|
|
- # Move down to insertion position
|
|
|
- await self.movement.move_to_position(x, y, z)
|
|
|
- # Release cell
|
|
|
- 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)}")
|
|
|
- raise e
|
|
|
+ x, y, z = slot.position
|
|
|
+ # Move to safe height first
|
|
|
+ await self.movement.move_to_position(x, y, self.system_settings.safe_height)
|
|
|
+ # Move down to insertion position
|
|
|
+ await self.movement.move_to_position(x, y, z)
|
|
|
+ # Release cell
|
|
|
+ if not await self.movement.deactivate_endeffector():
|
|
|
+ raise RuntimeError(f"Failed to release cell {cell.id}")
|
|
|
|
|
|
slot.occupied = True
|
|
|
slot.cell_id = cell.id
|
|
|
@@ -156,7 +152,7 @@ class RobotController:
|
|
|
|
|
|
# Move back to safe height
|
|
|
await self.movement.move_to_position(x, y, self.system_settings.safe_height)
|
|
|
- logger.info(f"Cell {cell.id} inserted to slot at position {slot.position}")
|
|
|
+ logger.info(f"Cell {cell.id} inserted to {slot}")
|
|
|
return True
|
|
|
|
|
|
async def collect_cell_from_slot(self, slot: SlotConfig):
|
|
|
@@ -164,14 +160,14 @@ class RobotController:
|
|
|
logger.error("Gripper already occupied")
|
|
|
return None
|
|
|
|
|
|
+ x, y, z = slot.position
|
|
|
+ # Move to safe height first
|
|
|
+ await self.movement.move_to_position(x, y, self.system_settings.safe_height)
|
|
|
+ # Move down to collection position
|
|
|
+ await self.movement.move_to_position(x, y, z)
|
|
|
+ # Grip cell
|
|
|
try:
|
|
|
- x, y, z = slot.position
|
|
|
- # Move to safe height first
|
|
|
- await self.movement.move_to_position(x, y, self.system_settings.safe_height)
|
|
|
- # Move down to collection position
|
|
|
- await self.movement.move_to_position(x, y, z)
|
|
|
- # Grip cell
|
|
|
- if not await self.movement.activate_gripper():
|
|
|
+ if not await self.movement.activate_endeffector():
|
|
|
raise RuntimeError("Failed to grip cell")
|
|
|
self.gripper_occupied = True
|
|
|
cell_id = slot.cell_id
|
|
|
@@ -180,13 +176,12 @@ class RobotController:
|
|
|
|
|
|
# Move back to safe height
|
|
|
await self.movement.move_to_position(x, y, self.system_settings.safe_height)
|
|
|
- logger.info(f"Cell {cell_id} collected from slot at position {slot.position}")
|
|
|
+ logger.info(f"Cell {cell_id} collected from {slot}")
|
|
|
return cell_id
|
|
|
except Exception as e:
|
|
|
- logger.error(f"Failed to collect cell: {str(e)}")
|
|
|
await self.movement.deactivate_endeffector() # Try to deactivate to avoid stuck gripper
|
|
|
self.gripper_occupied = False
|
|
|
- return None
|
|
|
+ raise e
|
|
|
|
|
|
async def sort_cell(self, cell: Cell):
|
|
|
if not self.gripper_occupied:
|
|
|
@@ -210,19 +205,16 @@ class RobotController:
|
|
|
logger.error("Cannot drop off: gripper not occupied")
|
|
|
return
|
|
|
|
|
|
- try:
|
|
|
- x, y, z = dropoff_grade.position
|
|
|
- # Move to safe height first
|
|
|
- await self.movement.move_to_position(x, y, self.system_settings.safe_height)
|
|
|
- # Move to dropoff position
|
|
|
- await self.movement.move_to_position(x, y, z)
|
|
|
- # Release cell
|
|
|
- if not await self.movement.deactivate_endeffector():
|
|
|
- raise RuntimeError("Failed to release cell")
|
|
|
- self.gripper_occupied = False
|
|
|
+ x, y, z = dropoff_grade.position
|
|
|
+ # Move to safe height first
|
|
|
+ await self.movement.move_to_position(x, y, self.system_settings.safe_height)
|
|
|
+ # Move to dropoff position
|
|
|
+ await self.movement.move_to_position(x, y, z)
|
|
|
+ # Release cell
|
|
|
+ if not await self.movement.deactivate_endeffector():
|
|
|
+ raise RuntimeError("Failed to release cell")
|
|
|
+ self.gripper_occupied = False
|
|
|
|
|
|
- # Move back to safe height
|
|
|
- await self.movement.move_to_position(x, y, self.system_settings.safe_height)
|
|
|
- logger.info(f"Cell dropped off at grade {dropoff_grade.name}")
|
|
|
- except Exception as e:
|
|
|
- logger.error(f"Failed to drop off cell: {str(e)}")
|
|
|
+ # Move back to safe height
|
|
|
+ await self.movement.move_to_position(x, y, self.system_settings.safe_height)
|
|
|
+ logger.info(f"Cell dropped off at grade {dropoff_grade.name}")
|