Calibrated Safety Filters for Residual RL on Surface Vessels

Reinforcement learning controllers for boats and drones usually reach real hardware through domain randomization, meaning the policy is trained across many simulators whose physical parameters (mass, drag, thrust curves) are randomly perturbed, in the hope that the real vehicle looks like one more random draw. Safety is then handled in one of two ways. It is either added to the reward as a penalty, which fails badly out of distribution, or bolted on as a separate shield whose safety margin a person sets by hand. We propose to connect the two. The spread of dynamics that domain randomization already samples during training can be used to calibrate the safety margin of a convex safety filter. The same filter then sits inside the training loop and stays there on the real boat. The learned policy is a residual correction on top of a geometric model-predictive controller, and its reward is simply that controller's own quadratic cost. This removes the multi-term hand-tuned reward that current vessel RL depends on.

The payoff is a concrete, checkable claim for autonomous surface vessels. If the real vessel's one-step dynamics fall inside the randomized family, a geofence and thrust-limit constraint holds with a stated probability, with no real-world training. We also expect the residual policy to track non-periodic disturbances better than the online-learning model-predictive controllers that currently set the bar on real rivers. The study also answers a question the literature raises but does not resolve. How wide can randomization get before a margin calibrated to it makes the safety problem infeasible?

Core Claim

Three ingredients exist separately and have not been combined. The first is a convex tracking controller on $SE(3)$, the group of 3D rigid-body poses. The second is a data-driven safety margin. The third is dynamics randomization. We use the randomization distribution as the calibration set for the margin. Let $\theta \sim p(\theta)$ denote randomized hull, drag, added-mass, and thruster parameters. Let $f_\theta$ be the resulting simulator step and $\hat f$ the nominal model used by the controller. We define the margin as the empirical $(1-\alpha)$ quantile of the one-step model error measured in the Lie algebra, the flat tangent space where pose errors can be added and compared:

$$\delta_\alpha = \mathrm{Quantile}_{1-\alpha}\Big(\big\|\log\big(\hat f(X_t,u_t)^{-1} f_\theta(X_t,u_t)\big)\big\|\Big),\quad \theta\sim p(\theta),\ (X_t,u_t)\sim \text{rollouts}.$$

Here $X_t$ is the vessel pose-and-velocity state, $u_t$ the thrust command, and $\log$ maps a pose discrepancy to a vector. The filter solves a small quadratic program, a convex optimization solvable in milliseconds. At each step it projects the combined command $u^{\text{mpc}}_t + \pi(o_t)$ to the nearest command whose nominal prediction keeps the vessel at least $\delta_\alpha$ inside every constraint. In this expression $\pi$ is the learned residual policy and $o_t$ its observation:

$$u_t = \arg\min_{u\in\mathcal U}\ \|u - u^{\text{mpc}}_t - \pi(o_t)\|^2 \quad \text{s.t.}\quad h\big(\hat f(X_t,u)\big) \ge \delta_\alpha .$$

The function $h$ is the signed distance to the geofence or keep-out zone. The policy is trained with the filter active, and its reward is $-(e_t^\top Q e_t + u_t^\top R u_t)$. This is the same stage cost the nominal controller already minimizes, with $e_t$ the Lie-algebra tracking error. What is new is not any single component. It is that the randomization distribution becomes the object the safety statement is conditioned on, and that the reward inherits from control design rather than from a separately tuned list of penalties.

Where This Sits in Prior Work

Two papers motivate the gap directly. Time-optimal Flight in Cluttered Environments via Safe Reinforcement Learning combines all four directions for a quadrotor: rotation-matrix attitude, randomized mass, drag and thrust, and a hand-tuned reward with exponential obstacle penalties. Because safety lives only in the reward, success falls to 66.7% on unseen denser forests, and the method was never flown on hardware. Deep Reinforcement Learning Based Tracking Control of an Autonomous Surface Vessel in Natural Waters transfers a DDPG policy zero-shot to the Charles River with 0.14 m tracking error against NMPC's 0.22 m. It does so with a five-term reward and no randomization, and it pays for it with about 5.4 N average thrust versus 3.9 N for NMPC. That is the kind of reward-driven exploitation of simulator flaws we aim to remove by inheriting the controller's cost. MetaDrive supplies the general argument against penalty shaping: small penalties are traded away for return, while large ones produce a policy that does nothing.

Two papers supply the control method. Convex Geometric Trajectory Tracking using Lie Algebraic MPC for Autonomous Marine Vehicles turns 6-degree-of-freedom hydrodynamic tracking into a quadratic program, about 50 ms per step against about 800 ms for NMPC. It overshoots under large errors and does no learning. Online Learning-Enhanced Lie Algebraic MPC adds a Fourier-feature residual model and works on a real BlueBoat. It explicitly assumes quasi-periodic disturbances and primes its features on nominal trajectories without randomization. We reuse its controller as the nominal layer. We replace its periodic residual with a learned policy, and we test it on exactly the non-periodic disturbances it names as a weakness.

Three papers constrain the safety design. Sim-to-Lab-to-Real shows that a reachability-based shield plus randomization can reach hardware, with 86.7% empirical safety on a quadruped. It operates on high-level navigation actions, still uses hand-engineered task rewards, and needs hundreds of lab environments for its guarantees. We target low-level coupled vessel dynamics with a far cheaper calibration. Safe Reinforcement Learning Using Black-Box Reachability Analysis builds reachable sets from trajectory data, which is closest to our margin. Its sets are not tied to a randomization distribution, it assumes no fluid disturbances, and it was only simulated. Provably Safe Sim-to-Real Transfer gives the cleanest guarantee (0% unsafe iterations against 68.5% for an unconstrained baseline), but only on a 5x5 tabular gridworld under a separable-mismatch assumption. Diffuse hydrodynamic error violates that assumption, which is why we use a quantile margin rather than a mismatch region. Combining Reinforcement Learning with Model Predictive Control for On-Ramp Merging shows that an MPC supervisor over an RL agent can reach 0% crashes where standalone DDPG crashed 85.1% out of distribution. That result supports supervision, but it was obtained on planar traffic kinematics with a fixed margin and no randomization.

Research Program

We will build the stack on the Otter vessel model in the Marine Systems Simulator and on the Virtual RobotX (VRX) simulator. The nominal layer is the Lie-algebraic MPC. The residual policy is a small network trained with PPO under the filter. The randomization family covers mass and added mass, linear and quadratic drag coefficients, thruster deadband and gain, actuation latency, and current and wind fields. It deliberately includes non-periodic gust bursts and current shears. The margin $\delta_\alpha$ is computed once per randomization width from held-out rollouts.

We will sweep that width in multiples of a nominal range. For each width we record three things: the calibrated margin, the fraction of states where the filter's quadratic program is infeasible, and task performance. This produces the robustness-versus-feasibility curve that the file's Gap 4 identifies but no paper measures. We will also check coverage. For dynamics sampled outside the training family (a heavier hull, a biased thruster), we measure how the empirical violation rate departs from $\alpha$. An honest safety claim has to say where it stops holding.

If a BlueBoat-class platform is available, we run the zero-shot river deployment with a virtual geofence. The protocol matches the BlueBoat and Charles River studies so the numbers are comparable. If no platform is available, the claim is limited to simulation with held-out simulators, and we say so.

Baselines

The naive reference point is the nominal Lie-algebraic MPC with no learning and a hand-set constraint margin. It shows what the geometric controller alone achieves and gives the energy floor.

The strongest existing method on this question is the online Fourier-learning Lie-algebraic MPC of Online Learning-Enhanced Lie Algebraic MPC. That paper reports 0.830 m RMSE on the VRX lawnmower path at 3.0 m/s wind, against 1.441 m for standard MPC. On a real BlueBoat it reports tracking error falling from 1.17 m to 0.76 m, running at 50 Hz on a single-core CPU. We will rerun it from its description on identical VRX trajectories, wind seeds, and disturbance schedules, using the same single-core compute budget and the same geofence. Its feature count and learning rate get a tuning budget equal to the one we spend on the residual policy's hyperparameters. Beating it means lower RMSE on the non-periodic disturbance set, with violation rate at or below its level and average thrust no higher. Matching it on periodic wind is acceptable. Because this baseline is a real threat, we also give it a stronger residual model: more frequencies, plus a small online-updated network. That separates "RL is needed" from "a better residual model is needed."

The strongest reinforcement-learning competitor is the five-term-reward DDPG controller of Deep Reinforcement Learning Based Tracking Control of an Autonomous Surface Vessel in Natural Waters, which reports 0.14 m mean field error and about 5.4 N average thrust. We reimplement it in the same simulators, both with and without our randomization family, and give it the same number of environment steps. Beating it means comparable tracking at lower thrust and fewer constraint violations. The thrust gap is the direct test of whether inheriting the controller's cost removes reward exploitation.

For constrained RL without a filter, we run PPO-Lagrangian with the same randomization, residual structure, and cost-limit tuning budget. Safety Gymnasium reports that on velocity tasks it cuts violations by 98% relative to PPO while losing 45% of reward. We expect to keep violations near zero during training without a comparable reward loss.

Four ablations isolate the key ingredients. The first replaces $\delta_\alpha$ with a hand-set margin of equal average size, which isolates calibration. The second trains without the filter and adds it only at deployment, which isolates filter-in-the-loop training. The third swaps the inherited cost for the five-term reward, which isolates the reward choice. The fourth runs the filter with the calibrated margin but no residual policy, which isolates learning.

Why not just…?

Why not just use the online-learning Lie-algebraic MPC and skip RL? This is the most serious alternative, and it may win on smooth, periodic wind. Its own authors attribute its limits to the Fourier assumption, and we have no evidence yet that a learned residual beats a richer online model. The strengthened-residual baseline settles it. If a small online network inside MPC matches our residual policy on non-periodic gusts, we report that RL is unnecessary. The calibrated filter is controller-agnostic, so it would then stand as the contribution for that stack as well.

Why not just add a Lagrangian cost constraint to a randomized policy? Constrained policy optimization only bounds expected cost at convergence and permits violations throughout training. It also degrades as violations become rare, the "safety paradox" described in Breaking Safety Paradox with Feasible Dual Policy Iteration. Moreover, a violation of the expected-cost budget on a real river is a collision, not a statistic. The PPO-Lagrangian baseline measures training-time violations directly.

Why not just bolt a shield onto an existing randomized policy at deployment? A policy trained without the filter learns actions the filter will clip, so the deployed system behaves differently from what was optimized. The merging study had to hand over control to MPC until stability returned. The deploy-only-filter ablation measures intervention rate and the tracking loss this causes.

Why not just widen the randomization until everything transfers? Wider ranges make policies conservative, as noted in Provably Safe Sim-to-Real Transfer, and under our scheme they also inflate $\delta_\alpha$ until the filter becomes infeasible. The width sweep turns this trade-off into a measured curve rather than an argument.

Decisive Checks

The proposal succeeds if four things hold. First, the empirical violation rate on held-out simulators drawn from the randomization family stays at or below $\alpha$ while the hand-set-margin ablation does not. Second, the residual policy beats the strengthened online-learning MPC on the non-periodic disturbance set in VRX at equal compute. Third, the inherited-cost policy uses less thrust than the five-term-reward controller at matched tracking error. Fourth, the width sweep shows a range where the filter stays feasible and performance improves over nominal training. The proposal fails informatively if coverage breaks under modest out-of-family shifts, or if the richer MPC residual matches the policy. In either case we would learn exactly which ingredient carries the gain. For the formal-shielding benchmarks, there is no reported per-benchmark number on Lacuna for Adaptive Probabilistic Shielding, so we do not use it as a quantitative anchor.