Skip to content

Exo1i/Tactic-SW

Repository files navigation

๐ŸŽฎ Tactic ๐Ÿค–

A collection of interactive games combining physical hardware control and computer vision through a modern web interface.

Developed as a project for the Advanced Microprocessors course.

This project is dedicated to our incredible team of collaborators whose innovation, persistence, and teamwork made it all possible.

๐Ÿ” Overview

Tactic is a platform that integrates computer vision, machine learning, and robotic control to create engaging physical games that can be played through a web interface. The system uses a camera to observe the physical game state, AI to understand what's happening, and controls robotic components via an ESP32 microcontroller to manipulate physical game pieces.

๐Ÿ’ป Technologies Used

Backend

  • FastAPI: High-performance Python web framework for building APIs
  • OpenCV: Computer vision library for image processing and analysis
  • YOLOv5: Real-time object detection for identifying game pieces
  • WebSockets: Real-time bidirectional communication
  • asyncio: Asynchronous I/O for handling concurrent operations
  • NumPy: Scientific computing library for numerical operations

Hardware Control

  • ESP32: Microcontroller for controlling physical game components
  • Arduino: Programming environment for the ESP32
  • Servo Motors: For precise mechanical movements
  • Stepper Motors: For rotation and positioning
  • Relays: For controlling different game components

Frontend

  • Next.js: React framework for building the web interface
  • React: JavaScript library for building user interfaces
  • TailwindCSS: Utility-first CSS framework
  • WebSockets: Client-side implementation for real-time communication

๐Ÿ—๏ธ System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     WebSockets     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     WebSockets     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚             โ”‚<โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€>โ”‚             โ”‚<โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€>โ”‚             โ”‚
โ”‚  Next.js    โ”‚    JSON Messages   โ”‚  FastAPI    โ”‚    JSON Commands   โ”‚    ESP32    โ”‚
โ”‚  Frontend   โ”‚                    โ”‚  Backend    โ”‚                    โ”‚  Controller โ”‚
โ”‚             โ”‚<โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚             โ”‚                    โ”‚             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    Video Frames    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                        โ”‚                                    โ”‚
                                        โ”‚                                    โ”‚
                                  โ”Œโ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”                        โ”Œโ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”
                                  โ”‚ Computer  โ”‚                        โ”‚ Physical  โ”‚
                                  โ”‚ Vision &  โ”‚                        โ”‚ Hardware  โ”‚
                                  โ”‚ AI Models โ”‚                        โ”‚ Componentsโ”‚
                                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“ก WebSocket Communication

The project implements a three-layer WebSocket communication system:

  1. Frontend to Backend WebSockets:

    • Each game connects to a specific WebSocket endpoint (ws://localhost:8000/ws/{game_id})
    • Sends configuration data and (for some games) camera frames to the backend
    • Receives game state updates, processed frames, and arm movement status
  2. Backend to ESP32 WebSockets:

    • The backend maintains a WebSocket connection to the ESP32 (ws://192.168.168.84:80)
    • Sends JSON commands to control game-specific hardware components
    • Implements auto-reconnect and command retry logic for reliable operation
  3. ESP32 Internal WebSocket Server:

    • The ESP32 runs a WebSocket server that listens for commands
    • Handles game switching, servo control, and motor movements
    • Returns success/failure status for each command

๐ŸŽฒ Games

Memory Matching ๐Ÿง 

A vision-based memory matching game with robotic arm interaction. The system detects card positions, manipulates cards with a robotic arm, and uses either color detection or YOLO object detection to identify matches.

Tic Tac Toe โŒโญ•

A classic game where a robotic arm plays against the user, using computer vision to track the board state.

Rubik's Cube Game ๐ŸŸฉ๐ŸŸฅ๐ŸŸฆ

The system detects a Rubik's cube's state and controls a mechanism to solve it.

Shell Game ๐Ÿฅš

A classic shell game with computer vision to track the positions of cups and a hidden ball.

Target Shooter ๐ŸŽฏ

A shooting game where the system uses vision to aim at targets.

๐Ÿ”Œ ESP32 Integration

The ESP32 is programmed with Arduino to control various hardware components:

  • Manages different game modes through relay control
  • Controls servo motors for precise arm movements
  • Drives stepper motors for rotation mechanisms
  • Handles electromagnets for picking up game pieces

The ESP32 WebSocket server processes JSON messages with the following structure:

{
  "action": "switch|command",
  "game": "ARM|SHOOTER|RUBIK",  // for "switch" action
  "command": "servo_angles_or_game_specific_command"  // for "command" action
}

๐Ÿ› ๏ธ Setup and Installation

Prerequisites

  • Python 3.8+
  • Node.js 14+
  • ESP32 with appropriate circuitry

Backend Setup

cd backend
pip install -r requirements.txt
python main.py

Frontend Setup

npm install
npm run dev

ESP32 Setup

  1. Install Arduino IDE
  2. Install ESP32 board support
  3. Upload the esp32_webserver.ino sketch to your ESP32

๐Ÿ“‚ Project Structure

  • /backend - FastAPI backend server
    • /games - Game-specific backend logic
    • /utils - Utility functions including ESP32 WebSocket client
  • /src - Next.js frontend
    • /app - Pages and components
    • /app/games - Game-specific frontend implementations

๐Ÿ‘จโ€๐Ÿ’ป Meet the Team ๐Ÿ‘ฉโ€๐Ÿ’ป

This project was brought to life by a dedicated team of collaborators:

Profile Contributor
Abdelrahman Abdelrahman Adel Hashiem (@Abdelrahman-Adel610)
Ahmed Fathy Ahmed Fathy (@ahmedfathy0-0)
Ahmed Ellabban Ahmed Ellabban (@ahmedGamalEllabban)
Alieldin Alaa Alieldin Alaa (@AliAlaa88)
Alyaa Ali Alyaa Ali (@Alyaa242)
Amira Khalid Amira Khalid (@AmiraKhalid04)
Mohamed Emad Mohamed Emad (@engmohamed-emad)
Habiba Ayman Habiba Ayman (@habibayman)
Saif Saif (@im-saif)
Karim Zakzouk Karim Zakzouk (@KarimZakzouk)

We extend our heartfelt appreciation to each member of this incredible team for their dedication, creativity, and collaborative spirit in bringing Tactic to life. โค๏ธ

๐Ÿ“œ License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 7