Skip to content

Repository files navigation

Torpedo-Style AUV Simulation & Control Framework

A high-fidelity, highly modular 6-DOF simulation environment for Autonomous Underwater Vehicles (AUVs). Built from first principles in MATLAB/Simulink, this framework completely decouples physics, guidance, and control to allow for rapid algorithm swapping, rigorous stress testing, and seamless transition to Hardware-in-the-Loop (HIL) deployment.

🚀 Project Overview

This project provides a professional-grade simulation architecture for torpedo-style AUVs (specifically modeled on the REMUS 100). Instead of a monolithic script, the system uses Interface-Based Design via strictly typed Simulink Bus Objects.

Core capabilities include:

  • True 6-DOF Hydrodynamics: Powered by Fossen's Marine Systems Simulator (MSS) plant model.
  • Nonlinear Control (SMC): Includes a robust 2nd-order Sliding Mode Controller that actively damps cross-coupling forces and rejects ocean currents.
  • Pure Path Following: Implements 3D Cross-Track Line-of-Sight (LOS) guidance to eliminate time-dependent integrator wind-up.
  • Severe Environment Modeling: Simulates Pierson-Moskowitz wave spectrums and 3D ocean currents.
  • HIL Readiness: Architecture guarantees the control logic has zero access to "perfect" physics, observing state purely through a Navigation bus, making it ready for ESP32/microcontroller deployment.

🏗️ System Architecture

The simulation is divided into 7 strictly isolated modules. The top-level Simulink model (AUV_TopLevel.slx) contains no logic; it is purely a wiring diagram connecting these modules.

Module Name Responsibility
M1 Environment Generates 3D ocean currents and wave forces (Pierson-Moskowitz). Pure feedforward.
M2 Guidance 3D Cross-Track LOS path following. Converts waypoints into kinematic references ($\chi_d, \upsilon_d, U_d$).
M3 Control The swappable brain. Maps kinematic references to generalized forces ($\tau_{ctrl}$). Includes PID and SMC.
M4 Actuation Maps generalized forces to physical hardware (RPM, Fin Angles) and enforces strict physical saturation.
M5 Dynamics The Ground Truth. Integrates actuator effort and environmental disturbances via remus100.m (RK4 solver).
M6 Navigation The Observer. Separates "Truth" from "Estimate" to simulate sensor noise and EKF latency (10ms unit delay).
M7 Viz/Log/HIL Passive read-only tap for live telemetry dashboards and serial UART communication to hardware.

⚙️ Control & Guidance Algorithms

1. Control: PID vs. 2nd-Order SMC

The baseline controller uses a linear PID with feedforward Coriolis cancellation. The advanced controller uses a First-Order Sliding Mode Controller (SMC) for surge, and Second-Order SMCs for pitch and yaw.

  • By incorporating the derivative of the error (angular rates $q, r$) into the sliding surface ($s = \dot{e} + \lambda e$), the SMC actively damps rotational momentum.
  • A boundary layer ($\phi$) smooths the discontinuous reaching law to prevent high-frequency actuator chattering.

2. Guidance: 3D Cross-Track LOS

Replaces standard "Virtual Rabbit" trajectory tracking with true geometric path following. It projects the AUV's coordinate orthogonally onto the 3D line segment between waypoints, calculating cross-track ($y_e$) and vertical ($z_e$) errors to dictate pitch and yaw commands, completely eliminating integrator wind-up during rapid maneuvers.


🛠️ Prerequisites

  • MATLAB & Simulink (R2021a or newer recommended)
  • MSS (Marine Systems Simulator) Toolbox by Thor I. Fossen. Ensure remus100.m is on your MATLAB path.

🚀 Getting Started

1. Build the Simulation

Do not build the Simulink model manually. The architecture is generated programmatically to ensure perfect bus typing and module integration.

Run the following in the MATLAB Command Window:

% 1. Load Bus definitions and vehicle physical parameters
buses
auv_params
auv_params_env_patch

% 2. Auto-generate the Top-Level Simulink Model
build_simulink_model

% 3. Route feedback delays (Breaks algebraic loops)
simulink_wiring_guide

2. Run the Full Closed-Loop Simulation

Once the model is built, launch the simulation with live telemetry dashboards:

run_simulation('live')

Dashboards will appear showing 6-DOF states, trajectory, cross-track error, and actuator effort in real-time.

3. Swapping Controllers (The Plug-and-Play Contract)

To swap from the baseline PID to the nonlinear SMC, you only need to change one block.

  1. Open AUV_TopLevel.slx.
  2. Double-click the Control block.
  3. Change the S-Function name from control_pid_sfcn to control_smc_sfcn.
  4. Press Ctrl+D to update the diagram. Run the simulation.

🧪 Stress Testing Suite

The repository includes severe operational stress tests to validate algorithmic robustness against extreme marine environments.

  • test_phase9_stress.m: The "Broadside Storm" — Forces the AUV to track a straight line while subjected to a massive orthogonal current (0.8 m/s) and 1.5m waves. Proves the SMC's ability to hold a slip angle without integrator drift.
  • test_phase11_pathfollowing.m: The "Torpedo Evasive Maneuver" — A high-speed sprint into a spiraling dive, followed by an instantaneous level-out. Proves the 3D Cross-Track Guidance eliminates depth wind-up.

Run any test directly from the command line:

test_phase11_pathfollowing
plot_phase11_pathfollowing

🔌 Hardware-in-the-Loop (HIL)

(Phase 10) The architecture isolates all hardware communication inside M7 (VizLogHIL_M7.slx). The Actuation bus already translates generalized forces into standard 1000-2000 µs PWM signals. By enabling the HIL_ENABLED flag, M7 will transmit an 8-byte sync-framed UART packet at 50Hz to an external ESP32/microcontroller to drive physical servos and brushless ESCs on a test stand.


🖼📊 Diagrams

MATLAB System Architecture

Top Level Simulink Architecture

Bus Interface Map

Bus Map

Development plan

Devolopment Plan

Full System Architecture

Full System

Simulink

Simulink

Torpedo Model (Remus 100)

Remus 100

📖 Acknowledgments

  • Vehicle physics and hydrodynamic coefficients derived from Thor I. Fossen's Handbook of Marine Craft Hydrodynamics and Motion Control and the MSS Toolbox.
  • Baseline REMUS 100 parameters courtesy of Prestero (2001) and Allen et al. (2000).

About

Torpedo Matlab Simulation

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages