main.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import asyncio
  2. from robot_control.src.utils.logging import LoggerSingleton
  3. from robot_control.src.robot.controller import RobotController
  4. from robot_control.src.utils.config import ConfigParser
  5. from robot_control.src.vision.datamatrix import DataMatrixReader
  6. class LoaderSystem:
  7. def __init__(self):
  8. self.config = ConfigParser()
  9. self.logger = LoggerSingleton.get_logger(self.config)
  10. self.controller = RobotController(self.config)
  11. cam = self.config.get_vision_config().get("camera_id")
  12. self.vision = DataMatrixReader(cam)
  13. self.logger.info("Initializing LoaderSystem")
  14. self.vision.initialize()
  15. async def run(self):
  16. await self.controller.connect()
  17. # Main robot control loop
  18. while True:
  19. await asyncio.sleep(0.1) # avoid busy loop
  20. #Check for free slots loop
  21. while True:
  22. slot = self.controller.get_next_free_slot()
  23. if not slot:
  24. break
  25. # Pick and place new cell
  26. cell_id = self.vision.read_datamatrix()
  27. if not cell_id:
  28. self.logger.debug("No cell detected")
  29. break
  30. self.logger.info(f"Processing cell {cell_id}")
  31. cell = self.controller.add_cell(cell_id)
  32. try:
  33. await self.controller.pick_cell_from_feeder()
  34. await self.controller.insert_cell_to_slot(cell, slot)
  35. except Exception as e:
  36. self.logger.error(f"Failed to process cell {cell_id}: {str(e)}")
  37. break
  38. # Check for completed measurements and sort cell
  39. await self.controller.process_finished_measurement()
  40. if __name__ == "__main__":
  41. loader_system = LoaderSystem()
  42. asyncio.run(loader_system.run())