|
|
@@ -39,6 +39,12 @@ class RobotController:
|
|
|
self.movement = RobotMovement()
|
|
|
self.movement.set_speed(self.system_settings.speed)
|
|
|
|
|
|
+ # Initialize with configured values
|
|
|
+ self.total_slots = sum(len(device.slots) for device in self.devices)
|
|
|
+ self.work_queue: List[SlotConfig] = []
|
|
|
+
|
|
|
+ self.gripper_occupied = False
|
|
|
+
|
|
|
# Initialize MQTT handler
|
|
|
mqtt_config = self.config.get_mqtt_config() # Add this to config parser
|
|
|
self.mqtt_handler = MQTTHandler(
|
|
|
@@ -53,12 +59,6 @@ class RobotController:
|
|
|
self.mqtt_handler.register_device(
|
|
|
Device(device_id=device.id, num_slots=len(device.slots))
|
|
|
)
|
|
|
-
|
|
|
- # Initialize with configured values
|
|
|
- self.total_slots = sum(len(device.slots) for device in self.devices)
|
|
|
- self.work_queue: List[SlotConfig] = []
|
|
|
-
|
|
|
- self.gripper_occupied = False
|
|
|
|
|
|
async def cleanup(self):
|
|
|
"""Cleanup resources on shutdown"""
|
|
|
@@ -92,10 +92,6 @@ class RobotController:
|
|
|
self.gripper_occupied = False
|
|
|
return False
|
|
|
|
|
|
- async def read_cell_id(self):
|
|
|
- # Use vision system to read data matrix and return cell ID
|
|
|
- return None
|
|
|
-
|
|
|
def get_next_free_slot(self):
|
|
|
for device in self.devices:
|
|
|
for slot in device.slots:
|
|
|
@@ -133,18 +129,29 @@ class RobotController:
|
|
|
await self.movement.move_to_position(x, y, z)
|
|
|
# Release cell
|
|
|
if not await self.movement.deactivate_gripper():
|
|
|
- raise RuntimeError("Failed to release cell")
|
|
|
- slot.occupied = True
|
|
|
- slot.cell_id = cell.id
|
|
|
- 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 {cell.id} inserted to slot at position {slot.position}")
|
|
|
- return True
|
|
|
+ raise RuntimeError("Failed to release cell")
|
|
|
except Exception as e:
|
|
|
logger.error(f"Failed to insert cell: {str(e)}")
|
|
|
- return False
|
|
|
+ return False
|
|
|
+
|
|
|
+ slot.occupied = True
|
|
|
+ slot.cell_id = cell.id
|
|
|
+ self.gripper_occupied = False
|
|
|
+
|
|
|
+ # Start measurement
|
|
|
+ cell.status = CellStatus.MEASURING
|
|
|
+ # cell.measurement_slot = slot.slot_id # TODO[SG]: Make this consistent
|
|
|
+ self.mqtt_handler.start_measurement(
|
|
|
+ device_id=slot.device_id,
|
|
|
+ slot=slot.slot_id,
|
|
|
+ cell_id=cell.id,
|
|
|
+ callback=lambda device_id, slot, cell_id, capacity: self.work_queue.append((cell_id, slot, device_id, capacity))
|
|
|
+ )
|
|
|
+
|
|
|
+ # 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}")
|
|
|
+ return True
|
|
|
|
|
|
async def collect_cell_from_slot(self, slot: SlotConfig):
|
|
|
if self.gripper_occupied:
|