ROBOTICS & COMPUTER VISION

DUAL STEPPER CAMERA

An endless-spin, AI-tracking camera system.

1. The "Why": Autonomous Tracking

Capturing dynamic action often requires a camera operator to keep the subject in frame. I wanted to build a system that could do this autonomously, specifically for tracking a ball or a moving object.

The challenge with traditional pan/tilt systems is the wiring. If the subject circles the camera multiple times, wires can get twisted and snap. My goal was to design a system where the top axis (and the camera) could spin endlessly without any physical wire constraints.

2. The "How": System Architecture

Tech Stack

  • Microcontroller: 2x ESP32 (Wireless Communication via ESP-NOW)
  • Actuators: NEMA 17 Stepper Motors with A4988 Drivers
  • Vision: OpenCV + Python (Object Detection on Host PC)
  • Power: 12V Slip Ring or LiPo Battery (for the rotating head)
  • Fabrication: 3D Printed PLA Parts (Gimbal Mechanism)

Wireless & Endless Spin Architecture

To solve the "tangled wire" problem, the system is split into two independent units that communicate wirelessly. This allows the top unit (Pan/Tilt Head) to rotate 360° continuously without any cable wrapping.

HOST COMPUTER
OpenCV Processing Target Calculation
↓ USB / WiFi
BASE STATION (ESP32 #1)
Controls Pan Motor (Bottom) Transmits Tilt Data
↓ ESP-NOW (Wireless)
ROTATING HEAD (ESP32 #2)
Controls Tilt Motor (Top) Battery Powered

Hardware Wiring

ESP32 GPIO 12/14
A4988 DRIVER Step / Dir
NEMA 17 Stepper Motor

Base Unit (Stationary)

This unit sits on the tripod. It houses the primary Pan Motor (NEMA 17) which rotates the entire upper assembly. It receives target coordinates from the PC and handles the heavy lifting of spinning the rig. It also acts as the wireless transmitter for the tilt commands.

Rotating Head (Mobile)

Mounted on top of the pan motor's shaft. It contains the Camera, the Tilt Motor, and a secondary ESP32. Because it receives commands wirelessly via ESP-NOW, it has zero data cables connecting it to the ground. Power is supplied via a small LiPo battery or a slip ring, enabling infinite rotation.

Control Loop & PID

Camera Feed OpenCV (Color/Shape Mask) Centroid (X, Y) Error Calculation PID Controller Motor Steps

The control system runs a closed-loop feedback mechanism. The computer processes the video feed frame-by-frame:

  • Detection: Converts the frame to HSV color space and masks for the specific color of the ball. Contours are found to determine the center point (centroid).
  • Error Calculation: Calculates the distance (in pixels) between the ball's centroid and the center of the image frame.
  • PID Control: A Proportional-Integral-Derivative controller computes the required motor speed.
    • Proportional: Moves faster if the error is large.
    • Integral: Corrects for steady-state error (if the camera is slightly off).
    • Derivative: Dampens the movement to prevent overshooting as the camera reaches the target.