From Simulation to Field: How to Validate Your ROS 2 Stack Before Going Outdoors
Tom Cosgrove,

TL;DR: Moving a ROS 2 simulation to a real robot fails most often because of unmodeled physics, sensor noise, and timing assumptions that hold in Gazebo but not on wet grass. A disciplined ros 2 simulation to real robot workflow uses staged validation: unit tests on nodes, deterministic SIL runs, randomized scenarios, hardware-in-the-loop with real sensors, then short controlled outdoor trials. Before any field deployment, verify TF tree consistency, QoS profiles on lossy networks, localization drift under GNSS dropout, controller behavior on slope and slip, and recovery from sensor faults. The checklist at the end of this article covers what to validate in simulation before you commit a UGV to terrain.
Why the Sim-to-Real Gap Still Breaks Field Deployments
The ros 2 simulation to real robot transition has improved with Gazebo Harmonic, the Gazebo Sim ecosystem, and better sensor plugins, but the domain gap remains a major source of failure in field robotics. Simulators model rigid-body contact, idealized IMUs, and lidar returns with simplified noise models. Outdoors you get wheel slip on loose gravel, GNSS multipath near buildings, lidar dropouts in rain, and IMU bias drift correlated with temperature.
The cost of finding these issues outdoors is high: a stuck rover in a remote test site can mean a day lost. The cost of finding them in simulation is a CI minute. The question is not whether to simulate, but how to structure simulation so it surfaces the failure modes you will actually encounter.
What a Staged Validation Pipeline Looks Like
A practical ros 2 simulation to real robot pipeline has five stages, each filtering a different class of bug before the next stage runs.
Stage 1: Unit and Integration Tests on Nodes
Before any simulator launches, your nodes need deterministic tests. Use launch_testing and rclpy or rclcpp test fixtures to publish synthetic messages and assert on outputs. Typical checks include:
- TF frames are published at expected rates and with correct parent-child relationships.
- Lifecycle nodes transition correctly under repeated activate/deactivate cycles.
- Action servers handle preemption and cancellation without leaking goal handles.
- Parameter callbacks reject invalid values rather than crashing.
These tests run in seconds and catch many regressions before anyone opens RViz.
Stage 2: Software-in-the-Loop with Deterministic Scenarios
Next, run the full stack against a Gazebo or Isaac Sim world with fixed seeds. The goal is reproducibility: the same scenario, run twice, should produce the same trajectory within numerical tolerance. This requires using use_sim_time consistently, fixing random seeds in noise models, and avoiding wall-clock-dependent logic in your controllers.
Useful scenarios at this stage include a straight-line traversal to validate odometry calibration, a figure-eight to expose yaw drift, and a planned navigation goal through a known obstacle field to validate the costmap and planner integration.
Stage 3: Randomized and Adversarial Scenarios
Determinism catches regressions; randomization catches design flaws. Use procedurally generated worlds with varying terrain roughness, lighting, and obstacle placement. Inject sensor faults explicitly: drop 10% of lidar scans, add a 200 ms latency spike on the camera topic, simulate GNSS outage for 30 seconds. If your localization falls over when GNSS drops for half a minute, you want to know that before a tree canopy proves it in the field.
This stage is where Fictionlab’s team typically catches QoS misconfigurations. A subscriber using RELIABLE on a high-rate sensor topic over a flaky link can introduce backpressure, latency, or queue growth if history depth and resource limits are not bounded. BEST_EFFORT with a small queue depth is often correct for sensor data; RELIABLE belongs on critical commands and state transitions.
Stage 4: Hardware-in-the-Loop
HIL means running the real compute payload, real sensors where possible, and simulated actuators or environment. For a Leo Rover stack, this often means the actual onboard computer running the navigation stack, with the motor controllers in a bench setup and a simulated world providing odometry and lidar. HIL exposes timing issues that pure SIL hides: CPU contention between perception and planning, USB bandwidth limits on multi-camera setups, and thermal throttling under load.
Stage 5: Controlled Outdoor Trials
Only after the first four stages pass do you take the robot outside, and even then you start in a parking lot or controlled test area before moving to the actual deployment site. Log everything with ros2 bag at full rate. The bags from these trials feed back into Stage 2 as replay scenarios, closing the loop.
How to Close the Domain Gap in Practice
The domain gap is not a single problem. It is at least four problems, and each needs a different mitigation.
Sensor modeling. Default lidar plugins often assume near-ideal returns unless configured otherwise. Real lidars miss returns on black surfaces, suffer from sun blinding, and produce ghost points in dust. Calibrate your simulated sensor noise against real bag data: record a stationary scan outdoors, measure the actual return rate and noise distribution, and tune the simulator to match.
Terrain interaction. Wheel-terrain contact is hard to simulate accurately. Gazebo’s friction and contact models are a coarse approximation of soil mechanics. For research applications, projects working on planetary analog terrain (see space applications) often add empirical slip models calibrated from field data rather than relying on physics defaults.
Network and timing. ROS 2 DDS over Wi-Fi behaves differently from DDS over localhost. Test with realistic network conditions using tc to inject latency and packet loss. If your teleop fails at 50 ms RTT, it will fail at the field site.
Power and thermal. Simulators do not model battery sag or CPU thermal throttling. Run HIL sessions long enough to hit thermal steady state, typically 30 to 60 minutes under representative load.
What to Check in Simulation Before You Go Outdoors
This checklist captures the validations that experience in research deployments shows are most likely to prevent field failures. Treat it as a gate, not a guideline.
- TF tree integrity. No disconnected frames, no duplicate publishers, all transforms within expected latency. Verify with
ros2 run tf2_tools view_frames. - Clock consistency. Every node respects
use_sim_time. Mixed-clock setups produce silent localization drift. - QoS profiles. Sensor topics use
BEST_EFFORTwith bounded queues; critical commands and state useRELIABLE. Verify withros2 topic info -v. - Localization under GNSS dropout. EKF or equivalent maintains pose within acceptable error for at least 60 seconds without GNSS.
- Costmap behavior on inflation radius. Robot does not get trapped in narrow passages or refuse valid goals near obstacles.
- Recovery behaviors. Stuck detection triggers and resolves within bounded time. No infinite recovery loops.
- Bag replay. The stack runs against a recorded field bag and produces sensible plans. This is one of the cheapest sim-to-real checks available.
- Emergency stop. Software stop commands interrupt motion within a bounded time regardless of planner state, and the hardware E-stop path is verified independently.
- Resource budget. CPU under 70%, memory stable over a one-hour run, no file descriptor leaks.
- Log volume. Disk usage during a typical mission fits available storage with margin for unplanned extensions.
How to Build a Reusable Validation Setup
A validation pipeline pays back only if it runs often. Structure your CI so that Stage 1 runs on every commit, Stage 2 runs on every merge to main, and Stage 3 runs nightly. Stages 4 and 5 are manual but should be triggered by a release tag, not by calendar pressure.
Use containerized simulation images so the environment is reproducible. Pin your ROS 2 distribution, your simulator version, and your plugin versions. A Stage 2 scenario that passed last month should still pass today if nothing in your code changed; if it does not, you have a dependency problem worth investigating.
Store representative field bags in a versioned artifact store. These bags are the reference data against which simulation fidelity is measured. When a new failure mode appears in the field, the bag of that failure becomes a regression test.
Frequently Asked Questions
How realistic does the simulator need to be?
Realistic enough to expose the failure modes you care about, not more. For navigation stack validation, terrain geometry and sensor noise matter most. For manipulation, contact dynamics matter most. Over-investing in visual fidelity rarely improves sim-to-real transfer for UGVs.
Should you use Gazebo Classic, Gazebo (Harmonic), or Isaac Sim?
Gazebo Harmonic is a current LTS choice commonly used with ROS 2 and has good plugin coverage. Isaac Sim offers better visual fidelity and GPU-accelerated sensor simulation, useful for ML perception training. Gazebo Classic is end-of-life and should not be chosen for new projects.
How long should HIL testing run before field deployment?
Long enough to reach thermal steady state and to exercise the longest realistic mission, whichever is greater. For a one-hour field mission, plan at least a two-hour HIL session.
What is the minimum useful set of recorded topics for bag replay?
At minimum: all sensor inputs, /tf and /tf_static, command velocity, odometry, and any planner state topics. Recording at full rate is preferable; downsampling hides timing issues that matter.
How do you validate behavior under sensor faults?
Inject faults at the topic level using a relay node that drops, delays, or corrupts messages based on a fault schedule. This is simpler than modifying the simulator and works identically in SIL and HIL stages.
Can reinforcement learning policies be validated the same way?
The pipeline structure is the same, but RL policies require additional checks for distribution shift. A policy trained in simulation must be evaluated on representative recorded data and in HIL before field trials, with explicit measurement of out-of-distribution behavior.
What is the single most common cause of sim-to-real failure?
In field experience, it is often QoS and timing assumptions that hold over localhost but fail over Wi-Fi or cellular links. Test your network early and pessimistically.
Take Your Validated Stack to the Field
A staged ros 2 simulation to real robot pipeline turns field deployment from a gamble into an engineering process. If you are building a custom UGV platform or adapting an existing one for a specific research or industrial scenario, Fictionlab’s team can support the integration and validation work. Learn more about custom robotics development with Fictionlab.