Skip to content

Repository files navigation

CoachBuddy

AI-powered basketball coaching system with gimbal tracking, computer vision shot analysis, and real-time feedback.

Built by Rishith Chennupati


Overview

CoachBuddy is an open-source basketball training system that uses a phone mounted on an Arduino-controlled gimbal to track a player's movements, analyze shooting form using computer vision, and provide real-time coaching feedback through an iOS app.

How It Works

  1. Mount your phone on the gimbal stand at the court
  2. Track — The gimbal follows your movement using servo motors and position detection
  3. Analyze — Python CV pipeline detects shot attempts, tracks body pose, and analyzes form
  4. Feedback — The iOS app shows real-time metrics, shot accuracy, and coaching suggestions

System Architecture

┌─────────────────┐ WiFi/BLE ┌──────────────────┐
│ iOS App │◄────────────────►│ Arduino Gimbal │
│ (SwiftUI) │ │ (Servo Control) │
│ │ └──────────────────┘
│ - Live View │ │
│ - Shot Metrics │ Mounted Phone
│ - Form Score │ Camera Feed
│ - History │ │
└────────┬─────────┘ ▼
│ ┌──────────────────┐
│ WebSocket │ Python CV Server │
└──────────────────────────►│ │
│ - MediaPipe Pose│
│ - Shot Detection│
│ - Form Analysis │
│ - Angle Scoring │
└──────────────────┘

Components

1. Gimbal Controller (firmware/)

Arduino-powered 2-axis gimbal that tracks the player and keeps the camera centered. Uses servo motors controlled via PCA9685 with smooth PID-based tracking.

2. Computer Vision (cv/)

Python pipeline using MediaPipe Pose for real-time body tracking. Analyzes shooting form by measuring joint angles at key phases: set point, release, and follow-through. Detects shot attempts and tracks ball trajectory.

3. iOS App (ios-app/)

SwiftUI app that displays the live camera feed, overlays shot metrics, provides coaching feedback, and tracks training history over time.

Hardware Requirements

ComponentPurposeEst. Cost
Arduino Uno R4 WiFiGimbal controller~$30
PCA9685 PWM DriverServo control~$8
2x MG996R ServosPan/tilt gimbal~$20
Phone mount bracketCamera mounting~$10
6V 5A Power SupplyServo power~$12
3D-printed gimbal frameStructure~$8

Total: ~$88

Software Requirements

Python (CV Server)

pip install -r requirements.txt

iOS App

  • Xcode 16+
  • iOS 18+
  • Swift 6

Firmware

  • Arduino IDE
  • Libraries: WiFiS3, Adafruit_PWMServoDriver, Wire

Quick Start

1. Flash the Gimbal

# Open firmware/gimbal-controller/gimbal-controller.ino in Arduino IDE# Create credentials.h with your WiFi SSID/password# Upload to Arduino

2. Start the CV Server

cd cv
python server.py --port 8765

3. Launch the iOS App

open ios-app/CoachBuddy.xcodeproj
# Build and run on your iPhone# Enter the CV server IP address in Settings

Shot Analysis Metrics

MetricWhat It Measures
Elbow AngleAlignment at set point (ideal: 85-95°)
Release AngleWrist angle at ball release (ideal: 45-55°)
Follow-ThroughArm extension after release (ideal: >160°)
Knee BendLower body engagement (ideal: 100-120°)
Balance ScoreShoulder-hip alignment during shot
Arc ConsistencyShot trajectory repeatability

Project Structure

CoachBuddy/
├── firmware/
│ ├── gimbal-controller/ # Arduino gimbal control + PID tracking
│ └── sensor-hub/ # IMU sensor data collection
├── cv/
│ ├── server.py # WebSocket CV server
│ ├── analysis/
│ │ ├── shot_detector.py # Detect shot attempts from pose data
│ │ ├── form_analyzer.py # Score shooting form angles
│ │ └── trajectory.py # Ball trajectory tracking
│ ├── models/
│ │ └── shot_classifier.py # ML shot type classification
│ └── utils/
│ ├── pose.py # MediaPipe pose utilities
│ ├── angles.py # Joint angle calculations
│ └── drawing.py # Visualization overlays
├── ios-app/
│ └── CoachBuddy/
│ ├── Views/ # SwiftUI views
│ ├── ViewModels/ # MVVM view models
│ ├── Models/ # Data models
│ ├── Services/ # WebSocket, networking
│ └── Components/ # Reusable UI components
├── tests/
│ └── cv/ # Python CV tests
├── docs/ # Documentation
└── scripts/ # Utility scripts

License

MIT License — see LICENSE

Acknowledgments

Built with MediaPipe, OpenCV, Arduino, and SwiftUI. Inspired by wanting to make basketball coaching accessible to everyone.

About

An AI basketball coach that uses a camera gimbal and computer vision to analyze your shots and give real-time feedback through an iOS app.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages