text stringclasses 3
values |
|---|
/usr/bin/c++ -std=c++11 -rdynamic CMakeFiles/test_cpp_myboat_control.dir/src/test_cpp_myboat_control.cpp.o -o /home/gabriel/lab_usv_ws/devel/.private/myboat_gazebo/lib/myboat_gazebo/test_cpp_myboat_control -L/home/gabriel/lab_usv_ws/devel/.private/wave_gazebo_plugins/lib -L/opt/ros/noetic/lib -L/usr/lib/x86_64-... |
/usr/bin/c++ -std=c++11 -rdynamic CMakeFiles/buoyancy_plugin_test.dir/test/buoyancy_test.cc.o -o /home/gabriel/lab_usv_ws/devel/.private/usv_gazebo_plugins/lib/usv_gazebo_plugins/buoyancy_plugin_test -L/home/gabriel/lab_usv_ws/devel/.private/wave_gazebo_plugins/lib -L/opt/ros/noetic/lib -L/usr/lib/x86_64-linux-... |
/usr/bin/c++ -std=c++11 -rdynamic CMakeFiles/sandisland_test.dir/sandisland_test_autogen/mocs_compilation.cpp.o CMakeFiles/sandisland_test.dir/test/sandisland.cc.o -o /home/gabriel/lab_usv_ws/devel/.private/vrx_gazebo/lib/vrx_gazebo/sandisland_test -L/usr/lib/x86_64-linux-gnu/gazebo-11/plugins -L/home/gabriel/l... |
YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
π₯οΈ USV Safe RL Workspace
Shielded Reinforcement Learning for Unmanned Surface Vehicles
A hybrid PPO + MPC safety-filter architecture for autonomous marine navigation, trained in a custom Gymnasium environment and validated in Gazebo 3D (ROS 1).
Research internship β State Key Laboratory of Ocean Sensing, Zhejiang University Β· Polytech Nice Sophia (UniversitΓ© CΓ΄te d'Azur)
Overview
Deep Reinforcement Learning produces agile but unverifiable navigation policies. Model Predictive Control produces safe but conservative (and expensive) ones. This project synthesizes both:
The RL agent (PPO) acts as the brain β high-level, adaptive navigation. The MPC Predictive Safety Filter acts as the spinal cord β a real-time reflex enforcing hard kinematic constraints on every command before it reaches the thrusters.
The full pipeline goes from a pure mathematical prototype (10 000+ simulated steps/second) to a physical 3D deployment inside Gazebo with a custom multi-layer LiDAR, wind disturbances and wave physics.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
LiDAR 3Γ360Β° β β
+ Odometry βββΌβββΆ Observation (18-D) βββΆ PPO Policy βββΆ u_RL β
β β β
β βΌ β
β βββββββββββββββββββββββββββββββ β
β β MPC SHIELD (QP, SLSQP) β β
β β Fossen 3-DOF prediction β β
β β d_safe = 2.0 m, H = 2 stepsβ β
β ββββββββββββββββ¬βββββββββββββββ β
β βΌ β
β Emergency reflex (<2.5 m) ββΆ u_safe βββΆ Thrusters (PWM)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
single synchronous 10 Hz control loop
Demonstrations
3D validation runs in Gazebo. Drop the corresponding
.giffiles intoreport_files/using the exact names below and they will render automatically.
| Test 1 β Sanity check (chicane) | Test 2 β Narrow corridor |
|---|---|
![]() |
|
| Smooth Sim-to-Sim transfer, shield rarely triggered | Β±30Β° heading clamp keeps the trajectory linear in an 8 m channel |
| Test 3 β Close quarters (orthogonal avoidance) | Test 4 β The Storm (lateral wind) |
|---|---|
![]() |
![]() |
| 3-layer LiDAR fusion resolves overlapping buoys during a 90Β° turn | The agent adopts a "crab" sideslip; the shield governs lateral drift |
| Test 5 β The Full Gauntlet (stress test) |
|---|
![]() |
| Longest course, tightest geometry, heaviest logging load β zero collisions |
Method
Vehicle dynamics β Fossen 3-DOF
The MPC predicts the vessel using the standard maneuvering model with pose $\eta = [x, y, \psi]^T$ and body velocities $\nu = [u, v, r]^T$:
where $M$ includes added mass, $C(\nu)$ the Coriolis terms, $D(\nu)$ the non-linear hydrodynamic damping, and $\tau = [\tau_u, 0, \tau_r]^T$ the differential thrust of the two motors.
The MPC safety shield
At each tick, the RL action $u_{RL}$ is projected onto the safe set by a Quadratic Program (scipy.optimize.SLSQP) over a 2-step horizon ($dt = 0.5$ s β 1 s look-ahead):
subject to the Fossen dynamics, actuator saturation, and the collision constraint $|P_{USV}(t+H) - P_{obs}(t+H)| \ge d_{safe} - \epsilon$. The heavily penalized slack $\epsilon$ guarantees feasibility under severe disturbance: instead of an infeasible solve, the filter degrades gracefully into maximum-effort emergency braking.
Curriculum learning (10 scenarios)
Training PPO directly on dynamic traffic collapses the policy, so the agent is grown through a weighted curriculum:
| # | Scenario | Skill taught |
|---|---|---|
| 1 | free |
Locomotion, heading correction, stopping precision |
| 2 | static_single |
Elementary avoidance without over-deviating |
| 3 | static_multi |
Chicane anticipation, multi-obstacle planning |
| 4 | narrow_corridor |
Precision navigation in an 8 m channel |
| 5 | moving_follow |
Safe overtaking with lateral offset |
| 6 | moving_cross |
COLREG-like crossing: cross or yield |
| 7 | moving_target |
Pursuit of a mobile waypoint |
| 8 | fast_unpredictable |
Robustness / spatial margin against erratic traffic |
| 9 | variable_distance_world |
Geometric generalization (30 m β 100 m) |
| 10 | mixed_dynamic |
Final synthesis exam |
Key stabilizers: scenario sub-weighting against catastrophic forgetting, learning rate $3\times10^{-5}$, PPO clip range $0.1$, spatial jitter / domain randomization, and a shield-intervention penalty $-0.1,|u_{MPC}-u_{RL}|_2$ that forces the network to internalize the physical constraints instead of leaning on the filter.
Results
Final converged policy, 100 episodes per scenario:
| Scenario | Success | Collision | Timeout | Mean length |
|---|---|---|---|---|
free |
1.00 | 0.00 | 0.00 | 189.5 |
narrow_corridor |
1.00 | 0.00 | 0.00 | 173.3 |
moving_follow |
1.00 | 0.00 | 0.00 | 161.4 |
variable_distance_world |
1.00 | 0.00 | 0.00 | 174.2 |
static_multi |
0.98 | 0.02 | 0.00 | 140.0 |
moving_cross |
0.96 | 0.04 | 0.00 | 168.1 |
moving_target |
0.96 | 0.00 | 0.04 | 373.5 |
static_single |
0.94 | 0.01 | 0.05 | 203.4 |
mixed_dynamic |
0.91 | 0.09 | 0.00 | 142.1 |
fast_unpredictable |
0.88 | 0.12 | 0.00 | 169.4 |
Network health (TensorBoard): approx_kl β 0.006 Β· explained_variance = 0.925 Β· value_loss = 0.032 Β· clip_fraction = 0.05 Β· std = 1.13 β a well-behaved trust region, an accurate critic, and preserved exploration.
Two engineering findings worth highlighting
- Over-engineering is the enemy. The first Gazebo deployment chattered and pirouetted. Adding defensive layers (state caches, async callbacks, nested clamps) made it undebuggable. The fix was removal: a single synchronous 10 Hz loop where observation, inference, shield and actuation share one atomic clock.
- The Observer Effect. Running
rosbag recordcollapses the Gazebo Real-Time Factor, desynchronizing the closed loop and making trajectories jagged. Unrecorded runs are perfectly smooth. The degradation became a free stress test: even with a severely lagging RL loop, the shield kept the collision count at zero.
Getting started
1. Requirements
- Ubuntu 20.04 + ROS Noetic (
ros-noetic-desktop-full) and Gazebo 11 - Python 3.8+ with
numpy,scipy,torch,stable-baselines3,gymnasium,matplotlib
A ready-to-use dev container is provided (osrf/ros:noetic-desktop-full + noVNC desktop on port 6080):
pip3 install numpy scipy torch stable-baselines3 gymnasium matplotlib
2. Build the ROS workspace
catkin_make # or: catkin build
source devel/setup.bash
3. Run the 3D simulation
./e1_myboat_gazebo_view1.bash # ocean world 1 (worlds/myocean1.world)
./e1_myboat_gazebo_view2.bash # ocean world 2
./e1_myboat_gazebo_view3.bash # ocean world 3
./e2_myboat_manual_control.bash # manual teleoperation of the thrusters
./test_py_myboat_control.bash # Python control node smoke test
Then start the shielded controller (loads usv_rl_brain_final.zip + vecnormalize_final.pkl):
rosrun myboat_gazebo usv_controller_final.py # or: python3 clean_version/usv_controller_final.py
4. Train / evaluate the policy (no Gazebo required)
cd clean_version
python3 train_rl.py # PPO curriculum training
python3 resume_train.py # fine-tune an existing checkpoint
python3 casino_method.py # random-restart search on the 10-scenario mix
python3 evaluate_each_scenario.py # per-scenario success / collision / timeout rates
python3 plot_metrics.py # learning curves
5. Reproduce the 3D test figures
cd tests_file
python3 plot_rosbag.py # trajectory + thruster command plots from a .bag file
Documentation
The complete internship report (theory, training methodology, Sim-to-Sim transfer, validation campaign, LiDAR URDF appendix) is available in report_files/, together with the intermediate phase reports.
Future work
The architecture is hardware-ready. The next milestone is deployment of the containerized controller onto the physical USV for real lake trials β where the MPC shield and the domain randomization used during training are expected to absorb the remaining Sim-to-Real gap without risky on-site retraining.
References
- Wabersich, K. P., & Zeilinger, M. N. (2021). A Predictive Safety Filter for Learning-Based Control of Constrained Nonlinear Dynamical Systems. Automatica, 129, 109597.
- Romero, A., Song, Y., & Scaramuzza, D. Actor-Critic Model Predictive Control: Differentiable Optimization Meets Reinforcement Learning for Agile Flight. IEEE T-RO.
- Song, Y., & Scaramuzza, D. (2022). Learning High-Level Policies for Model Predictive Control. IEEE RA-L.
- Brunke, L., et al. (2022). Safe Learning in Robotics: From Learning-Based Control to Safe Reinforcement Learning. Annual Review of Control, Robotics, and Autonomous Systems, 5, 411β444.
- Fossen, T. I. (2011). Handbook of Marine Craft Hydrodynamics and Motion Control. John Wiley & Sons.
Acknowledgments
Work carried out at the State Key Laboratory of Ocean Sensing, Zhejiang University, under the supervision of Prof. Weichang Li and Dr. Huarong Zheng, with the academic support of Prof. NoΓ«lle Stolfi (Polytech Nice Sophia). The baseline simulation assets are derived from the open-source VRX project.
- Downloads last month
- 74



