This repository contains the complete source code, drivers, and data analysis tools for a Real-Time Predictive Maintenance (PdM) Agent running on the QNX Real-Time Operating System (RTOS) - SDP 8.0.
The project implements a complete AI pipeline: from custom C++ hardware drivers on an embedded target to a Deep Learning model (1D-CNN) trained on real-world fault data.
Demo Objective: > The robot monitors its own physical state (Vibration, Current, Temperature) and uses an onboard AI brain (TensorFlow Lite) to detect "High Load" or "Vibration" faults in real-time.
Important:
The implementation requires root privileges to access the I²C bus and GPIO. The code uses QNX’s I²C API (via therpi_i2clibrary) and GPIO (via therpi_gpiolibrary).
- Repository Navigation
- Project Overview
- System Architecture
- System Schematic
- Hardware Setup
- Software Requirements
- Installation & Build
- Running the Demo
- Reproducing Results from the Report
- References & Acknowledgments
.
├── src/ # ROS 2 nodes running on QNX (drivers, inference, teleop)
│ ├── scuttle_sensors # [C++] Sensor node: reads I2C sensors & publishes /scuttle/data
│ ├── scuttle_driver # [Python] Motor control, Teleop, and TFLite PdM agent
│ └── common # [C] HAL libraries for GPIO and I2C (rpi_gpio, rpi_i2c)
│
├── experiments/ # Data science pipeline (Training + Sim-to-Real Validation)
│ ├── robot_a_training # Train Random Forest + 1D-CNN, export scuttle_model.tflite
│ └── robot_b_validation # Evaluate deployed model on unseen Robot B
│
├── models/ # Deployed models (e.g., scuttle_model.tflite)
├── target_scripts/ # Helper scripts for QNX target (start_robot.sh)
├── cmake/, platform/ # Toolchain and CMake configuration for QNX + ROS 2
├── build.sh, clean.sh # Host build and cleanup scripts
├── transfer.sh # Deploy compiled artifacts to Raspberry Pi over SSH
└── schematic.jpg # Hardware wiring diagram
For more detail, see:
src/README.md– Architecture of the embedded ROS 2 nodes and HAL.experiments/README.md– Data extraction, model training, and Sim-to-Real validation workflow.
This system consists of three distinct layers:
- Embedded Control (QNX): Custom ROS 2 nodes (C++/Python) interfacing with I2C/GPIO on the Raspberry Pi.
- Data Science (Laptop): A Python pipeline to process ROS 2 bags and train a 1D-CNN.
- Edge AI Inference (QNX): A TensorFlow Lite agent running at 20Hz on the robot.
To ensure robustness, this repository implements a strict validation protocol found in experiments/:
- Training: Performed on Robot A (Laminate Floor).
- Validation: Performed on Robot B (Carpeted Floor, Unseen Hardware).
- Metric: The model is evaluated on its ability to generalize to Robot B without retraining.
Full Project Report: Read the detailed PDF Report here
This robot is used for training data collection. It uses a custom H-Bridge driver.
- OS: QNX SDP 8.0
- Middleware: ROS 2 Humble
- Motor Driver: HW-231 (L298N Logic) via Digital GPIO
- Sensors:
- BNO055 (I2C): Accelerometer for Vibration analysis.
- SHT31-D (I2C): Temperature sensor mounted to the motor casing.
- INA219 (I2C): High-side DC Current sensor for load monitoring.
This robot is used for testing. It features different motors and chassis mechanics ("Unseen Hardware") but uses the same control electronics.
- Motor Driver: HW-231 (Transferred from Robot A) via Digital GPIO.
- Sensors: Transferred from Robot A to ensure data consistency.
All sensors share the Raspberry Pi's I2C bus (GPIO 2 & 3). Wire them in parallel using a breadboard.
| Sensor Pin | RPi Pin | Note |
|---|---|---|
| VCC / Vin | Pin 1 (3.3V) | Do not use 5V (Protects Pi Logic) |
| GND | Pin 6 (GND) | Common Ground |
| SDA | Pin 3 (GPIO 2) | I2C Data |
| SCL | Pin 5 (GPIO 3) | I2C Clock |
The HW-231 driver is controlled via direct GPIO.
| Driver Pin | RPi Pin | Function |
|---|---|---|
| VCC / Vin | Pin 2 (5V) | Power for the HW-231 |
| GND | Pin 39 (GND) | Ground |
| N1 (Right Fwd) | Pin 11 (GPIO 17) | Digital Control |
| N2 (Right Rev) | Pin 13 (GPIO 27) | Digital Control |
| N3 (Left Fwd) | Pin 15 (GPIO 22) | Digital Control |
| N4 (Left Rev) | Pin 16 (GPIO 23) | Digital Control |
Critical: The INA219 Current Sensor must be wired in SERIES between the Battery (+) and the Motor Driver (+) input.
- Operating System: Ubuntu 20.04 LTS (or compatible Linux distribution).
- QNX Software Development Platform (SDP): Version 8.0 (Installed and Licensed).
- Python Environment: Python 3.10+.
- Data Science Libraries:
- Core dependencies:
tensorflow,pandas,scikit-learn,seaborn. - Installation: Dependencies are strictly versioned in
experiments/requirements.txt.pip install -r experiments/requirements.txt
- Core dependencies:
- Operating System: QNX SDP 8.0 (aarch64le).
- Middleware: ROS 2 Humble (Cross-compiled).
- Inference Engine: TensorFlow Lite Runtime (2.x).
This project uses a custom build.sh script to cross-compile ROS 2 nodes for QNX.
- Source your QNX environment:
source ~/qnx800/qnxsdp-env.sh
- Run the build script:
This compiles the C++ sensor drivers and packages the Python inference nodes.
./build.sh
- Connect the Pi to your network.
- Update the IP address in
transfer.sh. - Run the deployment script:
This copies all binaries, scripts, and libraries to
./transfer.sh
/data/home/qnxuser/on the Pi.
I have provided a "One-Click" launch script for the demo.
- SSH into the Raspberry Pi:
ssh qnxuser@<PI_IP_ADDRESS>
- Start the System:
Run the helper script as root (required for hardware access):
sudo ./start_robot.sh
- The script launches 3 Background Nodes:
sensors_node(C++): Reads I2C sensors.motor_node(Python): Listens for drive commands.inference_node(Python): Runs the TFLite AI model and prints status.
- It launches 1 Foreground Node:
teleop_drive: Allows you to drive using W/A/S/D keys.
Demo Controls:
W: Drive Forward.S: Drive Reverse.SPACE: Emergency Stop.A/D: Spin Left / Right.Ctrl+C: Safely kills all nodes and exits.
This section explains how to regenerate the quantitative results (training and Sim-to-Real metrics) reported in the project report using the code in experiments/.
From the experiments/ directory:
cd experiments
source ~/ros2_humble/install/setup.bash # Source ROS 2 environment
python3 convert_all_bags.py # Fills robot_a_training/csv and robot_b_validation/csvcd robot_a_training
python3 train_model.pyArtifacts Produced:
output/training_matrix.png– Confusion matrix for Robot A.output/training_report.txt– Full classification report.../../models/scuttle_model.tflite– The TFLite model deployed to QNX.
cd ../robot_b_validation
python3 validate_model.pyArtifacts Produced:
output/validation_matrix.png– Confusion matrix for Robot B (Sim-to-Real).output/validation_report.txt– Metrics that match the Results section of the report.
Note: These three steps fully implement the validation strategy described in the "Methods" and "Results" sections of the project report.
Core Frameworks:
- QNX ROS 2 Port: Built using the official build scripts from QNX.
- TensorFlow Lite for QNX: Ported using the QNX build files.
Hardware Libraries:
- Hardware Samples: Initial sensor integration inspired by the QNX Hardware Component Samples.
