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

Add python bindings for bullet and torsional friction #1427

Merged
merged 4 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
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 @@ -79,6 +79,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 @@ -123,6 +124,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
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 torisional friction object.")
iche033 marked this conversation as resolved.
Show resolved Hide resolved
.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
Loading
Loading