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

Schema accessor #1393

Open
wants to merge 23 commits into
base: sdf14
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
310b6fd
added changes
aagrawal05 Aug 16, 2024
f8e22dc
string to string_view, refactoring
aagrawal05 Aug 16, 2024
339a4dc
Param_TEST: Check return values of Param::Get/Set (#1394)
scpeters Apr 8, 2024
ceee6ff
backport - Add mesh optimization attribute to <mesh> #1382
iche033 Mar 21, 2024
2028a96
backport - Update max_convex_hulls description #1386
iche033 Mar 26, 2024
2276134
Added Python wrapper to ConvexDecomposition (#1398)
ahcorde Apr 9, 2024
5590a14
Add package.xml, fix `gz sdf` tests on Windows (#1374)
azeey Apr 19, 2024
67bf992
Fix trivial warning on 24.04 for JointAxis_TEST.cc (#1402)
j-rivero Apr 22, 2024
8631b3f
Prepare for 14.2.0 release (#1405)
iche033 Apr 23, 2024
74aca7e
(Backport) Enable 24.04 CI, remove distutils dependency (#1413)
Blast545 May 14, 2024
0a61cc1
Allow empty strings in plugin and custom attributes (#1407)
scpeters May 20, 2024
186f7b1
Update default camera instrinsics skew to 0, which matches spec (#1423)
shameekganguly May 28, 2024
2489af1
Add note in migration guide on camera skew value change (#1425)
iche033 May 30, 2024
0127bb8
Added Automatic Moment of Inertia Calculations for Basic Shapes Pytho…
ahcorde May 30, 2024
faf94a0
Add bullet and torsional friction DOM (#1351)
iche033 Mar 20, 2024
6d4141e
Add python bindings for bullet and torsional friction (#1427)
iche033 May 30, 2024
8c0b857
Backport voxel_resolution sdf element
iche033 May 28, 2024
1286675
Prepare for 12.8.0 release (#1430) (#1432)
iche033 Jun 13, 2024
43ba646
Prepare for 14.3.0 release (#1437)
iche033 Jun 14, 2024
f0dfc5f
Add custom attribute to custom element in test (#1406)
scpeters Jun 19, 2024
c3e5690
Add Cone as a primitive parametric shape. (#1415)
bperseghetti Jun 20, 2024
2a66550
Prepare release 14.4.0 (#1441)
j-rivero Jun 21, 2024
e8e45a8
Style fixes
Aug 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/ci/packages.apt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ libtinyxml2-dev
liburdfdom-dev
libxml2-utils
python3-dev
python3-distutils
python3-gz-math7
python3-psutil
python3-pybind11
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ jobs:
codecov-enabled: true
cppcheck-enabled: true
cpplint-enabled: true
noble-ci:
runs-on: ubuntu-latest
name: Ubuntu Noble CI
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Compile and test
id: ci
uses: gazebo-tooling/action-gz-ci@noble
11 changes: 11 additions & 0 deletions .github/workflows/package_xml.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Validate package.xml

on:
pull_request:

jobs:
package-xml:
runs-on: ubuntu-latest
name: Validate package.xml
steps:
- uses: gazebo-tooling/action-gz-ci/validate_package_xml@jammy
2 changes: 1 addition & 1 deletion 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.1.1)
project (sdformat14 VERSION 14.4.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
72 changes: 72 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,62 @@
## libsdformat 14.X

### libsdformat 14.4.0 (2024-06-20)

1. Add Cone as a primitive parametric shape.
* [Pull request #1415](https://github.com/gazebosim/sdformat/pull/1415)
* Thanks to Benjamin Perseghetti

1. Add custom attribute to custom element in test
* [Pull request #1406](https://github.com/gazebosim/sdformat/pull/1406)

### libsdformat 14.3.0 (2024-06-14)

1. Backport voxel_resolution sdf element
* [Pull request #1429](https://github.com/gazebosim/sdformat/pull/1429)

1. Added Automatic Moment of Inertia Calculations for Basic Shapes Python wrappers
* [Pull request #1424](https://github.com/gazebosim/sdformat/pull/1424)

1. Add support for no gravity link
* [Pull request #1410](https://github.com/gazebosim/sdformat/pull/1410)
* [Pull request #1419](https://github.com/gazebosim/sdformat/pull/1419)

1. Update default camera instrinsics skew to 0, which matches spec
* [Pull request #1423](https://github.com/gazebosim/sdformat/pull/1423)
* [Pull request #1425](https://github.com/gazebosim/sdformat/pull/1425)

1. Allow empty strings in plugin and custom attributes
* [Pull request #1407](https://github.com/gazebosim/sdformat/pull/1407)

1. (Backport) Enable 24.04 CI, remove distutils dependency
* [Pull request #1413](https://github.com/gazebosim/sdformat/pull/1413)

1. Fix macOS workflow and backport windows fix
* [Pull request #1409](https://github.com/gazebosim/sdformat/pull/1409)

1. Fix warning with pybind11 2.12
* [Pull request #1389](https://github.com/gazebosim/sdformat/pull/1389)

1. Add bullet and torsional friction DOM
* [Pull request #1351](https://github.com/gazebosim/sdformat/pull/1351)
* [Pull request #1427](https://github.com/gazebosim/sdformat/pull/1427)

### libsdformat 14.2.0 (2024-04-23)

1. Fix trivial warning on 24.04 for JointAxis_TEST.cc
* [Pull request #1402](https://github.com/gazebosim/sdformat/pull/1402)

1. Add package.xml, fix `gz sdf` tests on Windows
* [Pull request #1374](https://github.com/gazebosim/sdformat/pull/1374)

1. Backport mesh optimization feature
* [Pull request #1398](https://github.com/gazebosim/sdformat/pull/1398)
* [Pull request #1386](https://github.com/gazebosim/sdformat/pull/1386)
* [Pull request #1382](https://github.com/gazebosim/sdformat/pull/1382)

1. Param_TEST: Check return values of Param::Get/Set
* [Pull request #1394](https://github.com/gazebosim/sdformat/pull/1394)

### libsdformat 14.1.1 (2024-03-28)

1. Fix warning with pybind11 2.12
Expand Down Expand Up @@ -574,6 +631,21 @@

## libsdformat 12.X

### libsdformat 12.8.0 (2024-06-06)

1. Add support for no gravity link
* [Pull request #1410](https://github.com/gazebosim/sdformat/pull/1410)

1. Add bullet and torsional friction DOM
* [Pull request #1351](https://github.com/gazebosim/sdformat/pull/1351)

1. Fix static builds and optimize test compilation
* [Pull request #1343](https://github.com/gazebosim/sdformat/pull/1343)
* [Pull request #1347](https://github.com/gazebosim/sdformat/pull/1347)

1. Update github action workflows
* [Pull request #1345](https://github.com/gazebosim/sdformat/pull/1345)

### libsdformat 12.7.2 (2023-09-01)

1. Fixed 1.9/light.sdf
Expand Down
3 changes: 3 additions & 0 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ but with improved human-readability..

### Modifications

1. The default camera lens intrinsics skew value in the Camera DOM class changed
from `1` to `0` to match the SDF specification.

1. World class only renames frames with name collisions if original file version
is 1.6 or earlier. Name collisions in newer files will cause `DUPLICATE_NAME`
errors, which now matches the behavior of the Model class.
Expand Down
79 changes: 79 additions & 0 deletions format_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import os

lines = os.listdir('./sdf/1.11/')
# Only keep the files that end with .sdf
lines = [line for line in lines if line.endswith('.sdf')]
for line in lines:
# Remove .sdf extension
snake_case = line.strip().split('.')[0]
# Convert from snake_case to CamelCase
camel_case = ''.join([word.capitalize() for word in snake_case.split('_')])

addHeader = """\n /// \\brief Get the schema file name accessor
public: static inline std::string_view SchemaFile();\n"""

addImpl = f"""
/////////////////////////////////////////////////
inline std::string_view {camel_case}::SchemaFile()
{{
static const char kSchemaFile[] = "{line}";
return kSchemaFile;
}}\n\n"""
# Debug print statements
# print(addHeader)
# print(addImpl)
# print(addTest)
# print("\n")

print(line)

# Edit './include/sdf/{camel_case}.hh'
# Find the line with 'class SDFFORMAT_VISIBLE {camel_case}`
try:
f = open('./include/sdf/' + camel_case + '.hh', 'r')
read_lines = f.readlines()
f.close()
line_number = 0
for i, line_raw in enumerate(read_lines):
if line_raw == " class SDFORMAT_VISIBLE " + camel_case + '\n':
line_number = i+3 # After the class line there is `\n{\n` and then the constructor
break
if line_number == 0:
print("Error: Could not find class declaration in " + camel_case + ".hh")
exit(1)
try:
with open('./include/sdf/' + camel_case + '.hh', 'w') as file:
for i, line_raw in enumerate(read_lines):
file.write(line_raw)
if i == line_number:
file.write(addHeader)
except:
print("Unexpected error while writing to: " + camel_case + ".hh.")
except:
print("Error while writing to: " + camel_case + ".hh." + " Check if file exists.")

# Replace all instances of `line` with `std::string(this->SchemaFile())`
if (os.path.exists('./src/' + camel_case + '.cc')):
try:
f = open('./src/' + camel_case + '.cc', 'r')
read_lines = f.readlines()
f.close()

with open('./src/' + camel_case + '.cc', 'w') as file:
for i, line_raw in enumerate(read_lines):
if "kSchemaFile[]" not in line_raw:
file.write(line_raw.replace(f'"{line}"', 'std::string(this->SchemaFile())'))
else:
file.write(line_raw)
except:
print("Unexpected error while reading from: " + camel_case + ".cc.")

# Edit './src/{camel_case}.cc' if it exists
# Add implementation to end of document
if os.path.exists('./src/' + camel_case + '.cc'):
with open('./src/' + camel_case + '.cc', 'a') as file:
file.write(addImpl)
else:
print("Error: Could not find " + camel_case + ".cc")

print("Changes written to source successfully")
3 changes: 3 additions & 0 deletions include/sdf/Actor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ namespace sdf
/// \brief Default constructor
public: Actor();

/// \brief Get the schema file name accessor
public: static inline std::string_view SchemaFile();

/// \brief Load the actor based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/AirPressure.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ namespace sdf
/// \brief Default constructor
public: AirPressure();

/// \brief Get the schema file name accessor
public: static inline std::string_view SchemaFile();

/// \brief Load the airPressure based on an element pointer.
/// This is *not* the usual entry point. Typical usage of the SDF DOM is
/// through the Root object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/AirSpeed.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ namespace sdf
/// \brief Default constructor
public: AirSpeed();

/// \brief Get the schema file name accessor
public: static inline std::string_view SchemaFile();

/// \brief Load the air speed based on an element pointer.
/// This is *not* the usual entry point. Typical usage of the SDF DOM is
/// through the Root object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Altimeter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ namespace sdf
/// \brief Default constructor
public: Altimeter();

/// \brief Get the schema file name accessor
public: static inline std::string_view SchemaFile();

/// \brief Load the altimeter based on an element pointer. This is *not*
/// the usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Atmosphere.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ namespace sdf
/// \brief Default constructor
public: Atmosphere();

/// \brief Get the schema file name accessor
public: static inline std::string_view SchemaFile();

/// \brief Load the atmosphere based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Camera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ namespace sdf
/// \brief Constructor
public: Camera();

/// \brief Get the schema file name accessor
public: static inline std::string_view SchemaFile();

/// \brief Return true if both Camera objects contain the same values.
/// \param[_in] _alt Camera value to compare.
/// \returen True if 'this' == _alt.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Collision.hh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ namespace sdf
/// \brief Default constructor
public: Collision();

/// \brief Get the schema file name accessor
public: static inline std::string_view SchemaFile();

/// \brief Load the collision based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
108 changes: 108 additions & 0 deletions include/sdf/Cone.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright 2024 CogniPilot Foundation
* Copyright 2024 Open Source Robotics Foundation
* Copyright 2024 Rudis Laboratories
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef SDF_CONE_HH_
#define SDF_CONE_HH_

#include <optional>

#include <gz/math/Cone.hh>
#include <gz/math/Inertial.hh>
#include <gz/utils/ImplPtr.hh>
#include <sdf/Error.hh>
#include <sdf/Element.hh>
#include <sdf/sdf_config.h>

namespace sdf
{
// Inline bracket to help doxygen filtering.
inline namespace SDF_VERSION_NAMESPACE {
/// \brief Cone represents a cone shape, and is usually accessed
/// through a Geometry.
class SDFORMAT_VISIBLE Cone
{
/// \brief Constructor
public: Cone();

/// \brief Load the cone geometry based on a element pointer.
/// This is *not* the usual entry point. Typical usage of the SDF DOM is
/// through the Root object.
/// \param[in] _sdf The SDF Element pointer
/// \return Errors, which is a vector of Error objects. Each Error includes
/// an error code and message. An empty vector indicates no error.
public: Errors Load(ElementPtr _sdf);

/// \brief Get the cone's radius in meters.
/// \return The radius of the cone in meters.
public: double Radius() const;

/// \brief Set the cone's radius in meters.
/// \param[in] _radius The radius of the cone in meters.
public: void SetRadius(double _radius);

/// \brief Get the cone's length in meters.
/// \return The length of the cone in meters.
public: double Length() const;

/// \brief Set the cone's length in meters.
/// \param[in] _length The length of the cone in meters.
public: void SetLength(double _length);

/// \brief Get a pointer to the SDF element that was used during
/// load.
/// \return SDF element pointer. The value will be nullptr if Load has
/// not been called.
public: sdf::ElementPtr Element() const;

/// \brief Get the Gazebo Math representation of this cone.
/// \return A const reference to a gz::math::Sphered object.
public: const gz::math::Coned &Shape() const;

/// \brief Get a mutable Gazebo Math representation of this cone.
/// \return A reference to a gz::math::Coned object.
public: gz::math::Coned &Shape();

/// \brief Calculate and return the Inertial values for the cone. In
/// order to calculate the inertial properties, the function mutates the
/// object by updating its material properties.
/// \param[in] _density Density of the cone in kg/m^3
/// \return A std::optional with gz::math::Inertiald object or std::nullopt
public: std::optional<gz::math::Inertiald>
CalculateInertial(double _density);

/// \brief Create and return an SDF element filled with data from this
/// cone.
/// Note that parameter passing functionality is not captured with this
/// function.
/// \return SDF element pointer with updated cone values.
public: sdf::ElementPtr ToElement() const;

/// \brief Create and return an SDF element filled with data from this
/// cone.
/// Note that parameter passing functionality is not captured with this
/// function.
/// \param[out] _errors Vector of errors.
/// \return SDF element pointer with updated cone values.
public: sdf::ElementPtr ToElement(sdf::Errors &_errors) const;

/// \brief Private data pointer.
GZ_UTILS_IMPL_PTR(dataPtr)
};
}
}
#endif
Loading