The implementation in src/inference_loop.py provides a robust detection loop with hardware integration.
- Model Support: Runs both Legacy TFLite and Modern ONNX models via IREE runtime.
- Lighting Control: Synchronizes LED lighting with camera capture to ensure consistent image quality.
- Resolution Control: Optimizes local USB camera input for performance.
- Dry Run Mode: Simulutes the entire pipeline for safe testing without hardware.
Control the behavior using environment variables in your .env file.
| Variable | Default | Description |
|---|---|---|
MODEL_PATH |
models/spaghetti_v2.vmfb |
Path to the compiled IREE module. |
THRESHOLD |
0.5 |
Confidence threshold for detection. |
DRY_RUN |
false |
Set to true to simulate hardware interactions. |
| Variable | Default | Description |
|---|---|---|
CAMERA_TYPE |
http |
local (USB) or http (MJPEG stream). |
CAMERA_WIDTH |
640 |
Resolution width for local camera. |
CAMERA_HEIGHT |
480 |
Resolution height for local camera. |
| Variable | Default | Description |
|---|---|---|
LIGHTING_ENABLED |
false |
Enable/Disable lighting synchronization. |
LIGHTING_GCODE_ON |
SET_LED... |
G-code to turn lights ON. |
LIGHTING_GCODE_OFF |
SET_LED... |
G-code to turn lights OFF. |
To verify the logic without connecting a printer or camera:
DRY_RUN=true \
CAMERA_TYPE=local \
LIGHTING_ENABLED=true \
MODEL_PATH=models/model.vmfb \
python3 src/inference_loop.pyThis will:
- Log G-code commands instead of sending them.
- Generate mock images.
- Use a mock model (no inference).
- Log pause commands.