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.gazebo-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 }}

17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,20 @@ 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.
chapulina marked this conversation as resolved.
Show resolved Hide resolved

Set the `GAZEBO_VERSION` environment variable to the Gazebo version you'd
like to compile against. For example:

export GAZEBO_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
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)

# First try GZ_VERSION

# Edifice
if("$ENV{GZ_VERSION}" STREQUAL "edifice")
find_package(sdformat11 REQUIRED)
set(SDF_VER ${sdformat11_VERSION_MAJOR})

message(STATUS "Compiling against Gazebo Edifice (SDF 11), requested with GZ_VERSION")
# Fortress
elseif("$ENV{GZ_VERSION}" STREQUAL "fortress")
find_package(sdformat12 REQUIRED)
set(SDF_VER ${sdformat12_VERSION_MAJOR})

message(STATUS "Compiling against Gazebo Fortress (SDF 12), requested with GZ_VERSION")
elseif("$ENV{GZ_VERSION}" STREQUAL "citadel")
find_package(sdformat9 REQUIRED)
set(SDF_VER ${sdformat9_VERSION_MAJOR})

message(STATUS "Compiling against Gazebo Citadel (SDF 9), requested with GZ_VERSION")
endif()
# Then try ROS_DISTRO
elseif("$ENV{ROS_DISTRO}" STREQUAL "galactic")
chapulina marked this conversation as resolved.
Show resolved Hide resolved
find_package(sdformat11 REQUIRED)
set(SDF_VER ${sdformat11_VERSION_MAJOR})

message(STATUS "Compiling against Gazebo Edifice (SDF 11), requested with ROS_DISTRO")
# Then try any version available, looking from higher to lower
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})
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
16 changes: 14 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,19 @@
<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="$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="$GZ_VERSION == 'citadel'">sdformat</depend>
<depend condition="$GZ_VERSION == ''">sdformat</depend>

<depend>urdf</depend>

<build_depend>liburdfdom-headers-dev</build_depend>
Expand Down
11 changes: 10 additions & 1 deletion sdformat_urdf/src/sdformat_urdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ 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;
}
#if SDF_MAJOR_VERSION < 11
if (0u == sdf_dom.ModelCount()) {
errors.emplace_back(
sdf::ErrorCode::STRING_READ,
Expand All @@ -78,8 +79,16 @@ 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);
#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