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

Merge 13 -> 14 #1428

Merged
merged 9 commits into from
May 31, 2024
10 changes: 10 additions & 0 deletions include/sdf/Link.hh
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,22 @@ namespace sdf
/// \sa bool Model::EnableWind
public: bool EnableWind() const;

/// \brief Check if this link should be subject to gravity.
/// If true, this link should be affected by gravity.
/// \return true if the model should be subject to gravity, false otherwise.
public: bool EnableGravity() const;

/// \brief Set whether this link should be subject to wind.
/// \param[in] _enableWind True or false depending on whether the link
/// should be subject to wind.
/// \sa Model::SetEnableWind(bool)
public: void SetEnableWind(bool _enableWind);

/// \brief Set whether this link should be subject to gravity.
/// \param[in] _enableGravity True or false depending on whether the link
/// should be subject to gravity.
public: void SetEnableGravity(bool _enableGravity);

/// \brief Check if the automatic calculation for the link inertial
/// is enabled or not.
/// \return True if automatic calculation is enabled. This can be done
Expand Down
145 changes: 145 additions & 0 deletions include/sdf/Surface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef SDF_SURFACE_HH_
#define SDF_SURFACE_HH_

#include <gz/math/Vector3.hh>
#include <gz/utils/ImplPtr.hh>
#include "sdf/Element.hh"
#include "sdf/Types.hh"
Expand Down Expand Up @@ -122,6 +123,132 @@ namespace sdf
GZ_UTILS_IMPL_PTR(dataPtr)
};

/// \brief BulletFriction information for a friction.
class SDFORMAT_VISIBLE BulletFriction
{
/// \brief Default constructor
public: BulletFriction();

/// \brief Load BulletFriction friction 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 friction coefficient in first friction pyramid direction.
/// \returns Friction coefficient
public: double Friction() const;

/// \brief Set friction coefficient in first friction pyramid direction.
/// \param[in] _fricton Friction coefficient
public: void SetFriction(double _friction);

/// \brief Get the friction coefficient in second friction pyramid
/// direction.
/// \return Second friction coefficient
public: double Friction2() const;

/// \brief Set friction coefficient in second friction pyramid direction.
/// \param[in] _fricton Friction coefficient
public: void SetFriction2(double _friction);

/// \brief Get the first friction pyramid direction in collision-fixed
/// reference
/// \return First friction pyramid direction.
public: const gz::math::Vector3d &Fdir1() const;

/// \brief Set the first friction pyramid direction in collision-fixed
/// reference
/// \param[in] _fdir First friction pyramid direction.
public: void SetFdir1(const gz::math::Vector3d &_fdir);

/// \brief Get the rolling friction coefficient
/// \return Rolling friction coefficient
public: double RollingFriction() const;

/// \brief Set the rolling friction coefficient
/// \param[in] _slip1 Rolling friction coefficient
public: void SetRollingFriction(double _friction);

/// \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 Private data pointer.
GZ_UTILS_IMPL_PTR(dataPtr)
};

/// \brief Torsional friction
class SDFORMAT_VISIBLE Torsional
{
/// \brief Default constructor
public: Torsional();

/// \brief Load torsional friction 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 torsional friction coefficient.
/// \return Torsional friction coefficient
public: double Coefficient() const;

/// \brief Set the torsional friction coefficient.
/// \param[in] _fricton Torsional friction coefficient
public: void SetCoefficient(double _coefficient);

/// \brief Get whether the patch radius is used to calculate torsional
/// friction.
/// \return True if patch radius is used.
public: bool UsePatchRadius() const;

/// \brief Set whether to use patch radius for torsional friction
/// calculation.
/// \param[in] _usePatchRadius True to use patch radius.
/// False to use surface radius.
public: void SetUsePatchRadius(bool _usePatchRadius);

/// \brief Get the radius of contact patch surface.
/// \return Patch radius
public: double PatchRadius() const;

/// \brief Set the radius of contact patch surface.
/// \param[in] _radius Patch radius
public: void SetPatchRadius(double _radius);

/// \brief Get the surface radius on the contact point
/// \return Surface radius
public: double SurfaceRadius() const;

/// \brief Set the surface radius on the contact point.
/// \param[in] _radius Surface radius
public: void SetSurfaceRadius(double _radius);

/// \brief Get the ODE force dependent slip for torsional friction
/// \return Force dependent slip for torsional friction.
public: double ODESlip() const;

/// \brief Set the ODE force dependent slip for torsional friction
/// \param[in] _slip Force dependent slip for torsional friction.
public: void SetODESlip(double _slip);

/// \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 Private data pointer.
GZ_UTILS_IMPL_PTR(dataPtr)
};

/// \brief Friction information for a surface.
class SDFORMAT_VISIBLE Friction
{
Expand All @@ -145,6 +272,24 @@ namespace sdf
/// \param[in] _ode The ODE object.
public: void SetODE(const sdf::ODE &_ode);

/// \brief Get the associated BulletFriction object
/// \return Pointer to the associated BulletFriction object,
/// nullptr if the Surface doesn't contain a BulletFriction element.
public: const sdf::BulletFriction *BulletFriction() const;

/// \brief Set the associated BulletFriction object.
/// \param[in] _bullet The BulletFriction object.
public: void SetBulletFriction(const sdf::BulletFriction &_bullet);

/// \brief Get the torsional friction
/// \return Pointer to the torsional friction
/// nullptr if the Surface doesn't contain a torsional friction element.
public: const sdf::Torsional *Torsional() const;

/// \brief Set the torsional friction
/// \param[in] _torsional The torsional friction.
public: void SetTorsional(const sdf::Torsional &_torsional);

/// \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
Expand Down
2 changes: 2 additions & 0 deletions python/src/sdf/_gz_sdformat_pybind11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ PYBIND11_MODULE(BINDINGS_MODULE_NAME, m) {
sdf::python::defineAltimeter(m);
sdf::python::defineAtmosphere(m);
sdf::python::defineBox(m);
sdf::python::defineBulletFriction(m);
sdf::python::defineCamera(m);
sdf::python::defineCapsule(m);
sdf::python::defineCollision(m);
Expand Down Expand Up @@ -134,6 +135,7 @@ PYBIND11_MODULE(BINDINGS_MODULE_NAME, m) {
sdf::python::defineSky(m);
sdf::python::defineSphere(m);
sdf::python::defineSurface(m);
sdf::python::defineTorsional(m);
sdf::python::defineVisual(m);
sdf::python::defineWorld(m);

Expand Down
7 changes: 7 additions & 0 deletions python/src/sdf/pyLink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ void defineLink(pybind11::object module)
.def("set_enable_wind",
&sdf::Link::SetEnableWind,
"Set whether this link should be subject to wind.")
.def("enable_gravity",
&sdf::Link::EnableGravity,
"Check if this link should be subject to gravity. "
"If true, this link should be affected by gravity.")
.def("set_enable_gravity",
&sdf::Link::SetEnableGravity,
"Set whether this link should be subject to gravity.")
.def("add_collision",
&sdf::Link::AddCollision,
"Add a collision to the link.")
Expand Down
72 changes: 72 additions & 0 deletions python/src/sdf/pySurface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ void defineFriction(pybind11::object module)
"Get the ODE object.")
.def("set_ode", &sdf::Friction::SetODE,
"Set the ODE object.")
.def("bullet_friction", &sdf::Friction::BulletFriction,
pybind11::return_value_policy::reference_internal,
"Get the bullet friction object.")
.def("set_bullet_friction", &sdf::Friction::SetBulletFriction,
"Set the bullet friction object.")
.def("torsional", &sdf::Friction::Torsional,
pybind11::return_value_policy::reference_internal,
"Get the torsional friction object.")
.def("set_torsional", &sdf::Friction::SetTorsional,
"Set the torsional friction object.")
.def("__copy__", [](const sdf::Friction &self) {
return sdf::Friction(self);
})
Expand Down Expand Up @@ -118,6 +128,68 @@ void defineSurface(pybind11::object module)
return sdf::Surface(self);
}, "memo"_a);
}
/////////////////////////////////////////////////
void defineBulletFriction(pybind11::object module)
{
pybind11::class_<sdf::BulletFriction>(module, "BulletFriction")
.def(pybind11::init<>())
.def(pybind11::init<sdf::BulletFriction>())
.def("friction", &sdf::BulletFriction::Friction,
"Get the friction parameter.")
.def("set_friction", &sdf::BulletFriction::SetFriction,
"Set the friction parameter.")
.def("friction2", &sdf::BulletFriction::Friction2,
"Get the friction parameter.")
.def("set_friction2", &sdf::BulletFriction::SetFriction2,
"Set the friction2 parameter.")
.def("fdir1", &sdf::BulletFriction::Fdir1,
"Get the fdir1 parameter.")
.def("set_fdir1", &sdf::BulletFriction::SetFdir1,
"Set the fdir1 parameter.")
.def("rolling_friction", &sdf::BulletFriction::RollingFriction,
"Get the rolling fricion parameter.")
.def("set_rolling_friction", &sdf::BulletFriction::SetRollingFriction,
"Set the rolling friction parameter.")
.def("__copy__", [](const sdf::BulletFriction &self) {
return sdf::BulletFriction(self);
})
.def("__deepcopy__", [](const sdf::BulletFriction &self, pybind11::dict) {
return sdf::BulletFriction(self);
}, "memo"_a);
}
/////////////////////////////////////////////////
void defineTorsional(pybind11::object module)
{
pybind11::class_<sdf::Torsional>(module, "Torsional")
.def(pybind11::init<>())
.def(pybind11::init<sdf::Torsional>())
.def("coefficient", &sdf::Torsional::Coefficient,
"Get the coefficient parameter.")
.def("set_coefficient", &sdf::Torsional::SetCoefficient,
"Set the coefficient parameter.")
.def("use_patch_radius", &sdf::Torsional::UsePatchRadius,
"Get whether to use patch radius for torsional friction calculation.")
.def("set_use_patch_radius", &sdf::Torsional::SetUsePatchRadius,
"Set whether to use patch radius for torsional friction calculation.")
.def("patch_radius", &sdf::Torsional::PatchRadius,
"Get the radius of contact patch surface.")
.def("set_patch_radius", &sdf::Torsional::SetPatchRadius,
"Set the radius of contact patch surface.")
.def("surface_radius", &sdf::Torsional::SurfaceRadius,
"Get the surface radius on the contact point.")
.def("set_surface_radius", &sdf::Torsional::SetSurfaceRadius,
"Set the surface radius on the contact point.")
.def("ode_slip", &sdf::Torsional::ODESlip,
"Get the ODE force dependent slip for torsional friction.")
.def("set_ode_slip", &sdf::Torsional::SetODESlip,
"Set the ODE force dependent slip for torsional friction.")
.def("__copy__", [](const sdf::Torsional &self) {
return sdf::Torsional(self);
})
.def("__deepcopy__", [](const sdf::Torsional &self, pybind11::dict) {
return sdf::Torsional(self);
}, "memo"_a);
}
} // namespace python
} // namespace SDF_VERSION_NAMESPACE
} // namespace sdf
12 changes: 12 additions & 0 deletions python/src/sdf/pySurface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ void defineODE(pybind11::object module);
* \param[in] module a pybind11 module to add the definition to
*/
void defineSurface(pybind11::object module);

/// Define a pybind11 wrapper for an sdf::BulletFriction
/**
* \param[in] module a pybind11 module to add the definition to
*/
void defineBulletFriction(pybind11::object module);

/// Define a pybind11 wrapper for an sdf::Torsional
/**
* \param[in] module a pybind11 module to add the definition to
*/
void defineTorsional(pybind11::object module);
} // namespace python
} // namespace SDF_VERSION_NAMESPACE
} // namespace sdf
Expand Down
4 changes: 4 additions & 0 deletions python/test/pyLink_TEST.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def test_default_construction(self):
link.set_enable_wind(True)
self.assertTrue(link.enable_wind())

self.assertTrue(link.enable_gravity())
link.set_enable_gravity(False)
self.assertFalse(link.enable_gravity())

self.assertFalse(link.auto_inertia_saved())
link.set_auto_inertia_saved(True)
self.assertTrue(link.auto_inertia_saved())
Expand Down
Loading
Loading