Skip to content

Latest commit

Β 

History

64 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏭 Fully Automated Industrial Inspection & Sorting System with Digital Twin

AI Vision β€’ Robotics Optimization β€’ MATLAB β€’ CoppeliaSim β€’ Hardware-In-The-Loop

Python PyTorch MATLAB CoppeliaSim Arduino


πŸŽ₯ Full System Demonstration

Full System Demo

This demonstration shows the complete industrial workflow:

  • Conveyor monitoring
  • AI vision inspection
  • CNN classification
  • Expert system decision making
  • MATLAB robot controller
  • Optimization-based path planning
  • CoppeliaSim digital twin execution
  • Arduino HMI synchronization
  • OK and Defective sorting cycles

πŸ“Œ Project Overview

This project presents a complete Cyber-Physical Production System (CPPS) designed for automated industrial quality inspection and intelligent sorting.

The system combines Artificial Intelligence, Robotics, Optimization Algorithms, Digital Twin Technology, TCP/IP Communication, and Hardware-In-The-Loop integration to simulate a modern Industry 4.0 manufacturing cell.

A camera-based inspection system analyzes industrial casting parts moving on a conveyor. A custom Convolutional Neural Network (CNN) classifies each part as either OK or Defective.

The AI decision is translated by an Expert System into robotic actions, which are executed through MATLAB, optimized using multiple planning algorithms, and visualized in real-time inside a CoppeliaSim Digital Twin environment.

The final system performs fully automated inspection and sorting without human intervention.


πŸš€ Key Features

  • Real-Time AI Vision Inspection
  • Custom CNN Defect Detection Model
  • Expert System Decision Layer
  • TCP/IP Distributed Architecture
  • MATLAB Robotics Control Center
  • Forward & Inverse Kinematics
  • Multi-Algorithm Optimization Framework
  • CoppeliaSim Digital Twin
  • Hardware-In-The-Loop Integration
  • Arduino LCD & Status Indicators
  • Autonomous Conveyor-Based Sorting
  • Manual and Automatic Operating Modes
  • Emergency Stop Functionality

πŸ— System Architecture

Industrial Camera
        β”‚
        β–Ό
Image Acquisition
        β”‚
        β–Ό
CNN Vision Model
        β”‚
        β–Ό
Expert System
        β”‚
        β–Ό
TCP/IP Communication
        β”‚
        β–Ό
MATLAB Controller
        β”‚
        β–Ό
Optimization Algorithms
        β”‚
        β–Ό
Inverse Kinematics
        β”‚
        β–Ό
UR5 Robot
        β”‚
        β–Ό
Pick & Place Action
        β”‚
        β–Ό
Arduino HMI Feedback

🌐 Communication Architecture

The project operates using a distributed communication framework.

        +-------------------------+
        |      CoppeliaSim        |
        | Conveyor + UR5 + Sensor |
        +-------------------------+
                    |
                    | Port 19000
                    |
                    β–Ό

           TCP/IP
        +-------------------------+
        |         MATLAB          |
        |  IK / FK / Optimizers   |
        +-----------+-------------+
                    |
                    | Port 65432
                    |
                    β–Ό
        +-------------------------+
        |      Python AI Core     |
        | CNN + Expert System     |
        +-----------+-------------+
                    |
                    | Port 19001
                    |
                    β–Ό
        +-------------------------+
        | Arduino Serial Bridge   |
        | LCD + LEDs              |
        +-------------------------+

      

πŸ”§ Software Stack

Artificial Intelligence

  • Python
  • PyTorch
  • OpenCV
  • TorchVision

Robotics & Control

  • MATLAB
  • Robotics System Toolbox
  • Instrument Control Toolbox
  • Global Optimization Toolbox

Digital Twin

  • CoppeliaSim (V-REP)

Hardware Layer

  • Arduino UNO
  • LCD Display
  • LED Indicators

πŸ“‚ Dataset

The dataset used in this project is not included in this repository due to size limitations. the link to download it : https://www.kaggle.com/datasets/ravirajsinh45/real-life-industrial-dataset-of-casting-product?resource=download

The AI vision model performs binary classification of industrial casting products:

  • OK Parts
  • Defective Parts

Defective samples include multiple defect patterns commonly found in casting processes, such as cracks, scratches, and surface imperfections.

Dataset Structure:

casting_data/
β”œβ”€β”€ train/
β”‚   β”œβ”€β”€ ok_front/
β”‚   └── def_front/
β”‚
└── test/
    β”œβ”€β”€ ok_front/
    └── def_front/

Preprocessing Pipeline:

  1. RGB Image
  2. Grayscale Conversion
  3. Resize to 64Γ—64
  4. Tensor Conversion
  5. CNN Inference

🧠 AI Vision System

The inspection subsystem was developed using PyTorch and OpenCV.

Processing Pipeline:

Camera β†’ Image Processing β†’ CNN β†’ Classification β†’ Expert System

Camera Initialization

Camera Test

Image Processing Pipeline

Processing Pipeline

Histogram Analysis

Histogram Analysis

Detailed Image Analysis

Detailed Analysis


πŸ€– CNN Architecture

The custom CNN architecture was designed specifically for binary defect classification.

Input Image (64Γ—64Γ—1)

        β”‚
        β–Ό

Conv2D (1 β†’ 16)

        β”‚
        β–Ό

ReLU

        β”‚
        β–Ό

MaxPool

        β”‚
        β–Ό

Conv2D (16 β†’ 32)

        β”‚
        β–Ό

ReLU

        β”‚
        β–Ό

MaxPool

        β”‚
        β–Ό

Flatten

        β”‚
        β–Ό

FC (8192 β†’ 128)

        β”‚
        β–Ό

ReLU

        β”‚
        β–Ό

FC (128 β†’ 2)

        β”‚
        β–Ό

Output
(OK / DEFECTIVE)

Training Configuration:

  • Optimizer: Adam
  • Learning Rate: 0.001
  • Loss Function: CrossEntropyLoss
  • Binary Classification
  • Real Industrial Dataset

πŸ“ˆ Model Evaluation

Confusion Matrix

Evaluation Metrics:

  • Accuracy
  • Precision
  • Recall
  • F1 Score
  • Confusion Matrix

🧩 Expert System

The Expert System converts AI predictions into deterministic industrial actions.

Decision Rules:

IF Part = OK
    β†’ Packaging Line
    β†’ Green Bin
    β†’ Y = +500

IF Part = Defective
    β†’ Scrap Bin
    β†’ Red Bin
    β†’ Y = -500

Generated Outputs:

  • Robot Coordinates
  • Sorting Decision
  • Arduino Signals
  • MATLAB Commands

βš™οΈ MATLAB Robotics Control Center

MATLAB acts as the master controller of the entire system.

Responsibilities:

  • TCP Server
  • Robot Control
  • Forward Kinematics
  • Inverse Kinematics
  • Optimization
  • Benchmarking
  • Digital Twin Synchronization

MATLAB GUI

MATLAB – OK Sorting

MATLAB OK

MATLAB – Defective Sorting

MATLAB Defect


πŸš€ Optimization Algorithms

Implemented Path Planners:

  • Analytical Inverse Kinematics
  • Genetic Algorithm (GA)
  • Simulated Annealing (SA)
  • Particle Swarm Optimization (PSO)
  • Pattern Search

Evaluation Criteria:

  • Joint Motion Cost
  • Energy Consumption
  • Position Accuracy
  • Smoothness
  • Computational Time

The GUI supports:

Run ALL & Benchmark Best

for automatic comparison and optimal solution selection.


🌍 Digital Twin Environment

The industrial workcell was modeled inside CoppeliaSim.

Components:

  • Conveyor Belt
  • Proximity Sensor
  • Sorting Stations
  • UR5 Robot
  • Pick-and-Place Workspace

CoppeliaSim Workcell

OK Part

Coppelia OK

Defective Part

Coppelia Defect


πŸ”Œ Hardware-In-The-Loop (HIL)

The project includes a physical Arduino subsystem acting as an industrial HMI.

Features:

  • LCD Display
  • Status LEDs
  • Real-Time Feedback
  • TCP-to-Serial Integration

Arduino Circuit

LCD – OK

LCD OK

LCD – Defective

LCD Defect


βš™οΈ Operating Modes

AUTO Mode

  • Sensor Driven
  • Fully Autonomous
  • Continuous Production

MANUAL Mode

  • User Controlled
  • Editable Coordinates
  • Testing & Debugging

Emergency Stop

Press:

Q

to safely terminate:

  • Python
  • MATLAB
  • Arduino
  • TCP Connections

πŸ“¦ Installation & Setup

1. Clone Repository

git clone https://github.com/USERNAME/Industrial-Sorting-System.git

2. Install Python Packages

pip install torch torchvision opencv-python matplotlib pillow pyserial scikit-learn

3. Install Software

  • MATLAB R2023a or newer
  • CoppeliaSim
  • Arduino IDE

4. Configure Dataset Paths

Update image paths inside:

train_model.py
evaluate_model.py
realtime_conveyor.py

5. Configure Arduino Port

Update COM port in:

bridge.py

if auto-detection fails.


▢️ Execution Order

IMPORTANT:

Run programs in the following order:

  1. Launch CoppeliaSim Scene
  2. Run bridge.py
  3. Open MATLAB GUI
  4. Click Connect
  5. Run realtime_conveyor.py

The system is now fully synchronized.


πŸ† Project Achievements

βœ” AI-Based Defect Detection

βœ” Digital Twin Implementation

βœ” Hardware-In-The-Loop Integration

βœ” Real-Time TCP/IP Communication

βœ” Optimization-Based Motion Planning

βœ” MATLAB-CoppeliaSim Synchronization

βœ” Industrial Automation Workflow

βœ” Industry 4.0 Concepts


🀝 Project Team & Supervision

This project was developed as part of the MAE401 – Artificial Intelligence course at the Faculty of Engineering, Benha University.


Academic Supervision


Dr. Amro Shafik


Project Supervisor


Eng. Mohamed Nasser


Teaching Assistant


Development Team


Mahmoud Mohamed Shamekh


Omar Mahmoud Metwally


Omar Shokran


Mohamed Abdeltawab


Acknowledgments

We would like to express our sincere appreciation to our supervisors for their guidance, support, and valuable feedback throughout the development of this project.

We also thank all team members for their dedication, collaboration, and continuous efforts that contributed to the successful completion of this work.


πŸ“œ License

This repository is intended for educational, research, and demonstration purposes.

Releases

Packages

Contributors

Languages