Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scuttlebot Predictive Maintenance on QNX

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 the rpi_i2c library) and GPIO (via the rpi_gpio library).


Table of Contents


Repository Navigation

.
├── 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:


Project Overview

This system consists of three distinct layers:

  1. Embedded Control (QNX): Custom ROS 2 nodes (C++/Python) interfacing with I2C/GPIO on the Raspberry Pi.
  2. Data Science (Laptop): A Python pipeline to process ROS 2 bags and train a 1D-CNN.
  3. Edge AI Inference (QNX): A TensorFlow Lite agent running at 20Hz on the robot.

Validation Strategy (Sim-to-Real)

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


System Architecture

The "Test Rig" Robot (Robot A)

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.

The "Validation" Robot (Robot B)

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.

System Schematic

System Schematic

Hardware Setup

1. Sensor Wiring (I2C Bus)

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

2. Motor Wiring (HW-231)

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.


Software Requirements

Host Machine (Development Laptop)

  • 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

Target Machine (Raspberry Pi 4)

  • Operating System: QNX SDP 8.0 (aarch64le).
  • Middleware: ROS 2 Humble (Cross-compiled).
  • Inference Engine: TensorFlow Lite Runtime (2.x).

Installation & Build

1. Build the Robot Software

This project uses a custom build.sh script to cross-compile ROS 2 nodes for QNX.

  1. Source your QNX environment:
    source ~/qnx800/qnxsdp-env.sh
  2. Run the build script:
    ./build.sh
    This compiles the C++ sensor drivers and packages the Python inference nodes.

2. Deploy to Target

  1. Connect the Pi to your network.
  2. Update the IP address in transfer.sh.
  3. Run the deployment script:
    ./transfer.sh
    This copies all binaries, scripts, and libraries to /data/home/qnxuser/ on the Pi.

Running the Demo

I have provided a "One-Click" launch script for the demo.

  1. SSH into the Raspberry Pi:
    ssh qnxuser@<PI_IP_ADDRESS>
  2. Start the System: Run the helper script as root (required for hardware access):
    sudo ./start_robot.sh

What happens next?

  • The script launches 3 Background Nodes:
    1. sensors_node (C++): Reads I2C sensors.
    2. motor_node (Python): Listens for drive commands.
    3. 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.

Reproducing Results from the Report

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/.

1. Convert ROS 2 bag files to CSV

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/csv

2. Train the models on Robot A (Source Domain)

cd robot_a_training
python3 train_model.py

Artifacts 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.

3. Evaluate Sim-to-Real performance on Robot B (Target Domain)

cd ../robot_b_validation
python3 validate_model.py

Artifacts 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.

References & Acknowledgments

Core Frameworks:

Hardware Libraries:

About

project-group-151 created by GitHub Classroom

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages