Skip to content

Commit

Permalink
Galactic: Support Citadel, Edifice and Fortress (#8)
Browse files Browse the repository at this point in the history
* CI for Focal and Jammy (#10)

* CI for Focal and Jammy

Signed-off-by: Shane Loretz <sloretz@openrobotics.org>

* Only run on pull_request updates

Signed-off-by: Shane Loretz <sloretz@openrobotics.org>

* Focal;Galactic;Citadel,Edifice,Fortress

Signed-off-by: Shane Loretz <sloretz@openrobotics.org>

* Galactic: Support Citadel, Edifice and Fortress

Signed-off-by: Louise Poubel <louise@openrobotics.org>

* Remove custom action

Signed-off-by: Louise Poubel <louise@openrobotics.org>

* cascading logic

Signed-off-by: Louise Poubel <louise@openrobotics.org>

* gazebo -> gz

Signed-off-by: Louise Poubel <louise@openrobotics.org>

* oops

Signed-off-by: Louise Poubel <louise@openrobotics.org>

* Reorder things

Signed-off-by: Louise Poubel <louise@openrobotics.org>

* Fix tests with Edifice

Signed-off-by: Louise Poubel <louise@openrobotics.org>

* no gz-utils for SDF 9

Signed-off-by: Louise Poubel <louise@openrobotics.org>

* uncrustify

Signed-off-by: Louise Poubel <louise@openrobotics.org>

* Apply suggestions from code review

Signed-off-by: Louise Poubel <louise@openrobotics.org>

Co-authored-by: Shane Loretz <shane.loretz@gmail.com>

* Citadel

Signed-off-by: Louise Poubel <louise@openrobotics.org>

Co-authored-by: Shane Loretz <sloretz@osrfoundation.org>
Co-authored-by: Shane Loretz <sloretz@openrobotics.org>
Co-authored-by: Shane Loretz <shane.loretz@gmail.com>
  • Loading branch information
4 people authored Jun 8, 2022
1 parent 28565be commit cc26b1f
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 11 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,22 @@ See the [README in the `sdformat_urdf` package](./sdformat_urdf/README.md) for m
* provides a library and a `urdf_parser_plugin` using that library to convert SDFormat XML to URDF C++ DOM structures
* [`sdformat_test_files`](./sdformat_test_files/README.md)
* provides SDFormat models using different parts of the SDFormat XML specification for testing

## Version combinations

This package can be compiled against versions of libSDFormat.

Set the `GZ_VERSION` environment variable to match the libSDFormat version you'd like to compile against.
For example:

export GZ_VERSION=fortress

> You only need to set this variable when compiling, not when running.
ROS version | Gazebo version | libSDFormat version | Branch | Binaries hosted at
-- | -- | -- | -- | --
Galactic | Citadel | 9.x | [galactic](https://github.com/ros/ros_ign/tree/galactic) | https://packages.ros.org
Galactic | Edifice | 11.x | [galactic](https://github.com/ros/ros_ign/tree/galactic) | only from source
Galactic | Fortress | 12.x | [galactic](https://github.com/ros/ros_ign/tree/galactic) | only from source
Humble | Fortress | 12.x | [ros2](https://github.com/ros/ros_ign/tree/ros2) | https://packages.ros.org
Rolling | Fortress | 12.x | [ros2](https://github.com/ros/ros_ign/tree/ros2) | https://packages.ros.org
48 changes: 45 additions & 3 deletions sdformat_urdf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,60 @@ find_package(ament_cmake_ros REQUIRED)

find_package(pluginlib REQUIRED)
find_package(rcutils REQUIRED)
find_package(sdformat9 REQUIRED)
find_package(urdfdom_headers REQUIRED)
find_package(urdf_parser_plugin REQUIRED)
find_package(tinyxml2_vendor REQUIRED)
find_package(TinyXML2 REQUIRED)

# Choose SDF version

# Default to Citadel
set(SDF_VER 9)

# If the user didn't specify a GZ distribution, pick the one matching the ROS distribution according to REP 2000
if(NOT DEFINED ENV{GZ_VERSION} AND DEFINED ENV{ROS_DISTRO})
if("$ENV{ROS_DISTRO}" STREQUAL "foxy")
set(ENV{GZ_VERSION} "citadel")
elseif("$ENV{ROS_DISTRO}" STREQUAL "galactic")
# Using Citadel for backwards compatibility - per REP-2000 Galactic should be paired with Edifice
set(ENV{GZ_VERSION} "citadel")
elseif("$ENV{ROS_DISTRO}" STREQUAL "humble")
set(ENV{GZ_VERSION} "fortress")
endif()
endif()

# Find libsdformat matching the picked GZ distribution
if("$ENV{GZ_VERSION}" STREQUAL "citadel")
find_package(sdformat9 REQUIRED)
set(SDF_VER ${sdformat9_VERSION_MAJOR})
message(STATUS "Compiling against Gazebo Citadel (libSDFormat 9)")
elseif("$ENV{GZ_VERSION}" STREQUAL "edifice")
find_package(sdformat11 REQUIRED)
set(SDF_VER ${sdformat11_VERSION_MAJOR})
message(STATUS "Compiling against Gazebo Edifice (libSDFormat 11)")
elseif("$ENV{GZ_VERSION}" STREQUAL "fortress")
find_package(sdformat12 REQUIRED)
set(SDF_VER ${sdformat12_VERSION_MAJOR})
message(STATUS "Compiling against Gazebo Fortress (libSDFormat 12)")
# No GZ distribution specified, find any version of libsdformat we can
else()
foreach(major RANGE 13 9)
find_package(sdformat${major} QUIET)
if(sdformat${major}_FOUND)
# Next `find_package` call will be a noop
set(SDF_VER ${major})
message(STATUS "Compiling against libSDFormat ${major}")
break()
endif()
endforeach()
endif()

# Add sdformat_urdf shared library
add_library(sdformat_urdf SHARED
src/sdformat_urdf.cpp
)
target_link_libraries(sdformat_urdf PUBLIC
sdformat9::sdformat9
sdformat${SDF_VER}::sdformat${SDF_VER}
)
target_link_libraries(sdformat_urdf PRIVATE
rcutils::rcutils
Expand All @@ -50,7 +92,7 @@ target_link_libraries(sdformat_urdf_plugin PRIVATE
)

ament_export_dependencies(urdfdom_headers)
ament_export_dependencies(sdformat9)
ament_export_dependencies(sdformat${SDF_VER})

install(TARGETS sdformat_urdf EXPORT sdformat_urdf-export
ARCHIVE DESTINATION lib
Expand Down
19 changes: 17 additions & 2 deletions sdformat_urdf/package.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<package format="2">
<package format="3">
<name>sdformat_urdf</name>
<version>0.1.0</version>
<description>
Expand All @@ -17,7 +17,22 @@
<buildtool_depend>ament_cmake_ros</buildtool_depend>
<buildtool_export_depend>ament_cmake_ros</buildtool_export_depend>

<depend>sdformat</depend>
<!-- Edifice - should have been the default with Galactic per REP-2000 -->
<depend condition="$GZ_VERSION == edifice">sdformat11</depend>

<!-- Fortress -->
<depend condition="$ROS_DISTRO == 'humble'">sdformat12</depend>
<depend condition="$ROS_DISTRO == 'rolling'">sdformat12</depend>
<depend condition="$GZ_VERSION == fortress">sdformat12</depend>

<!--
For backwards compatibility, default to version 9, which comes with
the unversioned `sdformat` key on Focal. That's Gazebo Citadel.
-->
<depend condition="$ROS_DISTRO == 'galactic'">sdformat</depend>
<depend condition="$GZ_VERSION == 'citadel'">sdformat</depend>
<depend condition="$GZ_VERSION == ''">sdformat</depend>

<depend>urdf</depend>

<build_depend>liburdfdom-headers-dev</build_depend>
Expand Down
23 changes: 22 additions & 1 deletion sdformat_urdf/src/sdformat_urdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// limitations under the License.

#include <ignition/math/Pose3.hh>
#if SDF_MAJOR_VERSION >= 11
#include <ignition/utils/SuppressWarning.hh>
#endif
#include <rcutils/logging_macros.h>
#include <sdf/sdf.hh>
#include <urdf_world/types.h>
Expand Down Expand Up @@ -66,6 +69,13 @@ sdformat_urdf::sdf_to_urdf(const sdf::Root & sdf_dom, sdf::Errors & errors)
"SDFormat xml has a world; but only a single model is supported");
return nullptr;
}
// Multiple models per root is deprecated on SDF 11 and removed on 12.
// To keep test expectations consistent across all versions, we use
// the deprecated APIs for 11.
#if SDF_MAJOR_VERSION <= 11
#if SDF_MAJOR_VERSION >= 11
IGN_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION
#endif
if (0u == sdf_dom.ModelCount()) {
errors.emplace_back(
sdf::ErrorCode::STRING_READ,
Expand All @@ -78,8 +88,19 @@ sdformat_urdf::sdf_to_urdf(const sdf::Root & sdf_dom, sdf::Errors & errors)
"SDFormat xml has multiple models; but only a single model is supported");
return nullptr;
}

return convert_model(*sdf_dom.ModelByIndex(0), errors);
#if SDF_MAJOR_VERSION >= 11
IGN_UTILS_WARN_RESUME__DEPRECATED_DECLARATION
#endif
#else
if (nullptr == sdf_dom.Model()) {
errors.emplace_back(
sdf::ErrorCode::ELEMENT_MISSING,
"SDFormat xml has no models; need at least one");
return nullptr;
}
return convert_model(*sdf_dom.Model(), errors);
#endif
}

urdf::ModelInterfaceSharedPtr
Expand Down
2 changes: 1 addition & 1 deletion sdformat_urdf/test/graph_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


#include <gtest/gtest.h>
#include <sdf/sdf.hh>
#include <sdf/Types.hh>
#include <sdformat_urdf/sdformat_urdf.hpp>
#include <urdf_model/model.h>
#include <urdf_model/types.h>
Expand Down
3 changes: 3 additions & 0 deletions sdformat_urdf/test/include/test_tools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ get_file(const char * path)
} \
} while (false)


#if SDF_MAJOR_VERSION < 11
std::ostream & operator<<(std::ostream & os, const sdf::Errors & errors)
{
for (const auto & error : errors) {
os << error;
}
return os;
}
#endif

#endif // TEST_TOOLS_HPP_
19 changes: 18 additions & 1 deletion sdformat_urdf/test/joint_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@


#include <gtest/gtest.h>
#include <sdf/sdf.hh>
#include <sdf/Types.hh>
#include <sdformat_urdf/sdformat_urdf.hpp>
#include <urdf_model/model.h>
#include <urdf_model/types.h>

#include <limits>

#include "sdf_paths.hpp"
#include "test_tools.hpp"

Expand Down Expand Up @@ -112,8 +114,13 @@ TEST(Joint, joint_prismatic)
ASSERT_NE(nullptr, joint->limits);
EXPECT_DOUBLE_EQ(-0.2, joint->limits->lower);
EXPECT_DOUBLE_EQ(0.2, joint->limits->upper);
#if SDF_MAJOR_VERSION < 11
EXPECT_DOUBLE_EQ(-1, joint->limits->effort); // SDFormat default
EXPECT_DOUBLE_EQ(-1, joint->limits->velocity); // SDFormat default
#else
EXPECT_DOUBLE_EQ(std::numeric_limits<double>::infinity(), joint->limits->effort);
EXPECT_DOUBLE_EQ(std::numeric_limits<double>::infinity(), joint->limits->velocity);
#endif
ASSERT_EQ(nullptr, joint->safety);
ASSERT_EQ(nullptr, joint->calibration);
ASSERT_EQ(nullptr, joint->mimic);
Expand All @@ -139,8 +146,13 @@ TEST(Joint, joint_revolute)
ASSERT_NE(nullptr, joint->limits);
EXPECT_DOUBLE_EQ(-1.5, joint->limits->lower);
EXPECT_DOUBLE_EQ(1.5, joint->limits->upper);
#if SDF_MAJOR_VERSION < 11
EXPECT_DOUBLE_EQ(-1, joint->limits->effort); // SDFormat default
EXPECT_DOUBLE_EQ(-1, joint->limits->velocity); // SDFormat default
#else
EXPECT_DOUBLE_EQ(std::numeric_limits<double>::infinity(), joint->limits->effort);
EXPECT_DOUBLE_EQ(std::numeric_limits<double>::infinity(), joint->limits->velocity);
#endif
ASSERT_EQ(nullptr, joint->safety);
ASSERT_EQ(nullptr, joint->calibration);
ASSERT_EQ(nullptr, joint->mimic);
Expand Down Expand Up @@ -224,8 +236,13 @@ TEST(Joint, joint_revolute_default_limits)
ASSERT_NE(nullptr, joint->limits);
EXPECT_DOUBLE_EQ(-1e16, joint->limits->lower); // SDFormat default
EXPECT_DOUBLE_EQ(1e16, joint->limits->upper); // SDFormat default
#if SDF_MAJOR_VERSION < 11
EXPECT_DOUBLE_EQ(-1, joint->limits->effort); // SDFormat default
EXPECT_DOUBLE_EQ(-1, joint->limits->velocity); // SDFormat default
#else
EXPECT_DOUBLE_EQ(std::numeric_limits<double>::infinity(), joint->limits->effort);
EXPECT_DOUBLE_EQ(std::numeric_limits<double>::infinity(), joint->limits->velocity);
#endif
}

TEST(Joint, joint_revolute_two_joints_two_links)
Expand Down
2 changes: 1 addition & 1 deletion sdformat_urdf/test/link_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


#include <gtest/gtest.h>
#include <sdf/sdf.hh>
#include <sdf/Types.hh>
#include <sdformat_urdf/sdformat_urdf.hpp>
#include <urdf_model/model.h>
#include <urdf_model/types.h>
Expand Down
2 changes: 1 addition & 1 deletion sdformat_urdf/test/material_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


#include <gtest/gtest.h>
#include <sdf/sdf.hh>
#include <sdf/Types.hh>
#include <sdformat_urdf/sdformat_urdf.hpp>
#include <urdf_model/model.h>
#include <urdf_model/types.h>
Expand Down
2 changes: 1 addition & 1 deletion sdformat_urdf/test/pose_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include <gtest/gtest.h>
#include <ignition/math/Pose3.hh>
#include <sdf/sdf.hh>
#include <sdf/Types.hh>
#include <sdformat_urdf/sdformat_urdf.hpp>
#include <urdf_model/model.h>
#include <urdf_model/types.h>
Expand Down

0 comments on commit cc26b1f

Please sign in to comment.