Skip to content

Commit b50e236

Browse files
authored
Custom SDF tags for surface properties (#164)
* custom SDF tags for surface properties Signed-off-by: Mabel Zhang <mabel@openrobotics.org> * unnecessary line Signed-off-by: Mabel Zhang <mabel@openrobotics.org> * more unnecessary lines Signed-off-by: Mabel Zhang <mabel@openrobotics.org> * add generation header comment Signed-off-by: Mabel Zhang <mabel@openrobotics.org> * fix style checks Signed-off-by: Mabel Zhang <mabel@openrobotics.org>
1 parent 289a8df commit b50e236

9 files changed

Lines changed: 223 additions & 29 deletions

File tree

gazebo/dave_gazebo_model_plugins/CMakeLists.txt

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ cmake_minimum_required(VERSION 3.0.2)
22
project(dave_gazebo_model_plugins)
33

44
if(NOT "${CMAKE_VERSION}" VERSION_LESS "3.16")
5-
set(CMAKE_CXX_STANDARD 17)
6-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
5+
set(CMAKE_CXX_STANDARD 17)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
77
else()
8-
add_compile_options(-std=c++11)
8+
add_compile_options(-std=c++11)
99
endif()
1010

1111
find_package(catkin REQUIRED COMPONENTS
@@ -30,7 +30,7 @@ add_message_files(
3030
generate_messages(
3131
DEPENDENCIES
3232
std_msgs
33-
)
33+
)
3434

3535
catkin_package(
3636
INCLUDE_DIRS
@@ -47,7 +47,6 @@ catkin_package(
4747
dave_gazebo_ros_plugins
4848
)
4949

50-
5150
include_directories(${PROJECT_SOURCE_DIR}/include
5251
${Boost_INCLUDE_DIR}
5352
${catkin_INCLUDE_DIRS}
@@ -64,18 +63,44 @@ link_directories(${catkin_LIBRARY_DIRS}
6463

6564
# ocean current model plugin
6665
add_library(dave_ocean_current_model_plugin
67-
SHARED
68-
src/ocean_current_model_plugin.cc
66+
SHARED
67+
src/ocean_current_model_plugin.cc
6968
)
7069
add_dependencies(dave_ocean_current_model_plugin
71-
${catkin_EXPORTED_TARGETS}
70+
${catkin_EXPORTED_TARGETS}
7271
)
7372
target_link_libraries(dave_ocean_current_model_plugin
74-
${catkin_LIBRARIES}
75-
${PROTOBUF_LIBRARY}
73+
${catkin_LIBRARIES}
74+
${PROTOBUF_LIBRARY}
7675
)
7776
list(APPEND DAVE_GAZEBO_MODEL_PLUGINS_LIST dave_ocean_current_model_plugin)
7877

78+
# Declare C++ libraries for USBL
79+
add_library(transponderPlugin
80+
SHARED
81+
src/usbl_transponder_plugin.cc
82+
)
83+
add_dependencies(transponderPlugin
84+
dave_gazebo_model_plugins_generate_messages_cpp
85+
)
86+
87+
add_library(transceiverPlugin
88+
SHARED
89+
src/usbl_transceiver_plugin.cc
90+
)
91+
add_dependencies(transceiverPlugin
92+
dave_gazebo_model_plugins_generate_messages_cpp
93+
)
94+
95+
# Custom surface properties
96+
add_library(custom_surface_properties
97+
SHARED
98+
src/custom_surface_properties.cc
99+
)
100+
target_link_libraries(custom_surface_properties
101+
${catkin_LIBRARIES}
102+
)
103+
79104
#add_library(plugin_name
80105
# SHARED
81106
# src/plugin_source_file1.cc
@@ -107,19 +132,12 @@ install(DIRECTORY include/${PROJECT_NAME}/
107132
)
108133

109134
install(DIRECTORY include/
110-
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}
111-
FILES_MATCHING PATTERN ".h"
135+
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}
136+
FILES_MATCHING PATTERN ".h"
112137
)
113138

114139
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/
115140
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
116141
FILES_MATCHING PATTERN "*.pb.*"
117142
PATTERN "*~" EXCLUDE
118143
)
119-
120-
## Declare a C++ libraries for USBL
121-
add_library(transponderPlugin SHARED src/usbl_transponder_plugin.cc)
122-
add_dependencies(transponderPlugin dave_gazebo_model_plugins_generate_messages_cpp)
123-
124-
add_library(transceiverPlugin SHARED src/usbl_transceiver_plugin)
125-
add_dependencies(transceiverPlugin dave_gazebo_model_plugins_generate_messages_cpp)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (C) 2021 Open Source Robotics Foundation
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+
*/
17+
18+
#ifndef CUSTOM_SURFACE_PROPERTIES_H_
19+
#define CUSTOM_SURFACE_PROPERTIES_H_
20+
21+
#include <functional>
22+
#include <string>
23+
#include <gazebo/gazebo.hh>
24+
#include <gazebo/physics/physics.hh>
25+
#include <gazebo/common/common.hh>
26+
27+
namespace gazebo
28+
{
29+
class CustomSurfaceProperties : public ModelPlugin
30+
{
31+
// Documentation inherited.
32+
public: void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf);
33+
34+
/// \brief Called by the world update start event
35+
public: void OnUpdate();
36+
37+
/// \brief Pointer to the model
38+
private: physics::ModelPtr model;
39+
40+
/// \brief Pointer to the update event connection
41+
private: event::ConnectionPtr updateConnection;
42+
43+
/// \brief Surface material
44+
private: std::string material = "";
45+
46+
/// \brief Surface roughness, [0.0, 1.0]
47+
private: double roughness = 0.0;
48+
49+
/// \brief Biofouling rating, [0, 100]
50+
private: int biofoulingRating = 0;
51+
};
52+
}
53+
54+
#endif // CUSTOM_SURFACE_PROPERTIES_H_

gazebo/dave_gazebo_model_plugins/include/dave_gazebo_model_plugins/ocean_current_model_plugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
/// \file TransientCurrentPlugin.hh
16+
/// \file ocean_current_model_plugin.h
1717
/// \brief Plugin for the transient current plugin to publish vehicle depth
1818

1919
#ifndef OCEAN_CURRENT_MODEL_PLUGIN_H_
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (C) 2021 Open Source Robotics Foundation
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+
*/
17+
18+
#include <dave_gazebo_model_plugins/custom_surface_properties.h>
19+
20+
#include <gazebo/physics/physics.hh>
21+
22+
namespace gazebo
23+
{
24+
/////////////////////////////////////////////////
25+
void CustomSurfaceProperties::Load(physics::ModelPtr _parent,
26+
sdf::ElementPtr _sdf)
27+
{
28+
// Store the pointer to the model
29+
this->model = _parent;
30+
31+
// Listen to the update event. This event is broadcast every
32+
// simulation iteration.
33+
this->updateConnection = event::Events::ConnectWorldUpdateBegin(
34+
std::bind(&CustomSurfaceProperties::OnUpdate, this));
35+
36+
// Read custom tags for surface properties
37+
sdf::ElementPtr modelElt = _sdf->GetParent();
38+
this->material = modelElt->Get<std::string>("surface_props:material");
39+
40+
this->biofoulingRating = modelElt->Get<int>(
41+
"surface_props:biofouling_rating");
42+
43+
this->roughness = modelElt->Get<double>("surface_props:roughness");
44+
45+
gzdbg << "Read custom SDF tags: material " << this->material
46+
<< ", biofouling rating " << this->biofoulingRating
47+
<< ", roughness " << this->roughness << std::endl;
48+
}
49+
50+
/////////////////////////////////////////////////
51+
void CustomSurfaceProperties::OnUpdate()
52+
{
53+
}
54+
55+
// Register this plugin with the simulator
56+
GZ_REGISTER_MODEL_PLUGIN(CustomSurfaceProperties)
57+
}

gazebo/dave_gazebo_model_plugins/src/ocean_current_model_plugin.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
/// \file ocean_current.cc
16+
/// \file ocean_current_model_plugin.cc
1717

1818
#include <dave_gazebo_model_plugins/ocean_current_model_plugin.h>
1919

models/dave_worlds/worlds/distorted_coke.world

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?xml version="1.0"?>
2-
<sdf version="1.6">
2+
3+
<!-- This file is generated from ERB template coke_template.erb -->
4+
<sdf version="1.6" xmlns:surface_props="https://github.com/Field-Robotics-Lab/dave">
35
<world name="coke">
4-
<!-- Example of how fouling_rating can be used to vary coefficients -->
6+
57

68
<model name="coke_1">
79
<!-- To get model to show up in empty world without ground plane -->
@@ -64,6 +66,13 @@
6466
</geometry>
6567
</visual>
6668
</link>
69+
70+
<!-- Custom SDF elements for surface properties -->
71+
<surface_props:material>metal</surface_props:material>
72+
<surface_props:biofouling_rating>10</surface_props:biofouling_rating>
73+
<surface_props:roughness>0.1</surface_props:roughness>
74+
<plugin name="custom_surface_properties"
75+
filename="libcustom_surface_properties.so"/>
6776
</model>
6877

6978
</world>

urdf/scripts/sdf_custom_properties/README.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ objects.
1919

2020
## Dependencies
2121

22-
[Ruby](https://www.ruby-lang.org) is required:
22+
[Ruby](https://www.ruby-lang.org) is required for generating SDF files from
23+
ERB templates:
2324
```
2425
sudo apt-get install -y ruby
2526
```
@@ -44,9 +45,39 @@ ROS, you may want to export the file elsewhere, such as
4445
erb coke_template.erb > ../../../models/dave_worlds/worlds/distorted_coke.world
4546
```
4647

48+
## Custom SDF elements for surface properties
49+
50+
[An introductory tutorial](http://sdformat.org/tutorials?tut=custom_elements_attributes_proposal&cat=pose_semantics_docs&)
51+
on custom SDF elements and attributes can be found on the sdformat website.
52+
53+
### Schema
54+
55+
Currently, these custom properties are defined:
56+
57+
- `<surface_props:material>`: `string`
58+
- `<surface_props:biofouling_rating>`: `int`, in range `[0, 100]`, defined by
59+
the Navy biofouling scale.
60+
- `<surface_props:roughness>`: `double`, in range `[0.0, 1.0]`
61+
62+
Example SDF snippet:
63+
```
64+
<surface_props:material>metal</surface_props:material>
65+
<surface_props:biofouling_rating>30</surface_props:biofouling_rating>
66+
<surface_props:roughness>0.3</surface_props:roughness>
67+
```
68+
69+
### Custom Gazebo plugin
70+
71+
The custom SDF tags are handled by a custom Gazebo plugin that reads the SDF
72+
file.
73+
An example plugin (`custom_surface_properties`) is provided, which reads the
74+
custom SDF tags.
75+
76+
This plugin is loaded in the SDF file.
77+
4778
## Load the SDF in Gazebo
4879

49-
An example launch file is provided, which loads the SDF world:
80+
An example launch file is provided, which loads the SDF world generated above:
5081
```
5182
roslaunch dave_demo_launch distorted_coke.launch
5283
```
@@ -59,3 +90,10 @@ In Gazebo 11, regardless of the physics engine, parameters in the `<ode>` tag
5990
are used for most engines.
6091
This is an implementation detail.
6192
More documentation upstream is required, as ticketed in [this issue](https://github.com/ignitionrobotics/sdformat/issues/31).
93+
94+
## Future work
95+
96+
- Write a regression test to diff between the ERB generated file and the
97+
reference SDF file in the repo.
98+
- Flesh out the set of friction parameters that the biofouling rating should
99+
affect

urdf/scripts/sdf_custom_properties/coke.ref.sdf

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?xml version="1.0"?>
2-
<sdf version="1.6">
2+
3+
<!-- This file is generated from ERB template coke_template.erb -->
4+
<sdf version="1.6" xmlns:surface_props="https://github.com/Field-Robotics-Lab/dave">
35
<world name="coke">
4-
<!-- Example of how fouling_rating can be used to vary coefficients -->
6+
57

68
<model name="coke_1">
79
<!-- To get model to show up in empty world without ground plane -->
@@ -64,6 +66,13 @@
6466
</geometry>
6567
</visual>
6668
</link>
69+
70+
<!-- Custom SDF elements for surface properties -->
71+
<surface_props:material>metal</surface_props:material>
72+
<surface_props:biofouling_rating>10</surface_props:biofouling_rating>
73+
<surface_props:roughness>0.1</surface_props:roughness>
74+
<plugin name="custom_surface_properties"
75+
filename="libcustom_surface_properties.so"/>
6776
</model>
6877

6978
</world>

urdf/scripts/sdf_custom_properties/coke_template.erb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?xml version="1.0"?>
2-
<sdf version="1.6">
2+
<%# Header for files generated from this file %>
3+
<!-- This file is generated from ERB template coke_template.erb -->
4+
<sdf version="1.6" xmlns:surface_props="https://github.com/Field-Robotics-Lab/dave">
35
<world name="coke">
4-
<!-- Example of how fouling_rating can be used to vary coefficients -->
6+
<%# Example of how fouling_rating can be used to vary coefficients %>
57
<%
68
fouling_rating = 10
79
mu_factor = 0.001
@@ -70,6 +72,13 @@
7072
</geometry>
7173
</visual>
7274
</link>
75+
76+
<!-- Custom SDF elements for surface properties -->
77+
<surface_props:material>metal</surface_props:material>
78+
<surface_props:biofouling_rating><%= fouling_rating %></surface_props:biofouling_rating>
79+
<surface_props:roughness><%= fouling_rating * 0.01 %></surface_props:roughness>
80+
<plugin name="custom_surface_properties"
81+
filename="libcustom_surface_properties.so"/>
7382
</model>
7483
<%
7584
end

0 commit comments

Comments
 (0)