Skip to content

System Setup

Carlos Henrique Craveiro Aquino Veras edited this page Dec 4, 2024 · 3 revisions

Overview

This section provides step-by-step guidance for assembling the hardware components of the Auto-Aiming System and setting up the necessary software. Follow these instructions to ensure proper system configuration and functionality.

hardware

1. Components List

The project requires the following components:

Hardware

  • Raspberry Pi 4: Main processing unit for image acquisition and target segmentation.
  • Raspberry Pi Camera V2: High-definition camera for real-time video capture.
  • ESP32-WROOM: Microcontroller responsible for PID control and servo actuation.
  • Pan-Tilt Mechanism: A 3D-printed structure designed to mount and control the Raspberry Pi Camera.
  • 9G Servo Motors (x2): Control pan (Z-axis) and tilt (X-axis) movements.
  • I2C Interface: Communication bridge between Raspberry Pi and ESP32.
  • Additional items:
    • Breadboard and jumper wires
    • Power supply for Raspberry Pi and ESP32
    • Screwdrivers and assembly tools

Software Dependencies

  • OpenCV 2 (for C++): For image processing.
  • GStreamer: For the video streaming pipeline between the Raspberry Pi and the Raspberry Pi Camera V2.

2. Pan-Tilt Mechanism Assembly

Download the 3D Model

We used the Servo Pan Tilt - Raspberry Pi Camera model available on Thingiverse. This model is licensed under Creative Commons - Attribution - Share Alike (CC BY-SA).

3D Printing Components

  1. Download the STL files from Thingiverse.
  2. Use a standard 3D printer to print the components:
    • Recommended material: PLA or ABS.
    • Layer height: 0.2 mm.
    • Infill: 20% for a balance between strength and print time.

Assembly Instructions

  1. Attach the Servos:
    • Fix the first servo to the base to control the rotation along the Z-axis (pan).
    • Mount the second servo to the tilt arm to control the X-axis rotation.
  2. Install the Camera:
    • Secure the Raspberry Pi Camera V2 to the designated slot on the tilt arm.
    • Ensure proper alignment for stable image capture.

3. Wiring Connections

Raspberry Pi to ESP32 (I2C Interface):

Pin (Raspberry Pi) Pin (ESP32)
GPIO 2 (SDA) GPIO 21
GPIO 3 (SCL) GPIO 22
GND GND

Servo Motors to ESP32:

Servo Pin ESP32 Pin
Pan Servo GPIO 15
Tilt Servo GPIO 14
Power (VCC) 5V
Ground (GND) GND

Camera Connection:

  • Connect the Raspberry Pi Camera V2 to the CSI port on the Raspberry Pi.

4. Software Setup

Raspberry Pi: Install OpenCV 2 (C++)

  1. Update the system:
    sudo apt update && sudo apt upgrade
  2. Install OpenCV development libraries:
    sudo apt install libopencv-dev
  3. Test OpenCV with a sample C++ program:
    #include <opencv2/opencv.hpp>
    #include <iostream>
    
    int main() {
        cv::Mat img = cv::imread("test_image.jpg");
        if (img.empty()) {
            std::cout << "Image not found!" << std::endl;
            return -1;
        }
        cv::imshow("Test Image", img);
        cv::waitKey(0);
        return 0;
    }
    Compile the program using:
    g++ -o test_opencv test_opencv.cpp `pkg-config --cflags --libs opencv4`

Raspberry Pi: Install GStreamer

  1. Install GStreamer and related plugins:
    sudo apt install gstreamer1.0-tools gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly
  2. Test the pipeline with the Raspberry Pi Camera:
    libcamera-vid --inline --width 640 --height 480 --timeout 0 -o - | gst-launch-1.0 fdsrc ! decodebin ! videoconvert ! appsink

5. Power Setup

  • Use a reliable 5V, 2.5A power supply for the Raspberry Pi.
  • Power the ESP32 using either:
    • A 5V USB connection.
    • The 5V and GND pins on the ESP32 board.

6. Final Assembly and Testing

  1. Secure all components to ensure stability.
  2. Verify wiring connections.
  3. Power on the system and manually test the pan-tilt mechanism by sending test signals to the servos.

With the hardware and software setup complete, proceed to the Image Processing section for details on the image processing pipeline.