Skip to content

ARYA-mgc/fault-hawk

Repository files navigation

High-Performance Industrial Fault Detection & Autonomous Recovery System

This repository contains the source code and configuration for an industrial-grade, edge-deployed autonomous monitoring and fault detection system. Engineered specifically for the Raspberry Pi 5 operating within strict determinism requirements, the architecture leverages true real-time multi-threading, hybrid dual AI models, physics-based signal processing, and direct hardware actuation to mitigate critical machinery failures with sub-40 millisecond latency.

Core Architectural Components

Ultra-Low Latency Execution Pipeline

The orchestrator bypasses the Python Global Interpreter Lock (GIL) by utilizing a hybrid multiprocessing and threading architecture. I/O operations (I2C polling, SQLite transactions) operate on the main priority thread, while computationally expensive tasks (FFT operations, TFLite inferences) are executed asynchronously in isolated processes. This guarantees a maximum end-to-end latency of less than 40ms.

Advanced Signal Processing Layer

Raw sensor telemetry is conditioned prior to inference via physics-based processing pipelines:

  • Kalman Filtering: Implements a 1D state estimator to eliminate stochastic noise from sensitive analog readings (e.g., current draw).
  • Z-Score Normalization: Standardizes inputs based on baseline statistics to ensure numerical stability during neural network propagation.
  • Fast Fourier Transform (FFT): Converts high-frequency (1kHz) physical vibration buffers from the time domain into spectral frequency bins to detect mechanical anomalies such as bearing wear and rotor unbalance.

Dual AI Model Fusion

The anomaly detection engine relies on a concurrent dual-model approach, combined via a weighted fusion layer:

  • LSTM Autoencoder (TFLite): A deep learning sequence model tasked with identifying gradual pattern drift over time by calculating reconstruction loss.
  • Isolation Forest: A scikit-learn ensemble algorithm optimized for immediate point-anomaly and sudden spike detection.

Reliability & Resilience

  • Hardware Watchdog Integration: Hooks directly into the Linux kernel via /dev/watchdog to guarantee an autonomous hard-reboot of the edge hardware in the event of a catastrophic OS or orchestrator hang.
  • SQLite Event Logging: Maintains a persistent local database (storage/fault_history.db) logging every anomaly score, recovery action, and sensor state for post-incident forensic analysis.

Hardware Integration Specifications

This software stack requires a Raspberry Pi 5.

I2C Sensor Topology (SDA/SCL Pins 3 & 5)

Sensor Module Physical Measurement I2C Address Required Driver Library
MPU6050 Tri-axial Vibration 0x68 smbus2
ADS1115 Current (via ACS712) 0x48 adafruit-circuitpython-ads1x15
BMP280 Pressure / Temperature 0x76 adafruit-circuitpython-bmp280
INA219 Bus Voltage / Power 0x40 adafruit-circuitpython-ina219

GPIO Pinout Matrix

  • DHT22 (Environmental Humidity): GPIO 4
  • Relay Channel 1 (Primary Machine Power Cutoff): GPIO 17
  • Relay Channel 2 (Secondary/Backup System Actuation): GPIO 27
  • Audio Annunciator (Buzzer): GPIO 22
  • Visual Annunciator (LED Status Panel): GPIO 23

Deployment Procedures

1. Embedded Environment Pre-requisites

Enable the I2C interface and configure the hardware watchdog module on the Raspberry Pi.

sudo raspi-config # Interface Options -> I2C -> Enable

# Load Watchdog Kernel Module
sudo modprobe bcm2835_wdt
echo "bcm2835_wdt" | sudo tee -a /etc/modules

2. Dependency Installation

Initialize the virtual environment or install dependencies directly to the system Python environment.

pip3 install -r requirements.txt

3. Model Compilation & Export

Generate synthetic baselines, train the LSTM and Isolation Forest topologies, convert the LSTM to .tflite, and serialize the models to the ai_engine/models/ directory. This step may be performed on an x86 workstation prior to edge deployment.

python3 ai_engine/model_trainer.py

4. Real-Time Orchestrator Execution

Execution requires elevated privileges to access raw GPIO memory registers and the /dev/watchdog file descriptor.

sudo -E python3 main.py

Production Daemonization (Systemd)

To guarantee high availability, the orchestrator should be configured to initialize on boot and automatically recover from unexpected terminations via a systemd service.

  1. Create the unit file: sudo nano /etc/systemd/system/fault-detection.service
  2. Populate the configuration:
[Unit]
Description=High-Performance Fault Detection Edge Daemon
After=network.target

[Service]
ExecStart=/usr/bin/python3 /home/pi/Real-Time-Fault-Detection/main.py
WorkingDirectory=/home/pi/Real-Time-Fault-Detection
StandardOutput=inherit
StandardError=inherit
Restart=always
User=root
Environment=PYTHONUNBUFFERED=1

[Install]
WantedBy=multi-user.target
  1. Enable and initialize the daemon:
sudo systemctl enable fault-detection.service
sudo systemctl start fault-detection.service
sudo systemctl status fault-detection.service

About

Real-time fault detection and automated self-recovery system for industrial machinery using Edge AI on Raspberry Pi 5 — zero cloud dependency, PREEMPT-RT kernel, dual AI models (Isolation Forest + LSTM Autoencoder).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages