Skip to content

Commit

Permalink
Merge branch 'sdf14' into arjo/fix/example_sdf
Browse files Browse the repository at this point in the history
  • Loading branch information
arjo129 authored Jan 24, 2025
2 parents 044a1ec + a7ac86e commit 646bc24
Show file tree
Hide file tree
Showing 24 changed files with 1,110 additions and 110 deletions.
22 changes: 7 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if(COMMAND CMAKE_POLICY)
CMAKE_POLICY(SET CMP0004 NEW)
endif(COMMAND CMAKE_POLICY)

project (sdformat14 VERSION 14.5.0)
project (sdformat14 VERSION 14.6.0)

# The protocol version has nothing to do with the package version.
# It represents the current version of SDFormat implemented by the software
Expand Down Expand Up @@ -97,16 +97,6 @@ if (BUILD_SDF)
)
if (NOT Python3_Development_FOUND)
GZ_BUILD_WARNING("Python development libraries are missing: Python interfaces are disabled.")
else()
set(PYBIND11_PYTHON_VERSION 3)
find_package(pybind11 2.4 CONFIG QUIET)

if (pybind11_FOUND)
message (STATUS "Searching for pybind11 - found version ${pybind11_VERSION}.")
else()
GZ_BUILD_WARNING("pybind11 is missing: Python interfaces are disabled.")
message (STATUS "Searching for pybind11 - not found.")
endif()
endif()
endif()

Expand Down Expand Up @@ -136,9 +126,11 @@ if (BUILD_SDF)

################################################
# Find psutil python package for memory tests
find_python_module(psutil)
if (NOT PY_PSUTIL)
gz_build_warning("Python psutil package not found. Memory leak tests will be skipped")
if (BUILD_TESTING)
find_python_module(psutil)
if (NOT PY_PSUTIL)
gz_build_warning("Python psutil package not found. Memory leak tests will be skipped")
endif()
endif()

########################################
Expand All @@ -159,7 +151,7 @@ if (BUILD_SDF)
add_subdirectory(sdf)
add_subdirectory(conf)
add_subdirectory(doc)
if (pybind11_FOUND AND NOT SKIP_PYBIND11)
if (Python3_Development_FOUND AND NOT SKIP_PYBIND11)
add_subdirectory(python)
endif()
endif(BUILD_SDF)
Expand Down
23 changes: 23 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
## libsdformat 14.X

### libsdformat 14.6.0 (2024-11-18)

1. Support removing the actor, light, or model from the root.
* [Pull request #1492](https://github.com/gazebosim/sdformat/pull/1492)

1. Backport: Permit building python bindings separately from libsdformat library.
* [Pull request #1497](https://github.com/gazebosim/sdformat/pull/1497)

1. Backport: Improve installation instructions.
* [Pull request #1496](https://github.com/gazebosim/sdformat/pull/1496)

1. Backport: Fix symbol checking test when compiled with debug symbols.
* [Pull request #1476](https://github.com/gazebosim/sdformat/pull/1476)

1. Update joinPaths implementation in InstallationDirectories.
* [Pull request #1469](https://github.com/gazebosim/sdformat/pull/1469)

1. Decouple linking to shlwapi from `BUILD_TESTING`.
* [Pull request #1468](https://github.com/gazebosim/sdformat/pull/1468)

1. Add optional binary relocatability.
* [Pull request #1414](https://github.com/gazebosim/sdformat/pull/1414)

### libsdformat 14.5.0 (2024-08-05)

1. Adding Errors structure to XmlUtils
Expand Down
13 changes: 13 additions & 0 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ forward programmatically.
This document aims to contain similar information to those files
but with improved human-readability..

## libsdformat 14.6.0 to 14.7.0

1. Inertial parameters can now be automatically calculated with a specified
mass. Previously when the `//inertial/@auto` attribute is set to true, the
`//inertial/mass` value is ignored and the mass, center of mass location, and
inertia matrix are computed based on the collision geometries and densities.
The new behavior is that if `//inertial/mass` is specified, the inertial values
will be computed to preserve the specified mass. This is done by first
calculating inertial parameters from all collisions using density as usual,
calculating the ratio between user-specified mass and the auto-computed mass,
and rescaling the computed mass and moment of inertia by that mass ratio so
that the resulting mass matches the specified mass.

## libsdformat 13.x to 14.x

### Additions
Expand Down
96 changes: 50 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ which version you need, or leave it empty for version 1.

### macOS

On macOS, add OSRF packages:
On macOS, after installing the [Homebrew package manager](https://brew.sh),
add OSRF packages:
```sh
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew tap osrf/simulation
```

Expand Down Expand Up @@ -129,6 +129,25 @@ git clone https://github.com/gazebosim/sdformat -b sdf<#>
Be sure to replace `<#>` with a number value, such as 1 or 2, depending on
which version you need.

### Install dependencies

#### Ubuntu

```sh
cd sdformat
sudo apt -y install \
$(sort -u $(find . -iname 'packages-'`lsb_release -cs`'.apt' -o -iname 'packages.apt' | tr '\n' ' '))
```

#### macOS

```sh
brew install --only-dependencies sdformat<#>
```

Be sure to replace `<#>` with a number value, such as 14 or 15, depending on
which version you need.

### Build from Source

Standard installation can be performed in UNIX systems using the following
Expand All @@ -144,12 +163,35 @@ make install

sdformat supported cmake parameters at configuring time:

* `USE_INTERNAL_URDF` (`bool`) [default `False`] <br/>
Use an internal copy of urdfdom 1.0.0 instead of look for one
installed in the system
* `USE_UPSTREAM_CFLAGS` (`bool`) [default `True`] <br/>
Use the sdformat team compilation flags instead of the common set defined
by cmake.
| Name | Type | Default | Description |
|-----------------------|------|----------|--------------------------------------|
| `SKIP_PYBIND11` | BOOL | False | Skip generating Python bindings via pybind11 |
| `USE_INTERNAL_URDF` | BOOL | False | Use an internal copy of urdfdom 1.0.0 instead of looking for one installed in the system |
| `USE_UPSTREAM_CFLAGS` | BOOL | True | Use the sdformat team compilation flags instead of the common set defined by cmake. |

### Build python bindings separately from main library

If you want to build Python bindings separately from the main libsdformat library
(for example if you want to build Python bindings for multiple versions of Python),
you can invoke cmake on the `python` folder instead of the root folder.
This requires cmake version 3.22.1 due to the use of a `CMAKE_REQUIRE_FIND_PACKAGE_*`
variable, which is newer than the minimum required version of cmake for sdformat14.
Specify the path to the python executable with which you wish to build bindings
in the `Python3_EXECUTABLE` cmake variable.
Specify the install path for the bindings in the `CMAKE_INSTALL_PREFIX`
variable, and be sure to set your `PYTHONPATH` accordingly after install.

```bash
cd sdformat
mkdir build_python3
cd build_python3
cmake ../python \
-DPython3_EXECUTABLE=/usr/local/bin/python3.12 \
-DCMAKE_INSTALL_PREFIX=<prefix>
```

See the homebrew [sdformat15 formula](https://github.com/osrf/homebrew-simulation/blob/027d06f5be49da1e40d01180aedae7f76dc7ff47/Formula/sdformat15.rb#L12-L56)
for an example of building bindings for multiple versions of Python.

## Uninstallation

Expand All @@ -160,44 +202,6 @@ cd build
make uninstall
```

## macOS

### Prerequisites

Clone the repository
```sh
git clone https://github.com/gazebosim/sdformat -b sdf<#>
```
Be sure to replace `<#>` with a number value, such as 1 or 2, depending on
which version you need.

Install dependencies
```sh
brew install --only-dependencies sdformat<#>
```

### Build from Source

1. Configure and build
```sh
cd sdformat
mkdir build
cd build
cmake .. # Consider specifying -DCMAKE_INSTALL_PREFIX=...
make
```

2. Optionally, install and uninstall
```sh
sudo make install
```

To uninstall the software installed with the previous steps:
```sh
cd build/
sudo make uninstall
```

## Windows

### Prerequisites
Expand Down
5 changes: 4 additions & 1 deletion include/sdf/Collision.hh
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,15 @@ namespace sdf
/// \param[in] _autoInertiaParams An ElementPtr to the auto_inertia_params
/// element to be used if the auto_inertia_params have not been set in this
/// collision.
/// \param[in] _warnIfDensityIsUnset True to generate a warning that
/// the default density value will be used if it is not explicitly set.
public: void CalculateInertial(
sdf::Errors &_errors,
gz::math::Inertiald &_inertial,
const ParserConfig &_config,
const std::optional<double> &_density,
sdf::ElementPtr _autoInertiaParams);
sdf::ElementPtr _autoInertiaParams,
bool _warnIfDensityIsUnset = true);

/// \brief Get a pointer to the SDF element that was used during
/// load.
Expand Down
10 changes: 7 additions & 3 deletions include/sdf/Link.hh
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,13 @@ namespace sdf
const std::string &_resolveTo = "") const;

/// \brief Calculate & set inertial values(mass, mass matrix
/// & inertial pose) for the link. Inertial values can be provided
/// by the user through the SDF or can be calculated automatically
/// by setting the auto attribute to true.
/// & inertial pose) for the link. This function will calculate
/// the inertial values if the auto attribute is set to true.
/// If mass is not provided by the user, the inertial values will be
/// determined based on either link density or collision density if
/// explicitly set. Otherwise, if mass is specified, the inertia matrix
/// will be scaled to match the desired mass, while respecting
/// the ratio of density values between collisions.
/// \param[out] _errors A vector of Errors object. Each object
/// would contain an error code and an error message.
/// \param[in] _config Custom parser configuration
Expand Down
8 changes: 7 additions & 1 deletion include/sdf/ParserConfig.hh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ enum class ConfigureResolveAutoInertials

/// \brief If this values is used, CalculateInertial() would be
/// called and the computed inertial values would be saved
SAVE_CALCULATION
SAVE_CALCULATION,

/// \brief If this values is used, CalculateInertial() would be
/// called and the computed inertial values would be saved and
/// written to the XML Element, allowing the calculated values
/// to be printed with `gz sdf --print`.
SAVE_CALCULATION_IN_ELEMENT,
};

// Forward declare private data class.
Expand Down
5 changes: 5 additions & 0 deletions include/sdf/Root.hh
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ namespace sdf
public: sdf::ElementPtr ToElement(
const OutputConfig &_config = OutputConfig::GlobalConfig()) const;

/// \brief Remove the actor, light, or model if one of them exists.
/// The SDF Root object can only hold one, or none, from the set
/// [Actor, Light, Model].
public: void ClearActorLightModel();

/// \brief Private data pointer
GZ_UTILS_IMPL_PTR(dataPtr)
};
Expand Down
2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<package format="2">
<name>sdformat14</name>
<version>14.5.0</version>
<version>14.6.0</version>
<description>SDFormat is an XML file format that describes environments, objects, and robots
in a manner suitable for robotic applications</description>

Expand Down
39 changes: 31 additions & 8 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug")
# pybind11 logic for setting up a debug build when both a debug and release
# python interpreter are present in the system seems to be pretty much broken.
# This works around the issue.
set(PYTHON_LIBRARIES "${PYTHON_DEBUG_LIBRARIES}")
# Detect if we are doing a standalone build of the bindings, using an external sdformat
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
cmake_minimum_required(VERSION 3.22.1)
set(SDF_VER 14)
project(sdformat${SDF_VER}-python VERSION ${SDF_VER})
find_package(sdformat${SDF_VER} REQUIRED)
set(PROJECT_LIBRARY_TARGET_NAME "sdformat${PROJECT_VERSION_MAJOR}::sdformat${PROJECT_VERSION_MAJOR}")
# require python dependencies to be found
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
set(CMAKE_REQUIRE_FIND_PACKAGE_pybind11 TRUE)
include(GNUInstallDirs)
include(CTest)
elseif(${CMAKE_VERSION} VERSION_LESS "3.12.0")
# TODO: remove once the minimum CMake version is increased
if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug")
# pybind11 logic for setting up a debug build when both a debug and release
# python interpreter are present in the system seems to be pretty much broken.
# This works around the issue.
set(PYTHON_LIBRARIES "${PYTHON_DEBUG_LIBRARIES}")
endif()
endif()

set(PYBIND11_PYTHON_VERSION 3)
find_package(pybind11 2.4 CONFIG QUIET)

if (pybind11_FOUND)
message (STATUS "Searching for pybind11 - found version ${pybind11_VERSION}.")
else()
message(WARNING "pybind11 is missing: Python interfaces are disabled.")
return()
endif()

if(USE_SYSTEM_PATHS_FOR_PYTHON_INSTALLATION)
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c "if True:
COMMAND "${Python3_EXECUTABLE}" -c "if True:
from distutils import sysconfig as sc
print(sc.get_python_lib(plat_specific=True))"
OUTPUT_VARIABLE Python3_SITEARCH
Expand All @@ -28,7 +52,7 @@ if(USE_SYSTEM_PATHS_FOR_PYTHON_INSTALLATION)
endif()
else()
# If not a system installation, respect local paths
set(GZ_PYTHON_INSTALL_PATH ${GZ_LIB_INSTALL_DIR}/python)
set(GZ_PYTHON_INSTALL_PATH ${CMAKE_INSTALL_LIBDIR}/python)
endif()

# Set the build location and install location for a CPython extension
Expand Down Expand Up @@ -124,7 +148,6 @@ if (BUILD_TESTING AND NOT WIN32)

target_link_libraries(sdformattest PRIVATE
${PROJECT_LIBRARY_TARGET_NAME}
gz-utils${GZ_UTILS_VER}::gz-utils${GZ_UTILS_VER}
)

set(python_tests
Expand Down
4 changes: 4 additions & 0 deletions python/src/sdf/pyRoot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ void defineRoot(pybind11::object module)
.def("set_light", &sdf::Root::SetLight,
"Set the light object. This will override any existing model, "
"actor, and light object.")
.def("clear_actor_light_model", &sdf::Root::ClearActorLightModel,
"Remove the actor, light, or model if one of them exists."
"The SDF Root object can only hold one, or none, from the set"
"[Actor, Light, Model].")
.def("add_world", [](Root &self, const World &_world)
{
ThrowIfErrors(self.AddWorld(_world));
Expand Down
Loading

0 comments on commit 646bc24

Please sign in to comment.