Control_ROV
PublicLoading 3D model… large boards can take a moment.
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
-
Update System
sudo apt update && sudo apt upgrade -
Install Python and Flask
sudo apt install python3-full -y sudo apt-get install python3-flask -
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 -
Enable Interfaces
sudo raspi-configAnd navigate to: Interfacing Options → Enable I2C → Enable SPI.
-
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 -
Configure Automatic Startup
sudo nano /etc/rc.localAdd 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 0This 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.
-
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 -
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
| Function | GPIO Pin | Physical Pin | Connected To |
|---|---|---|---|
| CS (Chip Select) | GPIO 8 | Pin 24 | ADC MCP3208 |
| CLK (Clock) | GPIO 11 | Pin 23 | ADC MCP3208 |
| DOUT | GPIO 9 | Pin 21 | ADC MCP3208 |
| DIN | GPIO 10 | Pin 19 | ADC MCP3208 |
| Digital Output 1 | GPIO 5 | Pin 29 | Digital Output |
| Digital Output 2 | GPIO 6 | Pin 31 | Digital Output |
| Digital Output 3 | GPIO 16 | Pin 36 | Digital Output |
| Digital Output 4 | GPIO 26 | Pin 37 | Digital Output |
| PWM Channel 0 (A) | GPIO 12 | Pin 32 | PWM MDI for ECU |
| PWM Channel 1 (A) | GPIO 13 | Pin 33 | PWM MS for ECU |
| PWM Channel 1 (B) | GPIO 19 | Pin 35 | PWM MDD for ECU |
| PWM Channel 0 (B) | GPIO 18 | Pin 12 | Auxiliary PWM (Camera) |
| SDA | GPIO 2 | Pin 3 | MPU-6050 Accelerometer |
| SCL | GPIO 3 | Pin 5 | MPU-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 Color | Motor Color |
|---|---|
| Yellow | Blue |
| Black | Green |
| Red | White |
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-Streamerfor 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:
| Route | Method | Description |
|---|---|---|
/ | GET | Serves the main user interface (index.html). |
/gamepad_data | POST | Receives axes and button data from the controller. |
/update_pid | POST | Updates $K_p$, $K_i$, and $K_d$ coefficients in real-time. |
/read_all | GET | Returns all 8 ADC channel values in JSON format. |
/toggle | POST | Switches the state of a specific GPIO output (e.g., lights). |
/toggle_pid | POST | Enables or disables the depth stabilization loop. |
/get_all_data | GET | Fetches telemetry (pitch, roll, depth, motor states). |
/system_command | POST | Executes 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 Function | Specific Feature | JS Action | Backend Request |
|---|---|---|---|
| PID Tuning | Update coefficients | Form Submission | POST /update_pid |
| Telemetry | Update readings | setInterval() | GET /get_all_data |
| Manual Control | Gamepad input | updateGamepadStatus() | POST /gamepad_data |
| GPIO Toggle | Auxiliary triggers | togglePin(pin) | POST /toggle |
| Datalogger | Recording data | start-btn click | Client-side logic |
| System | Power off / resset | system_comand() | POST /system_command |
No comments yet. Be the first to ask about this board.