Kaynağa Gözat

adapt integration test accordingly

Silas Gruen 6 ay önce
ebeveyn
işleme
58dbe06f8c
1 değiştirilmiş dosya ile 30 ekleme ve 18 silme
  1. 30 18
      playgrounds/integration_test.py

+ 30 - 18
playgrounds/integration_test.py

@@ -4,19 +4,13 @@ import asyncio
 import logging
 from robot_control.src.robot.controller import RobotController, Cell, CellStatus
 from robot_control.src.utils.config import ConfigParser
+from robot_control.src.utils.logging import setup_logging
 from robot_control.src.vision.datamatrix import DataMatrixReader
 from robot_control.src.api.i2c_handler import I2C, MockI2C
 from robot_control.src.vendor.mcp3428 import MCP3428
 from robot_control.src.robot.pump_controller import PumpController
 from robot_control.src.api.gpio import PiGPIO, MockGPIO
 
-logging.basicConfig(
-    level=logging.INFO,
-    format='%(asctime)s - %(module)s - %(levelname)s - %(message)s',
-)
-
-logger = logging.getLogger(__name__)
-logger.setLevel(logging.INFO)
 
 """
 This is a test script for the loader system.
@@ -39,16 +33,30 @@ async def wait_for_enter():
 class LoaderSystem:
     def __init__(self):
         self.config = ConfigParser().config
+        setup_logging(self.config)  # Set up logging with config
         gpio_config = self.config.gpio
         if gpio_config.debug:
             self.gpio = MockGPIO()
         else:
             self.gpio = PiGPIO(out_pins=[gpio_config.pump_pin, gpio_config.valve_pin])
 
-        self.controller = RobotController(self.config, self.gpio)
-        # self.vision = DataMatrixReader(self.config)
+        # Initialize vision system
+        self.vision = DataMatrixReader(self.config.vision)
+        
+        # Initialize pump controller
+        self.pump_controller = PumpController(self.config, self.gpio)
+
+        # Initialize robot controller with all required arguments
+        self.controller = RobotController(
+            self.config,
+            self.gpio,
+            self.i2c,
+            self.vision,
+            self.pump_controller
+        )
         
-        logger.info("Initializing LoaderSystem")
+        self.logger = logging.getLogger(__name__)
+        self.logger.info("Initializing LoaderSystem")
         # self.vision.initialize()
 
         # Test stuff
@@ -59,7 +67,7 @@ class LoaderSystem:
         i2c_device_class = MCP3428 if not self.config.i2c.debug else MockI2C
         self.i2c = I2C(i2c_device_class)
         self.i2c.initialize()
-        logger.info(f"I2C initialized with {i2c_device_class.__name__}")
+        self.logger.info(f"I2C initialized with {i2c_device_class.__name__}")
 
         self.pump_controller = PumpController(self.config, self.gpio)
 
@@ -75,30 +83,34 @@ class LoaderSystem:
             try:
                 readings = await self.i2c.read_channels([1, 3, 4])
                 for channel, value in readings.items():
-                    logger.debug(f"Channel {channel} reading: {value}")
+                    self.logger.debug(f"Channel {channel} reading: {value}")
                     if channel == 3:  # Pressure reading
                         self.pump_controller.handle_tank_reading(value)
                     if channel == 4:
                         state = self.pump_controller.check_endeffector_state(value)
                         self.controller.set_suction_state(state)
             except Exception as e:
-                logger.error(f"Error polling I2C channels: {str(e)}")
+                self.logger.error(f"Error polling I2C channels: {str(e)}")
             await asyncio.sleep(1)  # Poll every second
 
     async def _loader_loop(self):
         while True:
             await wait_for_enter()
-            logger.info("Starting movement sequence...")
+            await self.controller.prepare_feeder_cell()
+
+
+            await wait_for_enter()
+            self.logger.info("Starting movement sequence...")
             await self.controller.pick_cell_from_slot(self.test_slot)
             await self.controller.dropoff_cell(self.test_dropoff)
 
             await self.controller.pick_cell_from_feeder()
-            cell = Cell(id="test_cell", status=CellStatus.WAITING)
+            cell = Cell(id=1, status=CellStatus.WAITING)
             await self.controller.insert_cell_to_slot(cell, self.test_slot)
-            logger.info("\nPress Enter to repeat sequence (or Ctrl+C to exit)...")
+            self.logger.info("\nPress Enter to repeat sequence (or Ctrl+C to exit)...")
 
     async def cleanup(self):
-        logger.info("Cleaning up resources...")
+        self.logger.info("Cleaning up resources...")
         await self.controller.cleanup()
         self.gpio.cleanup()
 
@@ -106,7 +118,7 @@ if __name__ == "__main__":
     loader_system = LoaderSystem()
 
     async def shutdown():
-        logger.info("Shutting down...")
+        loader_system.logger.info("Shutting down...")
         await loader_system.cleanup()
         sys.exit(0)