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

Galactic: Support Citadel, Edifice and Fortress #8

Merged
merged 13 commits into from
Jun 8, 2022
Merged
24 changes: 24 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: gh-ci
on:
pull_request
jobs:
test_sdformat_urdf:
runs-on: ubuntu-20.04
strategy:
matrix:
ros-distro: ["galactic"]
gz-version:
- "citadel" # libsdformat9
- "edifice" # libsdformat11
- "fortress" # libsdformat12
env:
GZ_VERSION: ${{ matrix.gz-version }}
steps:
- uses: ros-tooling/setup-ros@v0.3
with:
required-ros-distributions: ${{ matrix.ros-distro }}
- name: Build and test all packages
uses: ros-tooling/action-ros-ci@v0.2
with:
target-ros2-distro: ${{ matrix.ros-distro }}

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 different Gazebo versions.

Set the `GZ_VERSION` environment variable to the Gazebo 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 | Branch | Binaries hosted at
-- | -- | -- | --
Galactic | Citadel | [galactic](https://github.com/ros/ros_ign/tree/galactic) | https://packages.ros.org
Galactic | Edifice | [galactic](https://github.com/ros/ros_ign/tree/galactic) | only from source
Galactic | Fortress | [galactic](https://github.com/ros/ros_ign/tree/galactic) | only from source
Humble | Fortress | [ros2](https://github.com/ros/ros_ign/tree/ros2) | https://packages.ros.org
Rolling | Fortress | [ros2](https://github.com/ros/ros_ign/tree/ros2) | https://packages.ros.org
47 changes: 44 additions & 3 deletions sdformat_urdf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,59 @@ 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")
set(ENV{GZ_VERSION} "edifice")
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 +91,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