|
|
@@ -3,25 +3,36 @@ import logging
|
|
|
from robot_control.src.robot.controller import RobotController
|
|
|
from robot_control.src.utils.config import ConfigParser
|
|
|
from robot_control.src.vision.datamatrix import DataMatrixReader
|
|
|
-from robot_control.src.api.i2c_handler import I2C
|
|
|
+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
|
|
|
+from robot_control.src.api.gpio import PiGPIO, MockGPIO
|
|
|
+
|
|
|
+logging.basicConfig(
|
|
|
+ level=logging.INFO,
|
|
|
+ format='%(asctime)s - %(module)s - %(levelname)s - %(message)s',
|
|
|
+)
|
|
|
|
|
|
class LoaderSystem:
|
|
|
def __init__(self):
|
|
|
self.config = ConfigParser().config
|
|
|
gpio_config = self.config.gpio
|
|
|
- self.gpio = PiGPIO([gpio_config.pump_pin, gpio_config.valve_pin], [])
|
|
|
+ if gpio_config.debug:
|
|
|
+ self.gpio = MockGPIO()
|
|
|
+ else:
|
|
|
+ self.gpio = PiGPIO([gpio_config.pump_pin, gpio_config.valve_pin], [])
|
|
|
|
|
|
self.logger = logging.getLogger(__name__)
|
|
|
self.controller = RobotController(self.config, self.gpio)
|
|
|
- self.vision = DataMatrixReader(self.config.vision.camera_id)
|
|
|
+ self.vision = DataMatrixReader(self.config)
|
|
|
self.logger.info("Initializing LoaderSystem")
|
|
|
self.vision.initialize()
|
|
|
- self.i2c = I2C(MCP3428)
|
|
|
+
|
|
|
+ # Use mock I2C device if debug is enabled
|
|
|
+ i2c_device_class = MCP3428 if not self.config.i2c.debug else MockI2C
|
|
|
+ self.i2c = I2C(i2c_device_class)
|
|
|
self.i2c.initialize()
|
|
|
- self.logger.info("I2C initialized for MCP3428")
|
|
|
+ self.logger.info(f"I2C initialized with {i2c_device_class.__name__}")
|
|
|
|
|
|
self.pump_controller = PumpController(self.config, self.gpio, self.logger)
|
|
|
|
|
|
@@ -38,15 +49,12 @@ class LoaderSystem:
|
|
|
try:
|
|
|
readings = await self.i2c.read_channels([1, 3, 4])
|
|
|
for channel, value in readings.items():
|
|
|
- self.logger.info(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)
|
|
|
- # Perform a generic task based on the reading
|
|
|
- if value > 0.5: # Example condition
|
|
|
- self.logger.warning(f"Value {value} on channel {channel} exceeds threshold")
|
|
|
except Exception as e:
|
|
|
self.logger.error(f"Error polling I2C channels: {str(e)}")
|
|
|
await asyncio.sleep(1) # Poll every second
|
|
|
@@ -61,10 +69,11 @@ class LoaderSystem:
|
|
|
if not slot:
|
|
|
break
|
|
|
# Pick and place new cell
|
|
|
- cell_id = self.vision.read_datamatrix()
|
|
|
- if not cell_id:
|
|
|
+ cell_id_str = self.vision.read_datamatrix()
|
|
|
+ if not cell_id_str:
|
|
|
self.logger.debug("No cell detected")
|
|
|
break
|
|
|
+ cell_id = int(cell_id_str)
|
|
|
self.logger.info(f"Processing cell {cell_id}")
|
|
|
cell = self.controller.add_cell(cell_id)
|
|
|
try:
|