Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maritime tutorials 💧 - Part 4 of 4 #2260

Merged
merged 68 commits into from
Dec 23, 2023
Merged
Changes from 65 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
08a93c3
Adding maritime tutorials.
caguero Dec 1, 2023
9f07e8a
Adding \page
caguero Dec 1, 2023
df4034f
Buoyancy and hydrodynamics tutorials.
caguero Dec 2, 2023
7aac66f
Update tutorials/adding_system_plugins.md
caguero Dec 5, 2023
85ef1d1
Update tutorials/adding_system_plugins.md
caguero Dec 5, 2023
edfc7b5
Update tutorials/adding_system_plugins.md
caguero Dec 5, 2023
5720567
Update tutorials/adding_system_plugins.md
caguero Dec 5, 2023
299c181
Update tutorials/adding_system_plugins.md
caguero Dec 5, 2023
a0d3d6a
Update tutorials/create_vehicle.md
caguero Dec 5, 2023
20da621
Update tutorials/create_vehicle.md
caguero Dec 5, 2023
4c3d0cd
Update tutorials/create_vehicle.md
caguero Dec 5, 2023
fe3bcd4
Update tutorials/frame_reference.md
caguero Dec 5, 2023
ce7df55
Update tutorials/frame_reference.md
caguero Dec 5, 2023
a00ea7d
Apply suggestions from code review
caguero Dec 5, 2023
f0da870
Update tutorials/adding_visuals.md
caguero Dec 5, 2023
61503a8
Merge branch 'caguero/maritime_tutorials_part1' into caguero/maritime…
caguero Dec 5, 2023
5213800
Lander and lrauv tutorials.
caguero Dec 5, 2023
5665677
Tweak
caguero Dec 5, 2023
d3b3970
Tweaks
caguero Dec 5, 2023
766f3b3
Merge branch 'caguero/maritime_tutorials_part1' into caguero/maritime…
caguero Dec 5, 2023
ded077d
Update tutorials/theory_buoyancy.md
caguero Dec 5, 2023
6aaa9f2
Update tutorials/theory_buoyancy.md
caguero Dec 5, 2023
d05b43d
Update tutorials/theory_buoyancy.md
caguero Dec 5, 2023
e22a5ab
Update tutorials/theory_buoyancy.md
caguero Dec 5, 2023
d6f3757
Update tutorials/theory_buoyancy.md
caguero Dec 5, 2023
c8fe299
Update tutorials/theory_hydrodynamics.md
caguero Dec 5, 2023
f8f5678
Update tutorials/theory_hydrodynamics.md
caguero Dec 5, 2023
18c8fb3
Update tutorials/theory_hydrodynamics.md
caguero Dec 5, 2023
52fa02d
Update tutorials/theory_hydrodynamics.md
caguero Dec 5, 2023
412bce2
Update tutorials/theory_hydrodynamics.md
caguero Dec 5, 2023
d4c5b70
Tweak
caguero Dec 5, 2023
0af2a7d
Merge branch 'caguero/maritime_tutorials_part2' into caguero/maritime…
caguero Dec 5, 2023
8ba76b1
Update tutorials/create_vehicle.md
caguero Dec 6, 2023
ff1e127
Update tutorials/adding_visuals.md
caguero Dec 6, 2023
ef9be7b
Tweaks
caguero Dec 6, 2023
6153ae0
Merge branch 'caguero/maritime_tutorials_part1' of github.com:gazebos…
caguero Dec 6, 2023
e4722f4
Merge branch 'caguero/maritime_tutorials_part1' into caguero/maritime…
caguero Dec 6, 2023
592eec7
Update tutorials/theory_buoyancy.md
caguero Dec 6, 2023
6dd4668
Update tutorials/theory_buoyancy.md
caguero Dec 6, 2023
6b250d9
Update tutorials/theory_buoyancy.md
caguero Dec 6, 2023
37e09cf
Merge branch 'caguero/maritime_tutorials_part2' of github.com:gazebos…
caguero Dec 6, 2023
a20bb7d
Merge branch 'caguero/maritime_tutorials_part2' into caguero/maritime…
caguero Dec 6, 2023
f667c7e
Tweaks
caguero Dec 6, 2023
c7c4b60
Update tutorials/lander.md
caguero Dec 6, 2023
c5f7502
Update tutorials/lander.md
caguero Dec 6, 2023
bac0519
Adding a maritime surface vehicle tutorial.
caguero Dec 6, 2023
bbfa8e2
Tweaks
caguero Dec 7, 2023
1b4be86
Apply suggestions from code review
caguero Dec 7, 2023
9ec2750
Update tutorials/theory_buoyancy.md
caguero Dec 7, 2023
5f6561d
Merge branch 'caguero/maritime_tutorials_part2' into caguero/maritime…
caguero Dec 7, 2023
884abd0
Merge branch 'caguero/maritime_tutorials_part3' into caguero/maritime…
caguero Dec 7, 2023
45f5e2b
Update tutorials/theory_hydrodynamics.md
caguero Dec 12, 2023
397477a
Update tutorials/lander.md
caguero Dec 12, 2023
236559a
Update tutorials/lander.md
caguero Dec 12, 2023
ca65fb9
Update tutorials/lander.md
caguero Dec 12, 2023
755e3d0
Update tutorials/surface_vehicles.md
caguero Dec 12, 2023
cd10951
Update tutorials/surface_vehicles.md
caguero Dec 12, 2023
2c69504
Note about added mass.
caguero Dec 14, 2023
6b27aba
Merge branch 'caguero/maritime_tutorials_part2' of github.com:gazebos…
caguero Dec 14, 2023
a2a8334
Merge branch 'caguero/maritime_tutorials_part2' into caguero/maritime…
caguero Dec 14, 2023
b114462
Merge branch 'caguero/maritime_tutorials_part3' into caguero/maritime…
caguero Dec 14, 2023
292e12d
Tweaks
caguero Dec 14, 2023
8ceffd3
Merge
caguero Dec 22, 2023
b6214af
Tweaks
caguero Dec 22, 2023
d29db6e
Remove
caguero Dec 22, 2023
92eeb8c
Style.
caguero Dec 22, 2023
70d7799
Style
caguero Dec 22, 2023
33ba83e
Style
caguero Dec 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tutorials.md.in
Original file line number Diff line number Diff line change
@@ -95,7 +95,10 @@ for your model.
* \subpage adding_system_plugins "Adding system plugins:" How to add plugins to
your model to provide extra capabilities to it.
* \subpage lander "Create a lander vehicle:" How to create a lander robot.
* \subpage underwater_vehicles "Create an underwater vehicle:" How to create an underwater robot.
* \subpage underwater_vehicles "Create an underwater vehicle:" How to create an
underwater robot.
* \subpage surface_vehicles "Create a surface vehicle:" How to create a maritime
surface robot.

## License

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)

project(gazebo_maritime)

find_package(gz-sim8 REQUIRED)
set(GZ_SIM_VER ${gz-sim8_VERSION_MAJOR})
find_package(gz-common5 REQUIRED COMPONENTS graphics)
set(GZ_COMMON_VER ${gz-common5_VERSION_MAJOR})
find_package(gz-math7 REQUIRED)
set(GZ_MATH_VER ${gz-math7_VERSION_MAJOR})
find_package(gz-msgs10 REQUIRED)
caguero marked this conversation as resolved.
Show resolved Hide resolved
set(GZ_MSGS_VER ${gz-msgs10_VERSION_MAJOR})
find_package(gz-transport13 REQUIRED)
set(GZ_TRANSPORT_VER ${gz-transport13_VERSION_MAJOR})
caguero marked this conversation as resolved.
Show resolved Hide resolved
find_package(gz-plugin2 REQUIRED COMPONENTS loader register)
set(GZ_PLUGIN_VER ${gz-plugin2_VERSION_MAJOR})
find_package(gz-rendering8 REQUIRED)
set(GZ_RENDERING_VER ${gz-rendering8_VERSION_MAJOR})
find_package(gz-sensors8 REQUIRED)
set(GZ_SENSORS_VER ${gz-sensors8_VERSION_MAJOR})
find_package(gz-utils2 REQUIRED)
set(GZ_UTILS_VER ${gz-utils2_VERSION_MAJOR})
caguero marked this conversation as resolved.
Show resolved Hide resolved
find_package(sdformat14 REQUIRED)
find_package(Eigen3 REQUIRED)

# Waves
add_library(Waves SHARED
src/Wavefield.cc
)
target_link_libraries(Waves PUBLIC
Eigen3::Eigen
gz-common${GZ_COMMON_VER}::gz-common${GZ_COMMON_VER}
gz-math${GZ_MATH_VER}
gz-msgs${GZ_MSGS_VER}::gz-msgs${GZ_MSGS_VER}
gz-sim${GZ_SIM_VER}::core
)
install(
TARGETS Waves
DESTINATION lib)

# Other plugins
list(APPEND MARITIME_GZ_PLUGINS
PublisherPlugin
Surface
WaveVisual
)

foreach(PLUGIN ${MARITIME_GZ_PLUGINS})
add_library(${PLUGIN} SHARED src/${PLUGIN}.cc)
target_link_libraries(${PLUGIN} PUBLIC
Eigen3::Eigen
gz-plugin${GZ_PLUGIN_VER}::gz-plugin${GZ_PLUGIN_VER}
gz-rendering${GZ_RENDERING_VER}::gz-rendering${GZ_RENDERING_VER}
gz-sensors${GZ_SENSORS_VER}::gz-sensors${GZ_SENSORS_VER}
gz-sim${GZ_SIM_VER}::core
gz-transport${GZ_TRANSPORT_VER}::gz-transport${GZ_TRANSPORT_VER}
gz-utils${GZ_UTILS_VER}::gz-utils${GZ_UTILS_VER}
Waves
)
endforeach()

install(
TARGETS ${MARITIME_GZ_PLUGINS}
DESTINATION lib)

#============================================================================
# Resources
install(DIRECTORY
models
worlds
DESTINATION share/${PROJECT_NAME})
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (c) 2016 The UUV Simulator Authors.
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#version 330

////////// Input parameters //////////
// Textures
uniform sampler2D bumpMap;
uniform samplerCube cubeMap;

// Colors
uniform vec4 deepColor;
uniform vec4 shallowColor;
uniform float fresnelPower;
uniform float hdrMultiplier;

////////// Input computed in vertex shader //////////
in block
{
mat3 rotMatrix;
vec3 eyeVec;
vec2 bumpCoord;
} inPs;

out vec4 fragColor;

void main()
{
// Apply bump mapping to normal vector to make waves look more detailed:
vec4 bump = texture(bumpMap, inPs.bumpCoord)*2.0 - 1.0;
vec3 N = normalize(inPs.rotMatrix * bump.xyz);

// Reflected ray:
vec3 E = normalize(inPs.eyeVec);
vec3 R = reflect(E, N);

// negate z for use with the skybox texture that comes with gz-rendering
R = vec3(R.x, R.y, -R.z);

// uncomment this line if using other textures that are Y up
// Gazebo requires rotated cube map lookup.
// R = vec3(R.x, R.z, R.y);

// Get environment color of reflected ray:
vec4 envColor = texture(cubeMap, R, 0.0);

// Cheap hdr effect:
envColor.rgb *= (envColor.r+envColor.g+envColor.b)*hdrMultiplier;

// Compute refraction ratio (Fresnel):
float facing = 1.0 - dot(-E, N);
float waterEnvRatio = clamp(pow(facing, fresnelPower), 0.05, 1.0);

// Refracted ray only considers deep and shallow water colors:
vec4 waterColor = mix(shallowColor, deepColor, facing);

// Perform linear interpolation between reflection and refraction.
vec4 color = mix(waterColor, envColor, waterEnvRatio);

fragColor = vec4(color.xyz, 0.9);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// Copyright (c) 2016 The UUV Simulator Authors.
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.s


// Copyright (c) 2019 Rhys Mainwaring.
//
// Modified to accept vector parameters and use the form
// for Gerstner waves published in:
//
// Jerry Tessendorf, "Simulating Ocean Water", 1999-2004
//
// theta = k * dir . x - omega * t
//
// px = x - dir.x * a * k * sin(theta)
// py = y - dir.y * a * k * sin(theta)
// pz = a * k * cos(theta)
//
// k is the wavenumber
// omega is the angular frequency
//
// The derivative terms (Tangent, Binormal, Normal) have been
// updated to be consistent with this convention.
//

#version 330

in vec4 vertex;
in vec4 uv0;
uniform mat4 worldviewproj_matrix;

/////////// Input parameters //////////
// Waves
uniform int Nwaves;
uniform vec3 camera_position_object_space;
uniform float rescale;
uniform vec2 bumpScale;
uniform vec2 bumpSpeed;
uniform float t;
uniform vec3 amplitude;
uniform vec3 wavenumber;
uniform vec3 omega;
uniform vec3 steepness;
uniform vec2 dir0;
uniform vec2 dir1;
uniform vec2 dir2;
uniform float tau;

/////////// Output variables to fragment shader //////////
out block
{
mat3 rotMatrix;
vec3 eyeVec;
vec2 bumpCoord;
} outVs;

// Compute linear combination of Gerstner waves as described in
// GPU Gems, chapter 01: "Effective Water Simulation from Physical Models"
// http://http.developer.nvidia.com/GPUGems/gpugems_ch01.html

// Information regarding a single wave
struct WaveParameters {
float k; // wavenumber
float a; // amplitude
float omega; // phase constant of speed
vec2 d; // horizontal direction of wave
float q; // steepness for Gerstner wave (q=0: rolling sine waves)
};



out gl_PerVertex
{
vec4 gl_Position;
};

void main()
{
// Use combination of three waves. Values here are chosen rather arbitrarily.
// Other parameters might lead to better-looking waves.

WaveParameters waves[3];

waves[0] = WaveParameters(wavenumber.x, amplitude.x, omega.x, dir0.xy, steepness.x);
waves[1] = WaveParameters(wavenumber.y, amplitude.y, omega.y, dir1.xy, steepness.y);
waves[2] = WaveParameters(wavenumber.z, amplitude.z, omega.z, dir2.xy, steepness.z);

vec4 P = vertex;

// Iteratively compute binormal, tangent, and normal vectors:
vec3 B = vec3(1.0, 0.0, 0.0);
vec3 T = vec3(0.0, 1.0, 0.0);
vec3 N = vec3(0.0, 0.0, 1.0);

// Wave synthesis using linear combination of Gerstner waves
for(int i = 0; i < Nwaves; ++i)
{
// Evaluate wave equation:
float k = waves[i].k;
float a = waves[i].a * (1.0 - exp(-1.0*t/tau));
float q = waves[i].q;
float dx = waves[i].d.x;
float dy = waves[i].d.y;
float theta = dot(waves[i].d, P.xy)*k - t*waves[i].omega;
float c = cos(theta);
float s = sin(theta);

// Displacement of point due to wave (Eq. 9)
P.x -= q*a*dx*s;
P.y -= q*a*dx*s;
P.z += a*c;

// Modify normals due to wave displacement (Eq. 10-12)
float ka = a*k;
float qkac = q*ka*c;
float kas = ka*s;
float dxy = dx*dy;

B += vec3(-qkac*dx*dx, -qkac*dxy, -kas*dx);
T += vec3(-qkac*dxy, -qkac*dy*dy, -kas*dy);
N += vec3(dx*kas, dy*kas, -qkac);
}

// Compute (Surf2World * Rescale) matrix
B = normalize(B)*rescale;
T = normalize(T)*rescale;
N = normalize(N);
outVs.rotMatrix = mat3(B, T, N);

gl_Position = worldviewproj_matrix * P;

// Compute texture coordinates for bump map
outVs.bumpCoord = uv0.xy*bumpScale + t*bumpSpeed;

outVs.eyeVec = P.xyz - camera_position_object_space; // eye position in vertex space
}

Binary file not shown.
Binary file not shown.
Loading