Expose mjs_resolveOrientation to the Python API.

PiperOrigin-RevId: 762571376
Change-Id: I08d8394b24670c7f102356da4234b17f1ba4e05f
This commit is contained in:
Alessio Quaglino
2025-05-23 14:35:58 -07:00
committed by Copybara-Service
parent eb6f7dc6b7
commit 7a5b55f57e
2 changed files with 27 additions and 0 deletions
+14
View File
@@ -490,6 +490,20 @@ PYBIND11_MODULE(_specs, m) {
},
py::arg("name"),
py::return_value_policy::reference_internal);
mjSpec.def_static(
"resolve_orientation",
[](bool degree, const MjTypeVec<char>& sequence,
const raw::MjsOrientation* orientation) -> std::array<double, 4> {
std::array<double, 4> quat = {0, 0, 0, 0};
const char* err = mjs_resolveOrientation(quat.data(), degree,
sequence.ptr, orientation);
if (err) {
throw pybind11::value_error(err);
}
return quat;
},
py::arg("degree"), py::arg("sequence") = py::none(),
py::arg("orientation"), py::return_value_policy::copy);
// ============================= MJSBODY =====================================
mjsBody.def(
+13
View File
@@ -16,6 +16,7 @@
import gc
import inspect
import math
import os
import textwrap
import typing
@@ -129,6 +130,18 @@ class SpecsTest(absltest.TestCase):
""")
self.assertEqual(spec.to_xml(), xml)
def test_resolve_orientation(self):
spec = mujoco.MjSpec()
body = spec.worldbody.add_body(euler=[0, 0, 90])
quat = mujoco.MjSpec.resolve_orientation(
degree=spec.compiler.degree,
sequence=spec.compiler.eulerseq,
orientation=body.alt,
)
np.testing.assert_array_almost_equal(
quat, [math.sqrt(2) / 2, 0, 0, math.sqrt(2) / 2]
)
def test_kwarg(self):
# Create a spec.
spec = mujoco.MjSpec()