Design
How the pieces fit together, and why they are built this way.
The waves
One wave field is shared by everything that needs it: physics, the renderer, and future sensors. Wave models are plugins, and nothing that reads the waves depends on a particular model, so adding a new wave model changes nothing else. The full architecture, requirements and the guide to adding a wave model are in WAVES_DESIGN.md.
Floating vehicles the world doesn’t know
The problem. Gazebo’s buoyancy system floats the links named in the
world file’s <enable> list, or, with no list, every collision of every
model. A world shared by many vehicles, some spawned while it runs, can’t
know their names in advance; and floating everything is wrong, because a
vehicle’s contact geometry (brackets, hatches, thruster housings) is rarely
what displaces its water.
The options considered:
Option |
Why it was not chosen |
|---|---|
List every vehicle’s links in the world |
The world has to know every vehicle before it starts, and a vehicle spawned later, or a second copy of one, never floats. |
No list at all |
Everything floats, contact geometry included. |
Generate the world from a template at launch, filling in |
The world still needs every vehicle’s link names, and every custom world needs the same template machinery. |
Enable and disable services on the world plugin, with a model plugin that calls them |
Works, but needs transport, retries until the service exists, and a re-scan of links that already exist. Two plugins where one will do. |
A second, model-scoped instance of the plugin reading the world’s fluid |
Works, but two instances can push the same link twice, and every plugin loop has to be scoped to its model. |
Mark the collisions that displace |
Chosen. |
The chosen design. A collision carries an attribute, gz:buoyancy="true",
and a link with any marked collision floats by those alone, whatever the
model is called. The world adds <enable_by_default>false</enable_by_default>
so that unmarked collisions never float, and names nobody.
flowchart LR
M["model.sdf<br/><i>collision gz:buoyancy="true"</i>"]
S["ros_gz_sim create<br/><i>any name</i>"]
B["Buoyancy system<br/><i>enable_by_default false</i>"]
M --> S --> B
B -->|floats| L["the marked collisions only"]
Why it is the simplest of the six:
Plain SDF. The mark is data in the model file. No service, no second plugin, no timing, no name lookup.
Contact and displacement are separate shapes. A bracket keeps its contact box and adds no buoyancy; a hull gets both.
Renaming and copies are free, because nothing refers to a name.
Nothing changes for existing worlds. With neither tag the plugin behaves as it always has.
Where it lives. The change is upstream in Gazebo,
gz-sim commit 229ec07e.
Until a Gazebo release with it reaches the ROS vendor packages,
gz-maritime’s gz_buoyancy package carries the plugin with that change
applied, plus a workaround for a gz-math bug that crashed the simulation
when a box hull floated almost level
(gazebosim/gz-math#847).
When the release arrives, worlds switch the plugin name back to
gz-sim-buoyancy-system and no vehicle changes.
One name per instance
Several vehicles in one simulation need separate topics, ROS names and TF
trees. The multi-vehicle plan
lays the rules out; kai_bringup and the custom USV follow them:
the simulation part of a launch (server, GUI,
/clock) is separate from the spawn part (one instance: model, bridge, state publisher), so the first runs once and the second once per vehicle;the spawn part is one generic launch,
spawn_vehicle.launch.xml, that renders a vehicle’s model xacro, bridge template and URDF for a name, or runs the vehicle’s own generator; a vehicle ships files, not launch machinery, and a second copy of it is the same command with another name;one name per instance drives the model name, every topic, the ROS namespace and
robot_state_publisher’sframe_prefix; the URDF carries no name, so one description serves every instance;a vehicle’s bridge carries no
/clock; the simulation part bridges it once.
One thruster interface
Every vehicle here drives its propellers through gz_thruster, Gazebo’s
thruster system with a normalized command mode: a command in [-1, 1]
is scaled onto the plugin’s thrust limits, 1 to max_thrust_cmd and -1 to
min_thrust_cmd. Thrust in newtons is not something a real driver can
honour, since it depends on battery voltage and propeller state; an
autopilot or a controller produces a normalized output and the ESC maps it
onto the motor. With one interface, a controller written against the custom
USV drives the BlueBoat unchanged, and an autopilot’s servo outputs map onto
it directly. The mode is on its way upstream; when a Gazebo release carries
it, vehicles switch the plugin’s filename and name and nothing else.
Pingers in the world, receivers on vehicles
VRX’s acoustic pinger plugin lived on the receiving boat and held the pinger
as a position of its own: each boat had its own copy of the pinger, a
scoring plugin kept the copies in step over a topic, and a pinger hung under
a buoy did not move with it. gz_acoustics turns that round, the way the
buoyancy and wind marks do:
A pinger is a thing in the world. A model plugin writes it as a component on a link, so it moves with whatever carries it, every vehicle hears the same one, and the world can list them all.
A receiver is a sensor. A gz-sensors custom sensor on any link, found by the world’s acoustics system on any model, spawned at any time; its reading is in its own frame.
Behaviour, not acoustics. A ping is an event on a schedule, carried at the speed of sound to each receiver, and heard or not by a few rules (water, reach, band, field of view, dropout, overlap), each of which can be switched off. Nothing models how sound bends, echoes or fades beyond spherical spreading; a team testing its own signal processing will need more than this, which is left for later (time differences per hydrophone).
The world owns the switch. A pinger changes on its own
settopic; choosing which one pings in a task belongs to whoever runs the task, such as a competition server, which only has to sendsetmessages.
The plan, the survey of other simulators it draws on and what is left are in ACOUSTIC_PINGER_PLAN.md.
Buoyancy that follows the waves
Vehicles float on the flat water level by default, and the drawn waves pass
through their hulls (Waves and physics today).
gz_waves_buoyancy couples buoyancy to the waves, as a separate consumer of
the wave field that a world runs instead of the flat buoyancy. How it meets
each point:
A local water surface per collision shape. It samples the height of the drawn surface at each shape’s centre and at the ends of its footprint, fits a plane, and measures the volume under that plane instead of under z = 0.
Long hulls. One plane per shape is only good when the shape is short compared to the wavelength; the plane averages a shorter chop, and a long hull is better split into segments.
Update rate. The wave field updates at
<update_rate>(30 Hz inopen_water.sdf), slower than physics (250 Hz). Advancing it every step costs about four times the run time and changes the motion by nothing measurable, so the buoyancy reads the field as last advanced. A world that wants smoother forces sets<update_rate>0</update_rate>on the wave system.Choppy seas. The high-fidelity sea also moves the surface sideways;
waves::SurfaceHeightundoes that displacement to find the height of the surface as drawn.Hydrostatic only. The water pushes straight up with the weight displaced: no pressure change with depth under the wave, no horizontal wave force.
Seeing through the water
A camera under water sees the water as much as what is in it. The plan is in UNDERWATER_CAMERA_PLAN.md; this section grows as it lands.
What reaches the camera: the object’s light, faded with range; the veil the water adds; and the daylight, faded with depth before it lit anything.
The model. Per colour channel, a camera at depth z sees an object of colour J (as lit) at range r as
I = J · exp(−β^D r) + B∞(z) · (1 − exp(−β^B r)), B∞(z) = B∞ · exp(−K_d z)
the revised underwater image formation model (Akkaynak and Treibitz, CVPR 2018). The older “fog” model uses one coefficient for both terms; keeping β^D and β^B apart is what the revised model adds, and what lets a camera match real images (OceanSim’s colour-chart test).
The water belongs to the world. Like the waves, the wind and the
current, the water’s optics are one recipe on the world entity
(gz_water_optics), so every camera sees the same water, a change on the
water_optics/set topic reaches all of them at once, and other sensors can
read it later. Depth is measured below the wave field’s local surface, not a
flat level.
Water types, not coefficients. A world names a Jerlov type, the oceanographers’ classification, and optionally a visibility in metres; the system derives the coefficients from published optical properties (Solonenko and Mobley 2015): β^D = β^B = c = a + b, B∞ = b / c, K_d as measured. Explicit coefficients are there for a matched data set.
The presets.
The reference camera. gz_underwater_camera applies the model on the
CPU to an rgbd_camera’s colour and depth, which one render produces
together, so they never come from different frames. It is slower than a GPU
path would be (640×480 in about 22 ms) but exactly testable: its rendered
test checks the published image against the model computed in the test from
the in-air frame, pixel by pixel, and finds no difference. A GPU path, for
every camera and the GUI, must match it.
The GPU path. A render pass in gz-rendering sees only the colour image, never depth: passes are chained between two colour textures, and the camera’s depth buffer is Ogre’s own. So the GPU path does not post-process: it adds the model to Ogre’s PBS pixel shader, where every fragment knows its view-space position and so its range (the technique POSIM uses; no code taken from it). gz-rendering’s own shader pieces and Hlms listener are chained, not replaced. It matches the reference camera to 0.01 of a step on average. What PBS does not shade (the sky, the water surface, markers) is drawn as in air.
Checked against itself first. Every step is tested against what the
model predicts, generated from the same equations by
docs/_tools/underwater_camera_figures.py: a grey target against range,
the scene against depth, a colour chart by range.
What a camera must show: a 50 % grey target at each range, in three waters.
Sonar
Imaging, profiling and sidescan sonar share one engine, a sonar-equation model on geometry sampled with gz-rendering, configured by the shape of each sonar’s fan. The use cases, the theory of operation, the interface, and the implementation, testing and walkthroughs are in Sonar simulation design. Contributors can run the engine on its own with Render a ping without Gazebo. What a sonar costs, where the time goes, and how to keep it in budget are in Sonar performance.