An open API service indexing awesome lists of open source software.

https://github.com/srmainwaring/asv_wave_sim

This package contains plugins that support the simulation of waves and surface vessels in Gazebo.
https://github.com/srmainwaring/asv_wave_sim

gazebo hydrodynamics ros simulation waves

Last synced: 6 months ago
JSON representation

This package contains plugins that support the simulation of waves and surface vessels in Gazebo.

Awesome Lists containing this project

README

          

# Wave Sim

[![Ubuntu Jammy CI](https://github.com/srmainwaring/asv_wave_sim/actions/workflows/ubuntu-jammy-ci.yml/badge.svg)](https://github.com/srmainwaring/asv_wave_sim/actions/workflows/ubuntu-jammy-ci.yml)
[![macOS Ventura CI](https://github.com/srmainwaring/asv_wave_sim/actions/workflows/macos13-ventura-ci.yml/badge.svg)](https://github.com/srmainwaring/asv_wave_sim/actions/workflows/macos13-ventura-ci.yml)
[![Cpplint](https://github.com/srmainwaring/asv_wave_sim/actions/workflows/ccplint.yml/badge.svg)](https://github.com/srmainwaring/asv_wave_sim/actions/workflows/ccplint.yml)
[![Cppcheck](https://github.com/srmainwaring/asv_wave_sim/actions/workflows/ccpcheck.yml/badge.svg)](https://github.com/srmainwaring/asv_wave_sim/actions/workflows/ccpcheck.yml)

This package contains plugins that support the simulation of waves and surface vessels in [Gazebo](https://gazebosim.org/home).

![rs750_ardupilot_v3_upwind](https://user-images.githubusercontent.com/24916364/228044489-b434b1ae-c30f-4676-9415-1719ee75479b.gif)

The main branch targets [Gazebo Garden](https://gazebosim.org/docs/garden) and no longer has a dependency on ROS.

There are new features including FFT wave generation methods, ocean tiling, and support for the [Ogre2](https://github.com/OGRECave/ogre-next) render engine. There are some changes in the way that the wave parameters need to be set, but as far possible we have attempted to retain compatibility with the earlier versions. Further details are described below where you can also find a section describing [support for legacy versions of Gazebo](#legacy-versions).

## Dependencies

- A working installation of [Gazebo Garden](https://gazebosim.org/docs/garden) or later including development symbols.

- The simulation uses the [CGAL](https://www.cgal.org/) library for mesh manipulation and [FFTW](http://www.fftw.org/) to compute Fourier transforms. Both libraries are licensed GPL-3.0.

## Ubuntu

- Ubuntu 22.04 (Jammy)
- Gazebo Sim, version 7.1.0 (Garden)

Install CGAL and FFTW:

```zsh
sudo apt-get update
sudo apt-get install libcgal-dev libfftw3-dev
```

## macOS

- macOS 12.6 (Monterey)
- Gazebo Sim, version 7.1.0 (Garden)

Install CGAL and FFTW:

```zsh
brew update
brew install cgal fftw
```

## Installation

### Create a workspace

```bash
mkdir -p gz_ws/src
```

### Clone and build the package

Clone the `asv_wave_sim` repository:

```bash
cd ~/gz_ws/src
git clone https://github.com/srmainwaring/asv_wave_sim.git
```

Compile the package:

#### Ubuntu

```bash
colcon build --symlink-install --merge-install --cmake-args \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DBUILD_TESTING=ON \
-DCMAKE_CXX_STANDARD=17
```

Source the workspace:

```bash
source ./install/setup.bash
```

#### macOS

```bash
colcon build --symlink-install --merge-install --cmake-args \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DBUILD_TESTING=ON \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_MACOSX_RPATH=FALSE \
-DCMAKE_INSTALL_NAME_DIR=$(pwd)/install/lib
```

Source the workspace:

```bash
source ./install/setup.zsh
```

### Build the GUI plugin (optional)

There is an optional GUI plugin that controls the wave parameters.

```bash
cd ~/gz_ws/src/asv_wave_sim/gz-waves/src/gui/plugins/waves_control
mkdir build && cd build
cmake .. && make
```

## Usage

### Set environment variables

```bash
# for future use - to support multiple Gazebo versions
export GZ_VERSION=garden

# not usually required as should default to localhost address
export GZ_IP=127.0.0.1

# ensure the model and world files are found
export GZ_SIM_RESOURCE_PATH=\
$GZ_SIM_RESOURCE_PATH:\
$HOME/gz_ws/src/asv_wave_sim/gz-waves-models/models:\
$HOME/gz_ws/src/asv_wave_sim/gz-waves-models/world_models:\
$HOME/gz_ws/src/asv_wave_sim/gz-waves-models/worlds

# ensure the system plugins are found
export GZ_SIM_SYSTEM_PLUGIN_PATH=\
$GZ_SIM_SYSTEM_PLUGIN_PATH:\
$HOME/gz_ws/install/lib

# ensure the gui plugin is found
export GZ_GUI_PLUGIN_PATH=\
$GZ_GUI_PLUGIN_PATH:\
$HOME/gz_ws/src/asv_wave_sim/gz-waves/src/gui/plugins/waves_control/build
```

### Ubuntu VM

If running on an Ubuntu virtual machine you may need to use software rendering if the hypervisor does not support hardware acceleration for OpenGL 4.2+. Install `mesa-utils` to enable llvmpipe:

```bash
sudo apt-get install mesa-utils
```

To use the llvmpipe software renderer, prefix Gazebo commands with the `LIBGL_ALWAYS_SOFTWARE` environment variable:

```bash
LIBGL_ALWAYS_SOFTWARE=1 gz sim waves.sdf
```

## Examples

On macOS the client and server must be launched separately. The commands may be combined on Ubuntu.

Launch a Gazebo session.

Server:

```bash
gz sim -v4 -s -r waves.sdf
```

Client:

```bash
gz sim -v4 -g
```

The session should include a wave field and some floating objects.

## Changes

There are some changes to the plugin SDF schema for hydrodynamics and waves.

### Waves model and visual plugins

- The `filename` and `name` attributes for the wave model and visal plugins have changed.
- The `` element has been renamed to `` and moved into ``
- The `` element has been moved into ``
- Add new element `` to specify the wave generation algorithm. Valid options are: `sinusoid`, `trochoid` and `fft`.
- Add new element `` for use with the `fft` algorithm.
- Add new element `` for use with the `fft` algorithm.
- Add new element `` for use with the `fft` algorithm.

```xml

0
30



256.0
128


256.0 64.0
128 32


fft
5.0
135
2


trochoid
3
1.5
0.4
0.4
8.0
0.0
1.0
1 0

```

The waves visual plugin has the same algorithm elements as the model plugin and extra elements to control the shading algorithm. Two approaches are available:

- `DYNAMIC_GEOMETRY` uses PBS shaders and is suitable for small areas.
- `DYNAMIC_TEXTURE` uses a custom shader and is suitable for tiled areas.

```xml

0


DYNAMIC_GEOMETRY


-1 1
-1 1


fft
256.0
128
5.0
135
2



materials/waves_vs.glsl
materials/waves_fs.glsl


materials/waves_vs.metal
materials/waves_fs.metal



vertex
world_matrix


vertex
worldviewproj_matrix


vertex
camera_position


vertex
rescale
0.5
float


vertex
bumpScale
64 64
float_array


vertex
bumpSpeed
0.01 0.01
float_array


vertex
t
TIME



fragment
deepColor
0.0 0.05 0.2 1.0
float_array


fragment
shallowColor
0.0 0.1 0.3 1.0
float_array


fragment
fresnelPower
5.0
float


fragment
hdrMultiplier
0.4
float


fragment
bumpMap
materials/wave_normals.dds
texture
0


fragment
cubeMap
materials/skybox_lowres.dds
texture_cube
1

```

### Hydrodynamics plugin

- The `filename` and `name` attributes for the hydrodynamics plugin have changed.
- The hydrodynamics parameters are now scoped in an additional `` element.
- The buoyancy and hydrodynamics forces can be applied to specific entities
in a model using the `` element. The parameter should be a fully
scoped model entity (model, link or collision name).
- The `` element is not used.

```xml


model_name


model_name::link1
model_name::link2


model_name::link1::collision1
model_name::link1::collision2



1
1
1


1.0E-6
1.0E-6
1.0E-6
1.0E-6


1.0E+2
1.0E+2
0.4
1.0E+2
1.0E+2
0.4
1.0



10
1
1
1

```

## Tests

```bash
# build with tests
$ colcon build --merge-install --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_MACOSX_RPATH=FALSE -DCMAKE_INSTALL_NAME_DIR=$(pwd)/install/lib -DBUILD_TESTING=ON --packages-select gz-waves1

# run tests
colcon test --merge-install

# check results
colcon test-result --all --verbose
```

Testing within a project build directory

```bash
$ cd ~/gz_ws/src/asv_wave_sim/gz-waves
$ mkdir build && cd build
$ cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=ON
$ make && make test
```

## Plots

Plots may be generated for some of the wave spectra and wave simulation methods:

```bash
./install/bin/PLOT_WaveSpectrum
```

## Legacy versions

There is no plan to back-port new features to Gazebo9 or Gazebo11. The following branches are maintained for legacy support:

- [`gazebo9`](https://github.com/srmainwaring/asv_wave_sim/tree/gazebo9) - for Gazebo9 / ROS Melodic / Ubuntu 18.04 (Bionic).

- [`gazebo11`](https://github.com/srmainwaring/asv_wave_sim/tree/gazebo11) - for Gazebo11 / ROS Noetic / Ubuntu 20.04 (Focal).

In addition there are three branches that contain development iterations of the FFT wave simulation - for Gazebo11 / ROS Noetic / Ubuntu 20.04 (Focal):

- [`feature/fft-waves-v1`](https://github.com/srmainwaring/asv_wave_sim/tree/feature/fft-waves-v1)
- [`feature/fft-waves-v2`](https://github.com/srmainwaring/asv_wave_sim/tree/feature/fft-waves-v2)
- [`feature/fft-waves-v3`](https://github.com/srmainwaring/asv_wave_sim/tree/feature/fft-waves-v3)

## License

This is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the [GNU General Public License](LICENSE) for more details.

This project makes use of other open source software, for full details see the file [LICENSE_THIRDPARTY](LICENSE_THIRDPARTY).

## Acknowledgments

- Jacques Kerner's two part blog describing boat physics for games: [Water interaction model for boats in video games](https://www.gamasutra.com/view/news/237528/Water_interaction_model_for_boats_in_video_games.php) and [Water interaction model for boats in video games: Part 2](https://www.gamasutra.com/view/news/263237/Water_interaction_model_for_boats_in_video_games_Part_2.php).
- The [CGAL](https://doc.cgal.org) libraries are used for the wave field and model meshes.
- The [UUV Simulator](https://github.com/uuvsimulator/uuv_simulator) package for the orginal vertex shaders used in the wave field visuals.
- The [VMRC](https://bitbucket.org/osrf/vmrc) package for textures and meshes used in the wave field visuals.
- Jerry Tessendorf's paper on [Simulating Ocean Water](https://people.cs.clemson.edu/~jtessen/reports/papers_files/coursenotes2004.pdf)
- Curtis Mobley's web book [Ocean Optics](https://www.oceanopticsbook.info/) in particular the section on [Modeling Sea Surfaces](https://www.oceanopticsbook.info/view/surfaces/level-2/modeling-sea-surfaces) and [example IDL code](https://www.oceanopticsbook.info/packages/iws_l2h/conversion/files/IDL-SurfaceGenerationCode.zip)