Skip to content

Commit 8f84b05

Browse files
cagueroahcordecrvogtiche033
authored
Maritime tutorials 💧 - Part 4 of 4 (#2260)
* Adding a maritime surface vehicle tutorial. --------- Signed-off-by: Carlos Agüero <[email protected]> Co-authored-by: Alejandro Hernández Cordero <[email protected]> Co-authored-by: crvogt <[email protected]> Co-authored-by: Ian Chen <[email protected]>
1 parent beada29 commit 8f84b05

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+388808
-39
lines changed

tutorials.md.in

+4-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ for your model.
9595
* \subpage adding_system_plugins "Adding system plugins:" How to add plugins to
9696
your model to provide extra capabilities to it.
9797
* \subpage lander "Create a lander vehicle:" How to create a lander robot.
98-
* \subpage underwater_vehicles "Create an underwater vehicle:" How to create an underwater robot.
98+
* \subpage underwater_vehicles "Create an underwater vehicle:" How to create an
99+
underwater robot.
100+
* \subpage surface_vehicles "Create a surface vehicle:" How to create a maritime
101+
surface robot.
99102

100103
## License
101104

tutorials/adding_system_plugins.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ gz sim -r ~/gazebo_maritime/worlds/buoyant_turtle.sdf
131131
```
132132

133133
Now, when our simple trajectory controller reaches its target and stops appling
134-
force, the turtle stops moving acting like the fluid decelerates its motion.
134+
force, the turtle stops moving acting like the fluid decelerates its motion.
135135
Additionally you can notice how the up and down oscillations are also damped by
136136
the effect of the hydrodynamics.
137137

tutorials/adding_visuals.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mesh to our turtle, making it look much better.
1111
https://gazebosim.org/api/sim/8/meshtofuel.html
1212

1313
The next tutorials, although still relevant, are from an older version of Gazebo
14-
and some details might be different than the current versions:
14+
and some details might be different than the current versions:
1515

1616
https://classic.gazebosim.org/tutorials?tut=import_mesh&cat=build_robot
1717
https://classic.gazebosim.org/tutorials?cat=guided_i&tut=guided_i2

tutorials/files/adding_system_plugins/buoyant_turtle.sdf

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<grid>false</grid>
1010
</scene>
11-
11+
1212
<light type="directional" name="sun">
1313
<cast_shadows>true</cast_shadows>
1414
<pose>0 0 10 0 0 0</pose>
@@ -27,7 +27,7 @@
2727
filename="gz-sim-physics-system"
2828
name="gz::sim::systems::Physics">
2929
</plugin>
30-
30+
3131
<plugin
3232
filename="gz-sim-buoyancy-system"
3333
name="gz::sim::systems::Buoyancy">
@@ -44,17 +44,17 @@
4444
filename="gz-sim-user-commands-system"
4545
name="gz::sim::systems::UserCommands">
4646
</plugin>
47-
47+
4848
<plugin
4949
filename="gz-sim-scene-broadcaster-system"
5050
name="gz::sim::systems::SceneBroadcaster">
5151
</plugin>
52-
52+
5353
<plugin
5454
filename="gz-sim-sensors-system"
5555
name="gz::sim::systems::Sensors">
5656
</plugin>
57-
57+
5858
<gui fullscreen="0">
5959
<!-- 3D scene -->
6060
<plugin filename="MinimalScene" name="3D View">

tutorials/files/lander/buoyant_lander.sdf

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ambient>0.0 1.0 1.0</ambient>
77
<grid>false</grid>
88
</scene>
9-
9+
1010
<light type="directional" name="sun">
1111
<cast_shadows>true</cast_shadows>
1212
<pose>0 0 10 0 0 0</pose>
@@ -25,7 +25,7 @@
2525
filename="gz-sim-physics-system"
2626
name="gz::sim::systems::Physics">
2727
</plugin>
28-
28+
2929
<plugin
3030
filename="gz-sim-buoyancy-system"
3131
name="gz::sim::systems::Buoyancy">
@@ -42,17 +42,17 @@
4242
filename="gz-sim-user-commands-system"
4343
name="gz::sim::systems::UserCommands">
4444
</plugin>
45-
45+
4646
<plugin
4747
filename="gz-sim-scene-broadcaster-system"
4848
name="gz::sim::systems::SceneBroadcaster">
4949
</plugin>
50-
50+
5151
<plugin
5252
filename="gz-sim-sensors-system"
5353
name="gz::sim::systems::Sensors">
5454
</plugin>
55-
55+
5656
<gui fullscreen="0">
5757
<!-- 3D scene -->
5858
<plugin filename="MinimalScene" name="3D View">

tutorials/files/lander/inkfish-lander.dae

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,4 @@
336336
<scene>
337337
<instance_visual_scene url="#Scene"/>
338338
</scene>
339-
</COLLADA>
339+
</COLLADA>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
2+
3+
project(gazebo_maritime)
4+
5+
find_package(gz-sim8 REQUIRED)
6+
set(GZ_SIM_VER ${gz-sim8_VERSION_MAJOR})
7+
find_package(gz-common5 REQUIRED COMPONENTS graphics)
8+
set(GZ_COMMON_VER ${gz-common5_VERSION_MAJOR})
9+
find_package(gz-math7 REQUIRED)
10+
set(GZ_MATH_VER ${gz-math7_VERSION_MAJOR})
11+
find_package(gz-msgs10 REQUIRED)
12+
set(GZ_MSGS_VER ${gz-msgs10_VERSION_MAJOR})
13+
find_package(gz-transport13 REQUIRED)
14+
set(GZ_TRANSPORT_VER ${gz-transport13_VERSION_MAJOR})
15+
find_package(gz-plugin2 REQUIRED COMPONENTS loader register)
16+
set(GZ_PLUGIN_VER ${gz-plugin2_VERSION_MAJOR})
17+
find_package(gz-rendering8 REQUIRED)
18+
set(GZ_RENDERING_VER ${gz-rendering8_VERSION_MAJOR})
19+
find_package(gz-sensors8 REQUIRED)
20+
set(GZ_SENSORS_VER ${gz-sensors8_VERSION_MAJOR})
21+
find_package(gz-utils2 REQUIRED)
22+
set(GZ_UTILS_VER ${gz-utils2_VERSION_MAJOR})
23+
find_package(sdformat14 REQUIRED)
24+
find_package(Eigen3 REQUIRED)
25+
26+
# Waves
27+
add_library(Waves SHARED
28+
src/Wavefield.cc
29+
)
30+
target_link_libraries(Waves PUBLIC
31+
Eigen3::Eigen
32+
gz-common${GZ_COMMON_VER}::gz-common${GZ_COMMON_VER}
33+
gz-math${GZ_MATH_VER}
34+
gz-msgs${GZ_MSGS_VER}::gz-msgs${GZ_MSGS_VER}
35+
gz-sim${GZ_SIM_VER}::core
36+
)
37+
install(
38+
TARGETS Waves
39+
DESTINATION lib)
40+
41+
# Other plugins
42+
list(APPEND MARITIME_GZ_PLUGINS
43+
PublisherPlugin
44+
Surface
45+
WaveVisual
46+
)
47+
48+
foreach(PLUGIN ${MARITIME_GZ_PLUGINS})
49+
add_library(${PLUGIN} SHARED src/${PLUGIN}.cc)
50+
target_link_libraries(${PLUGIN} PUBLIC
51+
Eigen3::Eigen
52+
gz-plugin${GZ_PLUGIN_VER}::gz-plugin${GZ_PLUGIN_VER}
53+
gz-rendering${GZ_RENDERING_VER}::gz-rendering${GZ_RENDERING_VER}
54+
gz-sensors${GZ_SENSORS_VER}::gz-sensors${GZ_SENSORS_VER}
55+
gz-sim${GZ_SIM_VER}::core
56+
gz-transport${GZ_TRANSPORT_VER}::gz-transport${GZ_TRANSPORT_VER}
57+
gz-utils${GZ_UTILS_VER}::gz-utils${GZ_UTILS_VER}
58+
Waves
59+
)
60+
endforeach()
61+
62+
install(
63+
TARGETS ${MARITIME_GZ_PLUGINS}
64+
DESTINATION lib)
65+
66+
#============================================================================
67+
# Resources
68+
install(DIRECTORY
69+
models
70+
worlds
71+
DESTINATION share/${PROJECT_NAME})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright (c) 2016 The UUV Simulator Authors.
2+
// All rights reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#version 330
17+
18+
////////// Input parameters //////////
19+
// Textures
20+
uniform sampler2D bumpMap;
21+
uniform samplerCube cubeMap;
22+
23+
// Colors
24+
uniform vec4 deepColor;
25+
uniform vec4 shallowColor;
26+
uniform float fresnelPower;
27+
uniform float hdrMultiplier;
28+
29+
////////// Input computed in vertex shader //////////
30+
in block
31+
{
32+
mat3 rotMatrix;
33+
vec3 eyeVec;
34+
vec2 bumpCoord;
35+
} inPs;
36+
37+
out vec4 fragColor;
38+
39+
void main()
40+
{
41+
// Apply bump mapping to normal vector to make waves look more detailed:
42+
vec4 bump = texture(bumpMap, inPs.bumpCoord)*2.0 - 1.0;
43+
vec3 N = normalize(inPs.rotMatrix * bump.xyz);
44+
45+
// Reflected ray:
46+
vec3 E = normalize(inPs.eyeVec);
47+
vec3 R = reflect(E, N);
48+
49+
// negate z for use with the skybox texture that comes with gz-rendering
50+
R = vec3(R.x, R.y, -R.z);
51+
52+
// uncomment this line if using other textures that are Y up
53+
// Gazebo requires rotated cube map lookup.
54+
// R = vec3(R.x, R.z, R.y);
55+
56+
// Get environment color of reflected ray:
57+
vec4 envColor = texture(cubeMap, R, 0.0);
58+
59+
// Cheap hdr effect:
60+
envColor.rgb *= (envColor.r+envColor.g+envColor.b)*hdrMultiplier;
61+
62+
// Compute refraction ratio (Fresnel):
63+
float facing = 1.0 - dot(-E, N);
64+
float waterEnvRatio = clamp(pow(facing, fresnelPower), 0.05, 1.0);
65+
66+
// Refracted ray only considers deep and shallow water colors:
67+
vec4 waterColor = mix(shallowColor, deepColor, facing);
68+
69+
// Perform linear interpolation between reflection and refraction.
70+
vec4 color = mix(waterColor, envColor, waterEnvRatio);
71+
72+
fragColor = vec4(color.xyz, 0.9);
73+
}

0 commit comments

Comments
 (0)