A ROS 2 package for autonomous underwater vehicle navigation and control, designed for the BlueROV2 platform. This system implements computer vision-based tracking, PID control, and autonomous behaviors for submarine competition scenarios.
This project implements an autonomous navigation system for underwater vehicles with the following capabilities:
- Vision-based tracking using YOLOv8 for object detection
- AprilTag detection for precise distance estimation
- PID control for depth and heading stabilization
- State machine for autonomous scanning and chasing behaviors
- MAVROS integration for BlueROV2 communication
- Real-time camera processing for underwater computer vision
- PID Depth Controller: Maintains precise depth control with tunable PID parameters
- PID Heading Controller: Accurate yaw control for navigation
- Manual Control Override: Direct control via MAVROS ManualControl messages
- YOLOv8 Integration: Custom-trained model for underwater object detection
- AprilTag Detection: Precise distance and pose estimation
- Real-time Processing: Camera subscriber with image processing pipeline
- Scanning Mode: Search pattern with controlled depth and heading
- Chase Mode: Vision-guided pursuit of detected targets
- Light Flashing: Automated light control for signaling
- BlueROV2 or compatible ROV
- Onboard computer (Raspberry Pi 4, NVIDIA Jetson, or equivalent)
- Camera system
- Pressure sensor for depth measurement
- Ubuntu 20.04 or later
- ROS 2 (Foxy, Humble, or later)
- Python 3.8+
- ArduSub firmware
# Install ROS 2 (if not already installed)
# Follow official ROS 2 installation guide for your distribution
# Install MAVROS
sudo apt install ros-${ROS_DISTRO}-mavros ros-${ROS_DISTRO}-mavros-extras
# Install Python dependencies
pip install ultralytics opencv-python matplotlib numpy# Create workspace
mkdir -p ~/auvc_ws/src
cd ~/auvc_ws/src
# Clone repository
git clone https://github.com/YOUR_USERNAME/AUV-Group-Github.git
# Build workspace
cd ~/auvc_ws
colcon build --symlink-install
# Source workspace
source ~/auvc_ws/install/setup.bash# Clone ArduPilot
cd ~
git clone https://github.com/ArduPilot/ardupilot.git
cd ardupilot
git submodule update --init --recursive
# Run SITL
cd ~/ardupilot
Tools/autotest/sim_vehicle.py --vehicle=ArduSub --aircraft="bwsibot" -L RATBeach --out=udp:YOUR_COMPUTER_IP:14550The package includes several launch configurations:
ros2 launch intro_to_ros testitall.yamlLaunches the complete autonomous system with PID controllers, YOLO detection, and state machine.
ros2 launch intro_to_ros sitl.yamlRuns the system in Software-In-The-Loop simulation mode.
ros2 launch intro_to_ros PID_depth_test.yamlTests depth control independently.
ros2 launch intro_to_ros PID_heading_test.yamlTests heading control independently.
ros2 launch intro_to_ros YOLO.yamlRuns computer vision system only for testing.
ros2 topic pub /PID/desired_depth mavros_msgs/msg/Altitude "{relative: 0.8}"ros2 topic pub /img/desired_heading std_msgs/msg/Int16 "{data: 45}"ros2 topic pub /img/targetted std_msgs/msg/Bool "{data: true}"/bluerov2/depth(mavros_msgs/Altitude) - Current depth measurement/bluerov2/heading(std_msgs/Int16) - Current heading in degrees/bluerov2/camera/image_raw(sensor_msgs/Image) - Camera feed/img/desired_heading(std_msgs/Int16) - Target heading from vision/img/distance(std_msgs/Float32) - Distance to detected target/img/targetted(std_msgs/Bool) - Target acquisition status
/bluerov2/manual_control(mavros_msgs/ManualControl) - Movement commands/bluerov2/override_rc(mavros_msgs/OverrideRCIn) - Direct RC override (lights)/PID/desired_depth(mavros_msgs/Altitude) - Depth setpoint for PID/PID/desired_heading(std_msgs/Int16) - Heading setpoint for PID
PID controller for depth stabilization with anti-windup and output clamping.
Tunable Parameters (in intro_to_ros/pid_depth.py):
self.kp = 47 # Proportional gain
self.ki = 7 # Integral gain
self.kd = 18 # Derivative gainPID controller for heading/yaw stabilization.
Implements autonomous behaviors with state machine:
- SCANNING: Search pattern at minimum depth
- CHASE: Pursuit mode when target detected
- Automatic state transitions based on vision feedback
Processes camera feed for computer vision pipeline.
Integrates YOLO detection with movement control.
Subscribes to camera feed and runs YOLO inference.
Arms/disarms the vehicle for safety.
Converts pressure sensor readings to depth measurements.
AUV-Group-Github/
├── intro_to_ros/ # Main package directory
│ ├── armdisarm.py # Arm/disarm control
│ ├── camera_subscriber.py # Camera processing
│ ├── movement.py # State machine and behaviors
│ ├── pid_depth.py # Depth PID controller
│ ├── pid_heading.py # Heading PID controller
│ ├── pressure_to_depth.py # Sensor conversion
│ ├── yolo.py # YOLO detection utilities
│ ├── YOLOmovement.py # YOLO-based movement
│ └── YOLO_subscriber.py # YOLO ROS integration
├── launch/ # Launch configurations
│ ├── testitall.yaml # Full system launch
│ ├── sitl.yaml # Simulation launch
│ ├── PID_depth_test.yaml # Depth control test
│ ├── PID_heading_test.yaml # Heading control test
│ └── YOLO.yaml # Vision-only test
├── test/ # Unit tests
├── package.xml # ROS 2 package manifest
├── setup.py # Python package setup
└── README.md # This file
The PID controllers have been tuned for specific vehicle configurations. If using different hardware:
- Start Conservative: Begin with low gains
- Tune Proportional: Increase Kp until oscillation, then reduce by 50%
- Add Integral: Slowly increase Ki to eliminate steady-state error
- Add Derivative: Increase Kd to reduce overshoot and improve response
MIN_DEPTH = 0.4 # meters
MAX_DEPTH = 0.8 # metersThe system uses a custom-trained YOLOv8 model (best_ncnn_model). To retrain:
- Collect underwater imagery
- Annotate with your target classes
- Train using Ultralytics YOLO
- Replace model in
intro_to_ros/directory
cd ~/auvc_ws
colcon build --symlink-install
source install/setup.bashcd ~/auvc_ws
colcon test
colcon test-result --verbose# List all active topics
ros2 topic list
# Echo specific topic
ros2 topic echo /bluerov2/depth
# Check node info
ros2 node info /pid_depth
# View topic data rate
ros2 topic hz /bluerov2/camera/image_raw- Always test in simulation first using SITL before deploying to hardware
- Set depth limits appropriate for your operating environment
- Monitor battery levels during operation
- Have a kill switch or emergency surface procedure
- Test in controlled environment before competition/deployment
- Verify sensor calibration before each mission
# Check MAVROS status
ros2 topic echo /mavros/state
# Verify connection string in launch file
# Default: udp://:14550@YOUR_IP:14551# List camera topics
ros2 topic list | grep camera
# Check camera permissions
sudo usermod -a -G video $USER- Reduce Kp gain by 20-30%
- Ensure derivative term is not too high
- Check for sensor noise/filtering
Team Members:
- Aidan Gao (agao3019@gmail.com)
- Andy
- Ken
- Roneet
- Shamak
TODO: Add license information
- Built with ROS 2 and MAVROS
- Computer vision powered by Ultralytics YOLOv8
- Designed for BlueROV2 platform
- ArduSub flight controller
- ROS 2 Documentation
- MAVROS Documentation
- ArduSub Documentation
- BlueROV2 Technical Details
- YOLOv8 Documentation
For questions or issues, please contact the maintainer at agao3019@gmail.com