main.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import asyncio
  2. from utils.logging import LoggerSingleton
  3. from fastapi import FastAPI
  4. from robot.controller import RobotController, Cell
  5. from utils.config import ConfigParser
  6. from vision.datamatrix import DataMatrixReader
  7. class LoaderSystem:
  8. def __init__(self):
  9. self.config = ConfigParser()
  10. self.logger = LoggerSingleton.get_logger(self.config)
  11. self.controller = RobotController(self.config)
  12. self.vision = DataMatrixReader()
  13. self.logger.info("Initializing LoaderSystem")
  14. self.vision.initialize()
  15. async def run(self):
  16. self.logger.info("Connecting to robot controller")
  17. await self.controller.connect()
  18. while True:
  19. # Main robot control loop
  20. while True:
  21. slot = self.controller.get_next_free_slot()
  22. if not slot:
  23. self.logger.debug("No free slots available")
  24. break
  25. # Pick and place new cell
  26. cell_id = self.vision.read_datamatrix()
  27. if not cell_id:
  28. self.logger.debug("Failed to read datamatrix")
  29. break
  30. self.logger.info(f"Processing cell {cell_id}")
  31. cell = Cell(cell_id)
  32. await self.controller.pick_cell_from_feeder()
  33. await self.controller.insert_cell_to_slot(cell, slot)
  34. # Check for completed measurements
  35. if self.controller.work_queue:
  36. completed_slot = self.controller.work_queue.pop(0)
  37. cell_id = await self.controller.collect_cell_from_slot(completed_slot)
  38. cell = Cell(cell_id)
  39. await self.controller.sort_cell(cell)
  40. await asyncio.sleep(0.1)
  41. if __name__ == "__main__":
  42. loader_system = LoaderSystem()
  43. asyncio.run(loader_system.run())