Vision-Guided-Ball-Balancing-2DOF

2DOF Ball Balancing Plate using STM32, OpenCV, and PID Control

System Diagram

Table of Contents


Project Description

Developed during MCTR601 Mechatronics Engineering course (BSc in Mechatronics Engineering) at the German University in Cairo (GUC), this project implements a real-time ball balancing system using computer vision and embedded control to stabilize and track a ball on a 2-degree-of-freedom (2DOF) tilting platform. The primary goal is to design a system that can dynamically stabilize a rolling ball by adjusting the tilt of a platform in both the x and y directions.

System Diagram

Key Features

| Feature | Description | |———|————-| | Multi-Control Strategies | PID, PV (Proportional-Velocity Controller), and LQR for dynamic stabilization | | Trajectory Tracking | Follows predefined paths (circle, figure-8) or user-drawn real-time trajectories via GUI | | Laser Tracking | Ball chases a moving laser dot projected on the platform | | Online Tuning | STM32F103C8T6 communicates online with PC via FTDI Serial Module for parameter tuning and monitoring system states |

Functional Diagram

System Diagram

Technical Stack

Vision System

Control System

GUI Interface

Trajectory tracking

-Circle trajectory

image

System Diagram

Hardware Components

Project Highlights

System Architecture

System Diagram

The system follows a layered architecture structure to ensure modularity, scalability, and maintainability.

This architecture allows for seamless integration between software and hardware for responsive, accurate control.

Hardware

The physical system consists of a flat platform mounted on two servo motors arranged orthogonally, controlling tilt along the X and Y axes.

Technologies

The project integrates several key technologies:

System Diagram

How to Use It

The system is controlled primarily through a Java-based Graphical User Interface (GUI).

  1. Hardware Setup: Ensure the ball balancing platform, servos, webcam, STM32 (Bluepill), FTDI converter, and power supply are correctly connected.
  2. Start Vision System: Run the Python program which uses OpenCV to capture video from the webcam and perform ball/laser tracking. An interface allows selecting the correct camera.
  3. Start GUI: Launch the Java GUI application.
  4. Connect Hardware: Use the GUI to establish communication with the STM32 via the FTDI serial module.
  5. Calibration (if needed): The GUI may offer a calibration mode. The Python vision system includes real-time trackbars for tuning HSV thresholds for ball and laser detection.
  6. Mode Selection: Choose between operating modes like idle, automatic, manual, or calibration via the GUI.
  7. Control Algorithm Selection: Dynamically select the desired control algorithm (PID, PD, LQR, or custom) through the GUI.
  8. Parameter Tuning: Adjust control parameters (Kp, Ki, Kd, EMA alpha, etc.) online via the GUI for fine-tuning the system response.
  9. Setpoints & Trajectories: Set desired ball positions or select/draw predefined trajectories (circle, figure-eight, custom paths) via the GUI. Input desired angular velocity for trajectory execution.
  10. Monitoring: View real-time tracking of the ball’s position on a coordinate grid and visualize system input-output behavior through plotted graphs on the GUI.
  11. Data Logging: Export recorded data as CSV files for offline analysis.
  12. External Control (Optional): The GUI can connect to MATLAB or Python scripts via TCP/IP, allowing control signals to be generated externally, facilitating experimentation with advanced control techniques.

Contributors