From deb01b10eea60ac6f7ce3fac4c35febf721caf55 Mon Sep 17 00:00:00 2001 From: Keenon Werling Date: Fri, 27 Sep 2024 14:51:10 -0700 Subject: [PATCH] Adding a binding for unwrapEulerAngles --- python/_nimblephysics/dynamics/EulerJoint.cpp | 22 +++++++++---------- python/_nimblephysics/math/Geometry.cpp | 15 +++++++++++++ python/_nimblephysics/math/module.cpp | 10 ++++++++- python/_nimblephysics/nimblephysics.cpp | 6 +++-- python/nimblephysics.egg-info/PKG-INFO | 2 +- 5 files changed, 40 insertions(+), 15 deletions(-) diff --git a/python/_nimblephysics/dynamics/EulerJoint.cpp b/python/_nimblephysics/dynamics/EulerJoint.cpp index 964a942a7..d1d5f006d 100644 --- a/python/_nimblephysics/dynamics/EulerJoint.cpp +++ b/python/_nimblephysics/dynamics/EulerJoint.cpp @@ -44,17 +44,17 @@ namespace python { void EulerJoint(py::module& m) { - ::py::enum_(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_(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_( m, "EulerJointUniqueProperties") .def(::py::init<>()) .def( - ::py::init(), + ::py::init(), ::py::arg("axisOrder")); ::py::class_< @@ -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( @@ -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( @@ -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( diff --git a/python/_nimblephysics/math/Geometry.cpp b/python/_nimblephysics/math/Geometry.cpp index 80d3e6e18..a74723ffa 100644 --- a/python/_nimblephysics/math/Geometry.cpp +++ b/python/_nimblephysics/math/Geometry.cpp @@ -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 diff --git a/python/_nimblephysics/math/module.cpp b/python/_nimblephysics/math/module.cpp index c8879ea23..03c284ccf 100644 --- a/python/_nimblephysics/math/module.cpp +++ b/python/_nimblephysics/math/module.cpp @@ -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"); @@ -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 diff --git a/python/_nimblephysics/nimblephysics.cpp b/python/_nimblephysics/nimblephysics.cpp index 923bb17cd..4a358001d 100644 --- a/python/_nimblephysics/nimblephysics.cpp +++ b/python/_nimblephysics/nimblephysics.cpp @@ -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); @@ -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); diff --git a/python/nimblephysics.egg-info/PKG-INFO b/python/nimblephysics.egg-info/PKG-INFO index fca4fcae1..6043c3909 100644 --- a/python/nimblephysics.egg-info/PKG-INFO +++ b/python/nimblephysics.egg-info/PKG-INFO @@ -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