Control_ROV

Public

@tdominguezmasciale

Download board files

Files for version 1. Pick what you came for.

Share Control_ROV

Check access before sharing the link.

Who can open this board

Anyone can open this board. No sign-in is required.

This link opens the latest version. Copying it does not grant additional access.

Loading…

README

ROV Control System

This project implements a local network-controlled ROV system. It features a web-based control interface, real-time video streaming, depth control via PID, and inertial measurement capabilities. The system is built around a Raspberry Pi 4B as the central processing unit. This project can be run without hardware connections for testing purposes.


Build and working ROV running the control system.

Components and Technologies Used

Hardware

  • Raspberry Pi 4B: Main processor serving as both web server and GPIO manager for hardware control.
  • ESCs: Blue Robotics BESC-R1 electronic speed controllers for T100 thrusters.
  • Thrusters: Blue Robotics T100 thrusters for ROV propulsion.
  • IMU MPU6050: GY521 module with MPU6050 inertial measurement unit (accelerometer + gyroscope).
  • Relays: SONGLE SRD-05VDC-SL-C relays for safe control of external loads.
  • ADC Converter MCP3208: Analog-to-digital converter for pressure sensor and analog signals.
  • Web Camera: Real-time video capture and streaming.
  • Depth Sensor MPX5100DP: Differential pressure sensor for depth measurement.

Frameworks and Libraries

  • Flask: Web server framework for control interface.
  • HTTP: Communication protocol between web interface and ROV.
  • MJPG-Streamer: Real-time JPEG streaming over IP network.
  • RPi.GPIO: Raspberry Pi GPIO control library.
  • Custom Libraries:
    • pid.py: Discrete PID controller for depth control.
    • esc.py: ESC motor controller for thruster speed/direction.
    • adc.py: MCP3208 analog signal reading.
    • filters.py: Signal filtering for motor control.
    • mpu6050.py: MPU6050 accelerometer/gyroscope handler.

Setup and Installation

  1. Update System

    sudo apt update && sudo apt upgrade
    
    
  2. Install Python and Flask

     sudo apt install python3-full -y
     sudo apt-get install python3-flask
    
  3. Install MJPG-Streamer: A utility that allows streaming video from a USB camera via HTTP, used for real-time visualization of the ROV's surroundings.

    sudo apt install build-essential libjpeg-dev imagemagick libv4l-dev git cmake uvcdynctrl -y cd ~
    git clone [https://github.com/jacksonliam/mjpg-streamer.git](https://github.com/jacksonliam/mjpg-streamer.git)
    cd mjpg-streamer/mjpg-streamer-experimental
    make
    sudo make install
    
  4. Enable Interfaces

    sudo raspi-config 
    

    And navigate to: Interfacing Options → Enable I2C → Enable SPI.

  5. Configure pigpiod Service: pigpiod is a utility that runs the pigpio library as a background process. This allows precise control of the Raspberry Pi's GPIO pins, necessary for sending PWM signals to the motors or ESCs. Enabling it as a service allows it to start automatically with the system and be ready before running the backend.

        sudo apt install pigpio
        sudo systemctl enable pigpiod
        sudo systemctl start pigpiod
    
  6. Configure Automatic Startup

        sudo nano /etc/rc.local
    

    Add the following (adjust paths as needed):

    
    #!/bin/sh -e
    
    sleep 5
    
    cd /home/tobias/mjpg-streamer/mjpg-streamer-experimental
    ./mjpg_streamer -i "./input_uvc.so -r 640x480 -f 30" -o "./output_http.so -w ./www" &
    
    sleep 10
    cd /home/tobias/ControlROV_01/
    python /home/tobias/ControlROV/app.py &
    
    exit 0
    

    This automatically launches the video server and the Flask backend at system startup. The sleep command ensures that the camera and network are ready before starting the processes. It is important to note that the paths used (/home/tobias/...) must be adapted to the file structure of the system where the project is implemented.

  7. Verify Services at Startup: This allows checking that the rc.local file executes correctly at startup, including the camera and Flask server.

    systemctl status rc-local.service
    
  8. IP Address Assignment Configure your router's DHCP settings to assign a static IP to the Raspberry Pi based on its MAC address (e.g., 192.168.0.160).

After this setup is done, the website will load on power on so we can directly access it via the browser of a device in the same network, in the IP address of the RaspberryPi, in the port 5000.

Pinout Configuration

FunctionGPIO PinPhysical PinConnected To
CS (Chip Select)GPIO 8Pin 24ADC MCP3208
CLK (Clock)GPIO 11Pin 23ADC MCP3208
DOUTGPIO 9Pin 21ADC MCP3208
DINGPIO 10Pin 19ADC MCP3208
Digital Output 1GPIO 5Pin 29Digital Output
Digital Output 2GPIO 6Pin 31Digital Output
Digital Output 3GPIO 16Pin 36Digital Output
Digital Output 4GPIO 26Pin 37Digital Output
PWM Channel 0 (A)GPIO 12Pin 32PWM MDI for ECU
PWM Channel 1 (A)GPIO 13Pin 33PWM MS for ECU
PWM Channel 1 (B)GPIO 19Pin 35PWM MDD for ECU
PWM Channel 0 (B)GPIO 18Pin 12Auxiliary PWM (Camera)
SDAGPIO 2Pin 3MPU-6050 Accelerometer
SCLGPIO 3Pin 5MPU-6050 Accelerometer

Boot Status Indicator (GPIO 16)

To provide a "plug-and-play" experience without a diagnostic screen, GPIO 16 (connected to a relay and high-intensity light) is activated as soon as the backend begins its boot sequence. Once the Flask server is fully initialized and the network is ready for connections, the light turns off automatically, signaling that the ROV is ready for operation.

ESC Wiring Standardization

Maintaining consistent wiring ensures predictable motor rotation direction:

Motor Phase to ESC Connection:

  • Phase 1 (ESC): Blue (motor)
  • Phase 2 (ESC): Green (motor)
  • Phase 3 (ESC): White (motor)
ESC ColorMotor Color
YellowBlue
BlackGreen
RedWhite

Project Structure

    ControlROV/
    ├── app.py                 # Main Flask application
    ├── pid.py                 # PID controller implementation
    ├── esc.py                 # ESC motor controller
    ├── adc.py                 # MCP3208 ADC interface
    ├── filters.py             # Signal filtering utilities
    ├── mpu6050.py             # IMU interface
    ├── static/                # Web static files
    │   ├── style.css/ 
        ├── scripts.js/       
    ├── templates/      
    │   └── index.html          # HTML
    ├── PCB/                    # PCB diagrams and schematics
    │   └── Modelos3D           # 3D Modeles
    │   └── PCB.kicad_pcb
    │   └── PCB.kicad_pro
    │   └── PCB.kicad_sch

Software Architecture

This section details the software design of the ROV control system, focusing on the interaction between the Backend (hardware logic/control) and the Frontend (web-based user interface).


High-Level Architecture

Although the Flask server and hardware control run on the same Raspberry Pi 4B, the system is conceptually divided into three layers to ensure clear separation of responsibilities:


High-Level Architecture.

  • ROV (Logic & Hardware): Low-level Python scripts interacting with motors, ESCs, and sensors via GPIO, I2C, and SPI.
  • Server (Flask): The bridge that manages state, processes requests from the user, and communicates with the hardware layer.
  • Web Page (Frontend): The pilot's dashboard for real-time monitoring and manual control.

Backend: Control and Communication (Python & Flask)

The backend acts as the brain of the ROV. It manages sensor data acquisition, real-time video streaming, and the PID control loop for depth stabilization.

Main Responsibilities

  • Control Logic: Execution of the discrete PID algorithm and motor mixing.
  • Hardware Interface: Communication with the MCP3208 (ADC) and MPU6050 (IMU).
  • API Management: Handling HTTP routes for bidirectional data flow.
  • Streaming: Integration of MJPG-Streamer for low-latency video over IP.


Backend flow diagram.


Real-time visualization of the PID controller maintaining depth stability.

API Routes

The following endpoints allow the Frontend to interact with the ROV's logic:

RouteMethodDescription
/GETServes the main user interface (index.html).
/gamepad_dataPOSTReceives axes and button data from the controller.
/update_pidPOSTUpdates $K_p$, $K_i$, and $K_d$ coefficients in real-time.
/read_allGETReturns all 8 ADC channel values in JSON format.
/togglePOSTSwitches the state of a specific GPIO output (e.g., lights).
/toggle_pidPOSTEnables or disables the depth stabilization loop.
/get_all_dataGETFetches telemetry (pitch, roll, depth, motor states).
/system_commandPOSTExecutes OS-level commands like Reboot or Shutdown.

Frontend: Web-Based User Interface

The frontend is built using HTML, CSS, and vanilla JavaScript. It uses asynchronous HTTP requests to update telemetry and send commands without refreshing the page.

Key JavaScript Functionalities

General FunctionSpecific FeatureJS ActionBackend Request
PID TuningUpdate coefficientsForm SubmissionPOST /update_pid
TelemetryUpdate readingssetInterval()GET /get_all_data
Manual ControlGamepad inputupdateGamepadStatus()POST /gamepad_data
GPIO ToggleAuxiliary triggerstogglePin(pin)POST /toggle
DataloggerRecording datastart-btn clickClient-side logic
SystemPower off / ressetsystem_comand()POST /system_command
Comments

No comments yet. Be the first to ask about this board.

Ask about this board

Sign in to BoardRepo

New here? Signing in creates your account; there is no separate sign-up.