From 230eea3683476b9ce9405a2daa93e9999fcf7a17 Mon Sep 17 00:00:00 2001 From: Shane Loretz Date: Fri, 3 Jun 2022 16:08:54 -0700 Subject: [PATCH 01/13] CI for Focal and Jammy (#10) * CI for Focal and Jammy Signed-off-by: Shane Loretz * Only run on pull_request updates Signed-off-by: Shane Loretz --- .github/workflows/ci.yaml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000..1eec8c8c --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,22 @@ +name: gh-ci +on: + pull_request +jobs: + test_sdformat_urdf: + runs-on: ubuntu-22.04 + strategy: + matrix: + ros-distro: ["humble", "rolling"] + gazebo-version: + - "fortress" # libsdformat12 + env: + GAZEBO_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 }} + From a268207acc2799fc1e8edd1a56b6631d999e0891 Mon Sep 17 00:00:00 2001 From: Shane Loretz Date: Fri, 3 Jun 2022 16:13:40 -0700 Subject: [PATCH 02/13] Focal;Galactic;Citadel,Edifice,Fortress Signed-off-by: Shane Loretz --- .github/workflows/ci.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1eec8c8c..0055e8eb 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -3,11 +3,13 @@ on: pull_request jobs: test_sdformat_urdf: - runs-on: ubuntu-22.04 + runs-on: ubuntu-20.04 strategy: matrix: - ros-distro: ["humble", "rolling"] + ros-distro: ["galactic"] gazebo-version: + - "citadel" # libsdformat9 + - "edifice" # libsdformat11 - "fortress" # libsdformat12 env: GAZEBO_VERSION: ${{ matrix.gazebo-version }} From 34c08d141c20041f9aa9f54aa442e743111199d4 Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Thu, 2 Jun 2022 17:07:33 -0700 Subject: [PATCH 03/13] Galactic: Support Citadel, Edifice and Fortress Signed-off-by: Louise Poubel --- .github/workflows/build-and-test.sh | 35 +++++++++++++++++++++++ .github/workflows/ci.yml | 31 ++++++++++++++++++++ README.md | 17 +++++++++++ sdformat_urdf/CMakeLists.txt | 25 ++++++++++++++-- sdformat_urdf/package.xml | 16 +++++++++-- sdformat_urdf/src/sdformat_urdf.cpp | 11 ++++++- sdformat_urdf/test/graph_tests.cpp | 2 +- sdformat_urdf/test/include/test_tools.hpp | 3 ++ sdformat_urdf/test/joint_tests.cpp | 19 +++++++++++- sdformat_urdf/test/link_tests.cpp | 2 +- sdformat_urdf/test/material_tests.cpp | 2 +- sdformat_urdf/test/pose_tests.cpp | 2 +- 12 files changed, 154 insertions(+), 11 deletions(-) create mode 100755 .github/workflows/build-and-test.sh create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/build-and-test.sh b/.github/workflows/build-and-test.sh new file mode 100755 index 00000000..3cf38778 --- /dev/null +++ b/.github/workflows/build-and-test.sh @@ -0,0 +1,35 @@ +#!/bin/bash +set -ev + +# Configuration. +export COLCON_WS=~/ws +export COLCON_WS_SRC=${COLCON_WS}/src +export DEBIAN_FRONTEND=noninteractive +export ROS_PYTHON_VERSION=3 + +apt update -qq +apt install -qq -y lsb-release wget curl build-essential + +# Citadel, Edifice and Fortress get come with rosdep for Focal + +# Dependencies. +echo "deb http://packages.ros.org/ros2/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list +curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add - +apt-get update -qq +apt-get install -y python3-colcon-common-extensions \ + python3-rosdep + +rosdep init +rosdep update +rosdep install --from-paths ./ -i -y --rosdistro $ROS_DISTRO + +# Build. +source /opt/ros/$ROS_DISTRO/setup.bash +mkdir -p $COLCON_WS_SRC +cp -r $GITHUB_WORKSPACE $COLCON_WS_SRC +cd $COLCON_WS +colcon build --event-handlers console_direct+ + +# Tests. +colcon test --event-handlers console_direct+ +colcon test-result diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..b22bc219 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,31 @@ +name: Build and test + +on: [push, pull_request] + +jobs: + ci: + name: CI + runs-on: ubuntu-latest + strategy: + matrix: + include: + - docker-image: "ubuntu:20.04" + gazebo-version: "citadel" + ros-distro: "galactic" + - docker-image: "ubuntu:20.04" + gazebo-version: "edifice" + ros-distro: "galactic" + - docker-image: "ubuntu:20.04" + gazebo-version: "fortress" + ros-distro: "galactic" + container: + image: ${{ matrix.docker-image }} + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Build and Test + run: .github/workflows/build-and-test.sh + env: + DOCKER_IMAGE: ${{ matrix.docker-image }} + GAZEBO_VERSION: ${{ matrix.gazebo-version }} + ROS_DISTRO: ${{ matrix.ros-distro }} diff --git a/README.md b/README.md index 0545d705..73be2871 100644 --- a/README.md +++ b/README.md @@ -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. + +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 diff --git a/sdformat_urdf/CMakeLists.txt b/sdformat_urdf/CMakeLists.txt index 23f11ab7..03854284 100644 --- a/sdformat_urdf/CMakeLists.txt +++ b/sdformat_urdf/CMakeLists.txt @@ -14,18 +14,37 @@ 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) +# Edifice +if("$ENV{GAZEBO_VERSION}" STREQUAL "edifice") + find_package(sdformat11 REQUIRED) + set(SDF_VER ${sdformat11_VERSION_MAJOR}) + + message(STATUS "Compiling against Gazebo Edifice") +# Fortress +elseif("$ENV{GAZEBO_VERSION}" STREQUAL "fortress") + find_package(sdformat12 REQUIRED) + set(SDF_VER ${sdformat12_VERSION_MAJOR}) + + message(STATUS "Compiling against Gazebo Fortress") +# Default to libSDFormat 9 for backwards compatibility +else() + find_package(sdformat9 REQUIRED) + set(SDF_VER ${sdformat9_VERSION_MAJOR}) + + message(STATUS "Compiling against Gazebo Citadel") +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 @@ -50,7 +69,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 diff --git a/sdformat_urdf/package.xml b/sdformat_urdf/package.xml index 992fe92d..bf965653 100644 --- a/sdformat_urdf/package.xml +++ b/sdformat_urdf/package.xml @@ -1,5 +1,5 @@ - + sdformat_urdf 0.1.0 @@ -17,7 +17,19 @@ ament_cmake_ros ament_cmake_ros - sdformat + + sdformat11 + + + sdformat12 + + + sdformat + sdformat + urdf liburdfdom-headers-dev diff --git a/sdformat_urdf/src/sdformat_urdf.cpp b/sdformat_urdf/src/sdformat_urdf.cpp index 3dd95aa5..b1491921 100644 --- a/sdformat_urdf/src/sdformat_urdf.cpp +++ b/sdformat_urdf/src/sdformat_urdf.cpp @@ -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, @@ -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 diff --git a/sdformat_urdf/test/graph_tests.cpp b/sdformat_urdf/test/graph_tests.cpp index 23d8b319..7807db80 100644 --- a/sdformat_urdf/test/graph_tests.cpp +++ b/sdformat_urdf/test/graph_tests.cpp @@ -14,7 +14,7 @@ #include -#include +#include #include #include #include diff --git a/sdformat_urdf/test/include/test_tools.hpp b/sdformat_urdf/test/include/test_tools.hpp index ef3459b1..13ac7207 100644 --- a/sdformat_urdf/test/include/test_tools.hpp +++ b/sdformat_urdf/test/include/test_tools.hpp @@ -81,6 +81,8 @@ 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) { @@ -88,5 +90,6 @@ std::ostream & operator<<(std::ostream & os, const sdf::Errors & errors) } return os; } +#endif #endif // TEST_TOOLS_HPP_ diff --git a/sdformat_urdf/test/joint_tests.cpp b/sdformat_urdf/test/joint_tests.cpp index d38c622e..98d9b9f8 100644 --- a/sdformat_urdf/test/joint_tests.cpp +++ b/sdformat_urdf/test/joint_tests.cpp @@ -14,11 +14,13 @@ #include -#include +#include #include #include #include +#include + #include "sdf_paths.hpp" #include "test_tools.hpp" @@ -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::infinity(), joint->limits->effort); + EXPECT_DOUBLE_EQ(std::numeric_limits::infinity(), joint->limits->velocity); +#endif ASSERT_EQ(nullptr, joint->safety); ASSERT_EQ(nullptr, joint->calibration); ASSERT_EQ(nullptr, joint->mimic); @@ -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::infinity(), joint->limits->effort); + EXPECT_DOUBLE_EQ(std::numeric_limits::infinity(), joint->limits->velocity); +#endif ASSERT_EQ(nullptr, joint->safety); ASSERT_EQ(nullptr, joint->calibration); ASSERT_EQ(nullptr, joint->mimic); @@ -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::infinity(), joint->limits->effort); + EXPECT_DOUBLE_EQ(std::numeric_limits::infinity(), joint->limits->velocity); +#endif } TEST(Joint, joint_revolute_two_joints_two_links) diff --git a/sdformat_urdf/test/link_tests.cpp b/sdformat_urdf/test/link_tests.cpp index d186a0de..b00ba8a9 100644 --- a/sdformat_urdf/test/link_tests.cpp +++ b/sdformat_urdf/test/link_tests.cpp @@ -14,7 +14,7 @@ #include -#include +#include #include #include #include diff --git a/sdformat_urdf/test/material_tests.cpp b/sdformat_urdf/test/material_tests.cpp index 02a129f3..0c8cda81 100644 --- a/sdformat_urdf/test/material_tests.cpp +++ b/sdformat_urdf/test/material_tests.cpp @@ -14,7 +14,7 @@ #include -#include +#include #include #include #include diff --git a/sdformat_urdf/test/pose_tests.cpp b/sdformat_urdf/test/pose_tests.cpp index 0f423a01..4ef34673 100644 --- a/sdformat_urdf/test/pose_tests.cpp +++ b/sdformat_urdf/test/pose_tests.cpp @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include #include From 037f6bad5d755e9f568c859625cc33bb4c28194b Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Fri, 3 Jun 2022 16:31:48 -0700 Subject: [PATCH 04/13] Remove custom action Signed-off-by: Louise Poubel --- .github/workflows/build-and-test.sh | 35 ----------------------------- .github/workflows/ci.yml | 31 ------------------------- 2 files changed, 66 deletions(-) delete mode 100755 .github/workflows/build-and-test.sh delete mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/build-and-test.sh b/.github/workflows/build-and-test.sh deleted file mode 100755 index 3cf38778..00000000 --- a/.github/workflows/build-and-test.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -set -ev - -# Configuration. -export COLCON_WS=~/ws -export COLCON_WS_SRC=${COLCON_WS}/src -export DEBIAN_FRONTEND=noninteractive -export ROS_PYTHON_VERSION=3 - -apt update -qq -apt install -qq -y lsb-release wget curl build-essential - -# Citadel, Edifice and Fortress get come with rosdep for Focal - -# Dependencies. -echo "deb http://packages.ros.org/ros2/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list -curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add - -apt-get update -qq -apt-get install -y python3-colcon-common-extensions \ - python3-rosdep - -rosdep init -rosdep update -rosdep install --from-paths ./ -i -y --rosdistro $ROS_DISTRO - -# Build. -source /opt/ros/$ROS_DISTRO/setup.bash -mkdir -p $COLCON_WS_SRC -cp -r $GITHUB_WORKSPACE $COLCON_WS_SRC -cd $COLCON_WS -colcon build --event-handlers console_direct+ - -# Tests. -colcon test --event-handlers console_direct+ -colcon test-result diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index b22bc219..00000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Build and test - -on: [push, pull_request] - -jobs: - ci: - name: CI - runs-on: ubuntu-latest - strategy: - matrix: - include: - - docker-image: "ubuntu:20.04" - gazebo-version: "citadel" - ros-distro: "galactic" - - docker-image: "ubuntu:20.04" - gazebo-version: "edifice" - ros-distro: "galactic" - - docker-image: "ubuntu:20.04" - gazebo-version: "fortress" - ros-distro: "galactic" - container: - image: ${{ matrix.docker-image }} - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Build and Test - run: .github/workflows/build-and-test.sh - env: - DOCKER_IMAGE: ${{ matrix.docker-image }} - GAZEBO_VERSION: ${{ matrix.gazebo-version }} - ROS_DISTRO: ${{ matrix.ros-distro }} From 34b6c75140a79c5c8183098a8e5e8ecf14fc9482 Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Fri, 3 Jun 2022 16:42:11 -0700 Subject: [PATCH 05/13] cascading logic Signed-off-by: Louise Poubel --- sdformat_urdf/CMakeLists.txt | 37 +++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/sdformat_urdf/CMakeLists.txt b/sdformat_urdf/CMakeLists.txt index 03854284..470f5e0f 100644 --- a/sdformat_urdf/CMakeLists.txt +++ b/sdformat_urdf/CMakeLists.txt @@ -19,24 +19,47 @@ 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{GAZEBO_VERSION}" STREQUAL "edifice") +if("$ENV{GZ_VERSION}" STREQUAL "edifice") find_package(sdformat11 REQUIRED) set(SDF_VER ${sdformat11_VERSION_MAJOR}) - message(STATUS "Compiling against Gazebo Edifice") + message(STATUS "Compiling against Gazebo Edifice (SDF 11), requested with GZ_VERSION") # Fortress -elseif("$ENV{GAZEBO_VERSION}" STREQUAL "fortress") +elseif("$ENV{GZ_VERSION}" STREQUAL "fortress") find_package(sdformat12 REQUIRED) set(SDF_VER ${sdformat12_VERSION_MAJOR}) - message(STATUS "Compiling against Gazebo Fortress") -# Default to libSDFormat 9 for backwards compatibility -else() + 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") + message(STATUS "Compiling against Gazebo Citadel (SDF 9), requested with GZ_VERSION") +endif() +# Then try ROS_DISTRO +elseif("$ENV{ROS_DISTRO}" STREQUAL "galactic") + 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 From c5afdc9726228b20ca70f799c640d4e173a70027 Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Fri, 3 Jun 2022 16:43:25 -0700 Subject: [PATCH 06/13] gazebo -> gz Signed-off-by: Louise Poubel --- .github/workflows/ci.yaml | 4 ++-- sdformat_urdf/package.xml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0055e8eb..8bb52b53 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,12 +7,12 @@ jobs: strategy: matrix: ros-distro: ["galactic"] - gazebo-version: + gz-version: - "citadel" # libsdformat9 - "edifice" # libsdformat11 - "fortress" # libsdformat12 env: - GAZEBO_VERSION: ${{ matrix.gazebo-version }} + GZ_VERSION: ${{ matrix.gazebo-version }} steps: - uses: ros-tooling/setup-ros@v0.3 with: diff --git a/sdformat_urdf/package.xml b/sdformat_urdf/package.xml index bf965653..21fc7501 100644 --- a/sdformat_urdf/package.xml +++ b/sdformat_urdf/package.xml @@ -18,17 +18,17 @@ ament_cmake_ros - sdformat11 + sdformat11 - sdformat12 + sdformat12 - sdformat - sdformat + sdformat + sdformat urdf From 60710034a6aa672439c130e7eb5b0231d9eba92f Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Fri, 3 Jun 2022 16:52:21 -0700 Subject: [PATCH 07/13] oops Signed-off-by: Louise Poubel --- sdformat_urdf/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/sdformat_urdf/CMakeLists.txt b/sdformat_urdf/CMakeLists.txt index 470f5e0f..801c5147 100644 --- a/sdformat_urdf/CMakeLists.txt +++ b/sdformat_urdf/CMakeLists.txt @@ -43,7 +43,6 @@ elseif("$ENV{GZ_VERSION}" STREQUAL "citadel") 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") find_package(sdformat11 REQUIRED) From 55e0b38af9e2b65218ab683133b80993e4308f1e Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Mon, 6 Jun 2022 12:39:29 -0700 Subject: [PATCH 08/13] Reorder things Signed-off-by: Louise Poubel --- .github/workflows/ci.yaml | 2 +- sdformat_urdf/CMakeLists.txt | 40 ++++++++++++++++++------------------ sdformat_urdf/package.xml | 3 +++ 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8bb52b53..9ce0c608 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,7 @@ jobs: - "edifice" # libsdformat11 - "fortress" # libsdformat12 env: - GZ_VERSION: ${{ matrix.gazebo-version }} + GZ_VERSION: ${{ matrix.gz-version }} steps: - uses: ros-tooling/setup-ros@v0.3 with: diff --git a/sdformat_urdf/CMakeLists.txt b/sdformat_urdf/CMakeLists.txt index 801c5147..95070d57 100644 --- a/sdformat_urdf/CMakeLists.txt +++ b/sdformat_urdf/CMakeLists.txt @@ -24,38 +24,38 @@ find_package(TinyXML2 REQUIRED) # Default to Citadel set(SDF_VER 9) -# First try GZ_VERSION +# 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() -# Edifice -if("$ENV{GZ_VERSION}" STREQUAL "edifice") +# 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 (SDF 11), requested with GZ_VERSION") -# Fortress + 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 (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") -# Then try ROS_DISTRO -elseif("$ENV{ROS_DISTRO}" STREQUAL "galactic") - 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 + 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() diff --git a/sdformat_urdf/package.xml b/sdformat_urdf/package.xml index 21fc7501..f6f97078 100644 --- a/sdformat_urdf/package.xml +++ b/sdformat_urdf/package.xml @@ -21,12 +21,15 @@ sdformat11 + sdformat12 + sdformat12 sdformat12 + sdformat sdformat sdformat From a9f3948f1e36634138d16fe564911c447a0ce420 Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Mon, 6 Jun 2022 13:02:03 -0700 Subject: [PATCH 09/13] Fix tests with Edifice Signed-off-by: Louise Poubel --- README.md | 6 ++++-- sdformat_urdf/src/sdformat_urdf.cpp | 8 +++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 73be2871..296a3ae0 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,10 @@ See the [README in the `sdformat_urdf` package](./sdformat_urdf/README.md) for m This package can be compiled against different Gazebo versions. -Set the `GAZEBO_VERSION` environment variable to the Gazebo version you'd +Set the `GZ_VERSION` environment variable to the Gazebo version you'd like to compile against. For example: - export GAZEBO_VERSION=fortress + export GZ_VERSION=fortress > You only need to set this variable when compiling, not when running. @@ -28,3 +28,5 @@ 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 diff --git a/sdformat_urdf/src/sdformat_urdf.cpp b/sdformat_urdf/src/sdformat_urdf.cpp index b1491921..798902cc 100644 --- a/sdformat_urdf/src/sdformat_urdf.cpp +++ b/sdformat_urdf/src/sdformat_urdf.cpp @@ -13,6 +13,7 @@ // limitations under the License. #include +#include #include #include #include @@ -66,7 +67,11 @@ 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 + // 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 + IGN_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION if (0u == sdf_dom.ModelCount()) { errors.emplace_back( sdf::ErrorCode::STRING_READ, @@ -80,6 +85,7 @@ sdformat_urdf::sdf_to_urdf(const sdf::Root & sdf_dom, sdf::Errors & errors) return nullptr; } return convert_model(*sdf_dom.ModelByIndex(0), errors); + IGN_UTILS_WARN_RESUME__DEPRECATED_DECLARATION #else if (nullptr == sdf_dom.Model()) { errors.emplace_back( From 7a7f856d9627f5c11d5fbc59e43ee9e5d1a7ee48 Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Mon, 6 Jun 2022 13:37:57 -0700 Subject: [PATCH 10/13] no gz-utils for SDF 9 Signed-off-by: Louise Poubel --- sdformat_urdf/src/sdformat_urdf.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sdformat_urdf/src/sdformat_urdf.cpp b/sdformat_urdf/src/sdformat_urdf.cpp index 798902cc..14fb3dd0 100644 --- a/sdformat_urdf/src/sdformat_urdf.cpp +++ b/sdformat_urdf/src/sdformat_urdf.cpp @@ -13,7 +13,9 @@ // limitations under the License. #include -#include +#if SDF_MAJOR_VERSION >= 11 + #include +#endif #include #include #include @@ -71,7 +73,9 @@ sdformat_urdf::sdf_to_urdf(const sdf::Root & sdf_dom, sdf::Errors & errors) // To keep test expectations consistent across all versions, we use // the deprecated APIs for 11. #if SDF_MAJOR_VERSION <= 11 - IGN_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION + #if SDF_MAJOR_VERSION >= 11 + IGN_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION + #endif if (0u == sdf_dom.ModelCount()) { errors.emplace_back( sdf::ErrorCode::STRING_READ, @@ -85,7 +89,9 @@ sdformat_urdf::sdf_to_urdf(const sdf::Root & sdf_dom, sdf::Errors & errors) return nullptr; } return convert_model(*sdf_dom.ModelByIndex(0), errors); - IGN_UTILS_WARN_RESUME__DEPRECATED_DECLARATION + #if SDF_MAJOR_VERSION >= 11 + IGN_UTILS_WARN_RESUME__DEPRECATED_DECLARATION + #endif #else if (nullptr == sdf_dom.Model()) { errors.emplace_back( From f0d5e64df6796de7bcb3b9a371560366bdb517e5 Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Mon, 6 Jun 2022 13:45:49 -0700 Subject: [PATCH 11/13] uncrustify Signed-off-by: Louise Poubel --- sdformat_urdf/src/sdformat_urdf.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sdformat_urdf/src/sdformat_urdf.cpp b/sdformat_urdf/src/sdformat_urdf.cpp index 14fb3dd0..3eddb7a5 100644 --- a/sdformat_urdf/src/sdformat_urdf.cpp +++ b/sdformat_urdf/src/sdformat_urdf.cpp @@ -73,9 +73,9 @@ sdformat_urdf::sdf_to_urdf(const sdf::Root & sdf_dom, sdf::Errors & errors) // 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 SDF_MAJOR_VERSION >= 11 + IGN_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION +#endif if (0u == sdf_dom.ModelCount()) { errors.emplace_back( sdf::ErrorCode::STRING_READ, @@ -89,9 +89,9 @@ sdformat_urdf::sdf_to_urdf(const sdf::Root & sdf_dom, sdf::Errors & errors) return nullptr; } return convert_model(*sdf_dom.ModelByIndex(0), errors); - #if SDF_MAJOR_VERSION >= 11 - IGN_UTILS_WARN_RESUME__DEPRECATED_DECLARATION - #endif +#if SDF_MAJOR_VERSION >= 11 + IGN_UTILS_WARN_RESUME__DEPRECATED_DECLARATION +#endif #else if (nullptr == sdf_dom.Model()) { errors.emplace_back( From 1ac4b88275222540fd7bff0bcbf4b42373a5ce4e Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Tue, 7 Jun 2022 17:29:31 -0700 Subject: [PATCH 12/13] Apply suggestions from code review Signed-off-by: Louise Poubel Co-authored-by: Shane Loretz --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 296a3ae0..e64f44c0 100644 --- a/README.md +++ b/README.md @@ -14,19 +14,19 @@ See the [README in the `sdformat_urdf` package](./sdformat_urdf/README.md) for m ## Version combinations -This package can be compiled against different Gazebo versions. +This package can be compiled against versions of libSDFormat. -Set the `GZ_VERSION` environment variable to the Gazebo version you'd -like to compile against. For example: +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 | 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 +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 From 6fae5e84abe4811241d2c1e4690d721e1454ec23 Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Tue, 7 Jun 2022 17:31:06 -0700 Subject: [PATCH 13/13] Citadel Signed-off-by: Louise Poubel --- sdformat_urdf/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdformat_urdf/CMakeLists.txt b/sdformat_urdf/CMakeLists.txt index 95070d57..3d460011 100644 --- a/sdformat_urdf/CMakeLists.txt +++ b/sdformat_urdf/CMakeLists.txt @@ -29,7 +29,8 @@ 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") + # 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()