POSIM v1.0.1Platform for Ocean Simulation · Documentation
Documentation menu
POSIM / Plugin reference

Ocean currents

POSIM generates ocean currents for the world, calculates the flow at each robot and exposes ROS controls. Uniform currents and currents that vary with depth use separate topics and settings.

Run the example

Prepare terminals A and B in your selected POSIM environment: native Ubuntu, WSL, Docker or the macOS remote desktop. Start the example in terminal A.

ros2 launch posim_demos posim_robot.launch.py \
  namespace:=rexrov world_name:=ocean_current_plugin z:=-5 paused:=false \
  gui:=true headless:=false use_teleop:=false use_web_joystick:=false

In terminal B, inspect Gazebo and ROS data in turn:

gz topic -e -t /ocean_current

Press Ctrl+C to stop the Gazebo viewer before running the ROS command.

ros2 topic echo /hydrodynamics/currentVelocityTopic --once

Configure uniform and stratified currents

Place both plugins directly inside <world>, following the example world SDF. Put the world-current plugin before the ROS plugin. Include a nonempty <namespace> and both <constant_current> and <transient_current> blocks. Missing required configuration disables current publication and logs an error. Uniform flow uses separate stochastic models for speed and horizontal/vertical angles.

Parameter Meaning / default
Both plugins: namespace Shared world namespace; set hydrodynamics for this example
constant_current/use_constant_current Enable uniform-current publication; default false
constant_current/topic Gazebo uniform-current topic; default ocean_current
transient_current/topic_stratified Gazebo layer topic under the namespace; default stratified_current_velocity
transient_current/databasefileName CSV under installed posim_worlds/worlds; default transientOceanCurrentDatabase.csv
transient_current/databasefilePath Optional custom CSV path; overrides databasefileName
Each stochastic model: mean Initial mean speed (m/s) or angle (rad); default 0
Each stochastic model: min, max Bounds; defaults −1 and 1; keep min < max and mean within bounds
Each stochastic model: noiseAmp Random increment amplitude; default 0
Each stochastic model: mu Gauss–Markov decay coefficient; default 0
tidal_oscillation Optional tidal input block; see the depth/tide section below
<plugin filename="OceanCurrentWorldPlugin"
        name="posim_gz_world_plugins::OceanCurrentWorldPlugin">
  <namespace>hydrodynamics</namespace>
  <constant_current>
    <use_constant_current>true</use_constant_current>
    <topic>ocean_current</topic>
    <velocity><mean>0.3</mean><min>0</min><max>0.6</max><mu>0</mu><noiseAmp>0</noiseAmp></velocity>
    <horizontal_angle><mean>0</mean><min>-3.14</min><max>3.14</max><mu>0</mu><noiseAmp>0</noiseAmp></horizontal_angle>
    <vertical_angle><mean>0</mean><min>-1.57</min><max>1.57</max><mu>0</mu><noiseAmp>0</noiseAmp></vertical_angle>
  </constant_current>
  <transient_current>
    <topic_stratified>stratified_current_velocity</topic_stratified>
    <databasefileName>transientOceanCurrentDatabase.csv</databasefileName>
  </transient_current>
</plugin>
<plugin filename="OceanCurrentPlugin" name="posim_ros_gz_plugins::OceanCurrentPlugin">
  <namespace>hydrodynamics</namespace>
</plugin>

The stratified-current CSV contains world X velocity (m/s), world Y velocity (m/s) and depth (m), in that order. The legacy keys velocity_north, velocity_east and velocity_down map directly to world X, Y and Z. Preserve the first three description/header rows. Supply at least two layers, with exactly three finite numbers per row and strictly increasing, nonnegative depths. A missing or malformed profile disables current publication and logs an error.

The world ROS plugin relays the full database; the model-current plugin computes flow at vehicle depth. Match the model <namespace> to the hydrodynamics subscription /model/<namespace>/ocean_current. Flow relative to vehicle velocity affects its hydrodynamic response.

Apply flow at the robot's depth

The REXROV quickstart uses uniform /ocean_current. To use the depth profile, add the following plugin directly under its <model> and add <namespace>rexrov</namespace> inside its existing gz-sim-hydrodynamics-system plugin. Keep that hydrodynamics plugin's link, density and drag coefficients. The model-current block is commented out in the REXROV descriptor; enable it once, then rebuild and source the workspace.

<plugin filename="OceanCurrentModelPlugin"
        name="posim_gz_model_plugins::OceanCurrentModelPlugin">
  <namespace>rexrov</namespace>
  <flow_velocity_topic>ocean_current</flow_velocity_topic>
  <transient_current>
    <topic_stratified>/hydrodynamics/stratified_current_velocity_topic_database</topic_stratified>
    <velocity_north><mean>0</mean><mu>0</mu><noiseAmp>0</noiseAmp><noiseFreq>0</noiseFreq></velocity_north>
    <velocity_east><mean>0</mean><mu>0</mu><noiseAmp>0</noiseAmp><noiseFreq>0</noiseFreq></velocity_east>
    <velocity_down><mean>0</mean><mu>0</mu><noiseAmp>0</noiseAmp><noiseFreq>0</noiseFreq></velocity_down>
  </transient_current>
  <tide_oscillation>false</tide_oscillation>
</plugin>
Model-plugin parameter Meaning / default
namespace Required topic namespace, rexrov here; match the hydrodynamics namespace
flow_velocity_topic Suffix under /model/<namespace>/; default ocean_current
transient_current/topic_stratified ROS database input; default hydrodynamics/stratified_current_velocity_topic_database
velocity_north, velocity_east, velocity_down Optional stochastic settings for each component; omitted components use zero noise
Each component's mean Initial velocity in m/s, default 0; replaced by the interpolated profile when data arrives
Each component's mu Decay coefficient from 0 to 1, applied using elapsed simulation seconds; default 0
Each component's noiseAmp Allowed deviation around the interpolated velocity in m/s, default 0
Each component's noiseFreq Random increment amplitude per update, default 0; despite its name, this value is not a frequency in Hz
tide_oscillation Apply supplied tidal data at the model; default false

The model plugin publishes /model/rexrov/ocean_current on both Gazebo (gz.msgs.Vector3d) and ROS (geometry_msgs/msg/TwistStamped). Inspect this output and the vehicle response after enabling the profile.

Depth comes from the attached model's world position, with zero depth above the surface. Flow is interpolated between layers and clamped to the nearest layer outside the profile. Paused or repeated simulation timestamps do not advance the current. Invalid database messages are rejected as a whole, preserving the last valid profile.

Systems and topics

Component Responsibility
posim_gz_world_plugins::OceanCurrentWorldPlugin Generate world flow and depth-layer data
Model current plugin Interpolate/apply the configured current at a model
posim_ros_gz_plugins::OceanCurrentPlugin Publish ROS observations and offer configuration services
Example topic Transport / type
/ocean_current Gazebo gz.msgs.Vector3d
/hydrodynamics/stratified_current_velocity Gazebo layer data
/hydrodynamics/stratifiedCurrentVelocityTopic ROS posim_interfaces/msg/StratifiedCurrentVelocity
/hydrodynamics/currentVelocityTopic ROS geometry_msgs/msg/TwistStamped
/hydrodynamics/stratified_current_velocity_topic_database ROS posim_interfaces/msg/StratifiedCurrentDatabase

Read the world's SDF for the configured namespaces and topic names. Keep vehicle hydrodynamics connected to the same intended flow source.

Configure a velocity

List service names and types before calling them:

ros2 service list -t
ros2 service call /hydrodynamics/set_current_velocity posim_interfaces/srv/SetCurrentVelocity \
  '{velocity: 0.3, horizontal_angle: 0.0, vertical_angle: 0.0}'

Velocity is in m/s and the two angles are in radians. The example requests a horizontal flow along the zero-angle direction; check the returned success flag and current data that follows.

Model services use GetCurrentModel and SetCurrentModel for velocity, horizontal angle and vertical angle. Parameters include mean, lower/upper bounds, noise amplitude and mu. Depth-specific services use the stratified interface types. For example, inspect the layer-velocity request and response before setting a layer:

ros2 interface show posim_interfaces/srv/SetStratifiedCurrentVelocity

Each request either applies completely or returns success: false without changing the current. Values must be finite and within the configured bounds. Velocity bounds are nonnegative; horizontal-angle bounds stay within −π to π, and vertical-angle bounds within −π/2 to π/2. Model settings apply to the global model and every depth layer while preserving each layer's mean, so new bounds must contain those means too.

Read and adjust the models

The example ROS namespace is /hydrodynamics. Inspect actual names with ros2 service list -t before calling them.

ros2 service call /hydrodynamics/get_current_velocity_model \
  posim_interfaces/srv/GetCurrentModel '{}'
ros2 service call /hydrodynamics/set_current_velocity_model \
  posim_interfaces/srv/SetCurrentModel \
  '{mean: 0.3, min: 0.0, max: 0.6, noise: 0.0, mu: 0.0}'
ros2 service call /hydrodynamics/set_stratified_current_velocity \
  posim_interfaces/srv/SetStratifiedCurrentVelocity \
  '{layer: 0, velocity: 0.2, horizontal_angle: 0.0, vertical_angle: 0.0}'
Service Interface Input
get_current_velocity_model, get_current_horz_angle_model, get_current_vert_angle_model GetCurrentModel Empty request
set_current_velocity_model, set_current_horz_angle_model, set_current_vert_angle_model SetCurrentModel mean, min, max, noise, mu
set_current_velocity SetCurrentVelocity velocity, horizontal_angle, vertical_angle
set_current_horz_angle, set_current_vert_angle SetCurrentDirection angle
set_stratified_current_velocity SetStratifiedCurrentVelocity layer, velocity, horizontal_angle, vertical_angle
set_stratified_current_horz_angle, set_stratified_current_vert_angle SetStratifiedCurrentDirection layer, angle

Speed is in m/s, angles in rad and layer is a zero-based database index. Check both success and observed topics. The ROS service field corresponding to SDF noiseAmp is noise.

Tidal inputs

The world plugin loads a configured depth database and uses stochastic current models. The optional tidal configuration uses a database or supplied harmonic constituents with a configured start time and ebb/flood direction. These are experiment inputs, rather than live current observations.

Preserve the database units, interpolation range, world origin and time reference when changing a profile. Compare received current and vehicle response with the same initial pose before interpreting a navigation result.

For tides, configure <tidal_oscillation> with CSV input or harmonic constituents such as M2/S2/N2, ebb/flood directions and a GMT start time. Example harmonic units are amplitude in m, phase in degrees and angular speed in degrees/hour. Distinguish tidal direction settings from the radian angles used by current services.

In tidal mode, the evaluated harmonic signal, or CSV speed divided by 100, is multiplied by the first depth-profile column. The example's height amplitudes are used as numeric factors; the model does not convert tidal height to current speed. Calibrate the combined signal and profile for the intended current velocity.

Tidal CSV files have one header row followed by YYYY-MM-DD HH:MM,event,speed rows. Events are flood, ebb or slack; speed is finite cm/s, with - permitted for skipped slack rows. Dates must be valid and strictly increasing. The loader retains alternating positive/negative peaks and requires at least two. Interpolation holds the first or last peak outside the time range. Missing files, incomplete settings or malformed data disable the world-current plugin with an error.

Current flow and model response

Depth-stratified currents and vehicle response
Depth-stratified currents and vehicle response
Data flow between world, ROS and model-current plugins
Data flow between world, ROS and model-current plugins
Vehicle response to uniform current
Vehicle response to stratified current
Vehicle response to stratified current
ROS uniform-current output
ROS uniform-current output
ROS stratified-current output
ROS stratified-current output
Stratified-current database output
Stratified-current database output
Applying current at model depth
Per-model current velocity
Per-model current velocity
Model-current ROS topic
Model-current ROS topic
Model-current Gazebo topic
Model-current Gazebo topic

Figures and videos: POSIM Notion Wiki. See Citation and licenses for DAVE documentation attribution. Use this page's code blocks for execution commands and topic names.