Skip to content

Commit

Permalink
Adding a binding for unwrapEulerAngles
Browse files Browse the repository at this point in the history
  • Loading branch information
keenon committed Sep 27, 2024
1 parent 3896ee2 commit deb01b1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
22 changes: 11 additions & 11 deletions python/_nimblephysics/dynamics/EulerJoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ namespace python {

void EulerJoint(py::module& m)
{
::py::enum_<dart::dynamics::EulerJoint::AxisOrder>(m, "AxisOrder")
.value("XYZ", dart::dynamics::EulerJoint::AxisOrder::XYZ)
.value("XZY", dart::dynamics::EulerJoint::AxisOrder::XZY)
.value("ZYX", dart::dynamics::EulerJoint::AxisOrder::ZYX)
.value("ZXY", dart::dynamics::EulerJoint::AxisOrder::ZXY);
::py::enum_<dart::dynamics::detail::AxisOrder>(m, "AxisOrder")
.value("XYZ", dart::dynamics::detail::AxisOrder::XYZ)
.value("XZY", dart::dynamics::detail::AxisOrder::XZY)
.value("ZYX", dart::dynamics::detail::AxisOrder::ZYX)
.value("ZXY", dart::dynamics::detail::AxisOrder::ZXY);

::py::class_<dart::dynamics::EulerJoint::UniqueProperties>(
m, "EulerJointUniqueProperties")
.def(::py::init<>())
.def(
::py::init<dart::dynamics::EulerJoint::AxisOrder>(),
::py::init<dart::dynamics::detail::AxisOrder>(),
::py::arg("axisOrder"));

::py::class_<
Expand Down Expand Up @@ -162,21 +162,21 @@ void EulerJoint(py::module& m)
.def(
"setAxisOrder",
+[](dart::dynamics::EulerJoint* self,
dart::dynamics::EulerJoint::AxisOrder _order) {
dart::dynamics::detail::AxisOrder _order) {
self->setAxisOrder(_order);
},
::py::arg("order"))
.def(
"setAxisOrder",
+[](dart::dynamics::EulerJoint* self,
dart::dynamics::EulerJoint::AxisOrder _order,
dart::dynamics::detail::AxisOrder _order,
bool _renameDofs) { self->setAxisOrder(_order, _renameDofs); },
::py::arg("order"),
::py::arg("renameDofs"))
.def(
"getAxisOrder",
+[](const dart::dynamics::EulerJoint* self)
-> dart::dynamics::EulerJoint::AxisOrder {
-> dart::dynamics::detail::AxisOrder {
return self->getAxisOrder();
})
.def(
Expand Down Expand Up @@ -209,7 +209,7 @@ void EulerJoint(py::module& m)
.def_static(
"convertToTransformOf",
+[](const Eigen::Vector3s& _positions,
dart::dynamics::EulerJoint::AxisOrder _ordering,
dart::dynamics::detail::AxisOrder _ordering,
const Eigen::Vector3s& flipAxisMap
= Eigen::Vector3s::Ones()) -> Eigen::Isometry3s {
return dart::dynamics::EulerJoint::convertToTransform(
Expand All @@ -221,7 +221,7 @@ void EulerJoint(py::module& m)
.def_static(
"convertToRotationOf",
+[](const Eigen::Vector3s& _positions,
dart::dynamics::EulerJoint::AxisOrder _ordering,
dart::dynamics::detail::AxisOrder _ordering,
const Eigen::Vector3s& flipAxisMap
= Eigen::Vector3s::Ones()) -> Eigen::Matrix3s {
return dart::dynamics::EulerJoint::convertToRotation(
Expand Down
15 changes: 15 additions & 0 deletions python/_nimblephysics/math/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,5 +301,20 @@ void Geometry(py::module& m)
.def("computeHalfExtents", &dart::math::BoundingBox::computeHalfExtents);
}

void EulerGeometry(py::module& m)
{
m.def(
"roundEulerAnglesToNearest",
+[](Eigen::Vector3s angle,
Eigen::Vector3s previousAngle,
dynamics::detail::AxisOrder axisOrder) -> Eigen::Vector3s {
return dart::math::roundEulerAnglesToNearest(
angle, previousAngle, axisOrder);
},
::py::arg("angle"),
::py::arg("previousAngle"),
::py::arg("axisOrder") = dart::dynamics::detail::AxisOrder::XYZ);
}

} // namespace python
} // namespace dart
10 changes: 9 additions & 1 deletion python/_nimblephysics/math/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void MultivariateGaussian(py::module& sm);
void GraphFlowDiscretizer(py::module& sm);
void PolynomialFitter(py::module& sm);

void dart_math(py::module& m)
py::module dart_math(py::module& m)
{
auto sm = m.def_submodule("math");

Expand All @@ -52,6 +52,14 @@ void dart_math(py::module& m)
MultivariateGaussian(sm);
GraphFlowDiscretizer(sm);
PolynomialFitter(sm);

return sm;
}

void EulerGeometry(py::module& sm);
void dart_euler_math(py::module& sm)
{
EulerGeometry(sm);
}

} // namespace python
Expand Down
6 changes: 4 additions & 2 deletions python/_nimblephysics/nimblephysics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ namespace python {
void eigen_geometry(py::module& m);

void dart_common(py::module& m);
void dart_math(py::module& m);
py::module dart_math(py::module& m);
void dart_euler_math(py::module& m);
void dart_dynamics(py::module& m);
void dart_collision(py::module& m);
void dart_constraint(py::module& m);
Expand Down Expand Up @@ -71,9 +72,10 @@ PYBIND11_MODULE(_nimblephysics, m)
eigen_geometry(m);

dart_common(m);
dart_math(m);
py::module math_module = dart_math(m);
dart_performance(m);
dart_dynamics(m);
dart_euler_math(math_module);
dart_collision(m);
dart_constraint(m);
dart_simulation_and_neural(m, neural, withRespectTo);
Expand Down
2 changes: 1 addition & 1 deletion python/nimblephysics.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: nimblephysics
Version: 0.10.45
Version: 0.10.48
Summary: A differentiable fully featured physics engine
Author: Keenon Werling
Author-email: keenonwerling@gmail.com
Expand Down

0 comments on commit deb01b1

Please sign in to comment.