Skip to content

Improve Sim Realism - #34

Draft
kethan1 wants to merge 14 commits into
mainfrom
kethan/sim-realism
Draft

kethan1 wants to merge 14 commits into
mainfrom
kethan/sim-realism

Conversation

@kethan1

@kethan1 kethan1 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Very much a draft

@kethan1
kethan1 marked this pull request as draft November 22, 2026 07:59
Both now follow their claude-extra-features-3 branches, which are on the
upstream masters.

Stonefish (c09c4d3): hydrodynamics from lumped coefficients, supply voltage
of thrusters, lock-stepped and offscreen rendering, pause/step, seeded
random numbers, sensor error models, per-beam DVL, lens and image sensor
model of the camera, water optics by coefficients and bounding boxes of the
segmentation camera.

stonefish_ros2 (483255d): the ROS interface of the above.
The T200 thrust curve was a table in utils.cpp, and the simulator had its
own copy that disagreed with it: the forward half of this one was two rows
(0.02 of command) off BlueRobotics' data, so the controller expected about
13% more forward thrust than the simulator, and the data, gives.

- data/t200_thrust.csv is now the only copy: BlueRobotics' public
  measurements at 10 to 20 V. The lookup table is generated from it at
  build time (scripts/generate_thrust_table), and the simulator reads the
  same file.
- The ESCs are open loop, so thrust follows the battery voltage. The new
  thruster_voltage parameter (16 V by default, as before) selects the
  curve, interpolated between the measured voltages
  (set_thruster_voltage()).

Forward commands for a given thrust rise by 0.02 with the corrected curve.
The simulated robot got its mass, buoyancy, added mass and drag from what
Stonefish estimates from its collision geometry, plus a global damping of
0.35, and the model sub_control was given for it was identified from that.
Nothing tied the two together, and no measurement of the real vehicle
could be put into the simulator.

- The robot's base link is now defined by the model block of the gains
  file the stack runs with (model_hydrodynamics()): rigid body mass,
  inertia, centres of gravity and buoyancy, displaced volume, added mass
  and linear and quadratic damping, through Stonefish's lumped
  hydrodynamics. The parts only give its looks, collisions and the shape
  that floats at the surface. The global damping is gone. Identify the real
  vehicle, put the result in the gains file, and the simulated one follows.
- model_error:=0.2 scales each term by a random factor within 20%, from the
  seed, to try the controller on a vehicle that differs from its model.
- The thrusters take sub_control's thrust table (thrust_curve()) with its
  supply voltages. battery_voltage sets the voltage they start at and
  sim/battery_voltage changes it while running; sub_control keeps assuming
  its thruster_voltage.

Checked against the simulator's ground truth: steady speeds for a given
wrench are within 3% of the model's in surge, sway, heave and yaw.
…ulation

Move timeouts, timed velocities, service waits and the age of detections
were measured on the steady clock. A simulation running slower than real
time (a slow GPU, software rendering, a paused or stepped run) used up
those budgets without the vehicle having had the time to move, so a
mission's outcome depended on the computer.

MissionClock is the steady clock on the vehicle and the simulator's time
when the node runs with use_sim_time, and the waits use it. Waits on what
is outside the simulation (a process exiting, Groot) stay on the steady
clock.
- lock_step (on by default) makes the simulation wait for the cameras:
  each frame is rendered at the step it is due and none is skipped. A slow
  GPU slows the simulation down instead of thinning out the frames the
  vision nodes get.
- The seed that places the scenario also seeds the simulator's sensor
  noise, so a seed reproduces the whole run.
- offscreen:=true renders the cameras without a window, for machines with
  no display; with LIBGL_ALWAYS_SOFTWARE=1 it needs no GPU either (about
  0.15 of real time with both cameras at full resolution on a laptop CPU).
  headless:=true is still the run with no cameras at all.
The DVL, IMU and pressure sensor only had white noise, and reported at
rates and with a beam angle that are not the real ones'. With sensor_noise
they now also have what the navigation actually has to cope with:

- DVL: the A50's 22.5 degree beams and 5 cm minimum range, and (new in
  Stonefish) a velocity only while three beams are on the bottom. A beam
  that grazes what it hits, as beside a wall, is lost. Reports are stamped
  with their time of validity and arrive 0.15 s later, and now and then a
  few are missing.
- IMU: 50 Hz like the NaviGuider's orientation, a yaw that wanders rather
  than drifting at one rate, and gyro offsets that differ between runs.
- Depth: 5 Hz like the firmware's, 2 mm resolution and an offset of about
  a centimetre.

The latency, dropout, bias and incidence values are estimates from the
manufacturers' data, not measurements of our sensors.
Rendered frames were cleaner than a camera's and every run looked the
same, which is not what a detector trained or tested on them will meet.

- camera_effects (on by default): the cameras' images get motion blur over
  their exposure and sensor noise, and the front camera's go through JPEG
  compression like the C922's MJPEG stream. Typical values for such
  cameras, not measured on ours.
- appearance:=<0 to 1> draws the look of the scene from the seed instead of
  using the one tuned to the pool footage: the water's clarity, the sun's
  position, the ripples, the floor's brightness, how faded the props'
  prints are, and the front camera's exposure and colour balance. It has
  its own random stream, so a seed's placements stay the same.
- The segmentation camera also publishes sim/segment/boxes
  (vision_msgs/Detection2DArray): the bounding box of each object in view,
  named like its labels, to annotate the front camera's frames.
ros2 run sub_bringup replay <bag> feeds a bag's thruster commands
(control/thrusters) to the simulated vehicle, open loop, and compares its
velocity with the one the bag recorded (odometry/filtered): the RMS error
per axis, the velocities as CSV and a plot. It turns how far the simulator
is from the vehicle into numbers, for a pool bag, and shows what a new
model block changes.

The run is cut into windows, each a fresh headless simulator started at
the bag's depth and attitude and stepped in lock with the commands (the
simulator's pause and step services), so the result is the same on any
computer; a 95 s run replays in under a minute. Windows break where the
vehicle is nearly at rest, and their first seconds and the time at the
surface are not scored.

On a bag recorded in the simulator it leaves 8% of the surge speed, 13% of
the heave speed and 5% of the yaw rate, which is the estimator's noise and
the restarts; with the thrusters at 12 V instead of 16 V it shows 26% and
65%.
@kethan1
kethan1 force-pushed the kethan/sim-realism branch from 50963a2 to dad7591 Compare December 3, 2026 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant