From 8cea254f3518972d60ab003790ceab58e1381958 Mon Sep 17 00:00:00 2001 From: Hongkai Dai Date: Mon, 13 May 2024 13:09:02 -0700 Subject: [PATCH] [pybind] Add MultibodyPlant::CalcRelativeRotationMatrix. (#21426) --- bindings/pydrake/multibody/plant_py.cc | 5 ++++- bindings/pydrake/multibody/test/plant_test.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/bindings/pydrake/multibody/plant_py.cc b/bindings/pydrake/multibody/plant_py.cc index 7218637a01c9..62ee8568dcf4 100644 --- a/bindings/pydrake/multibody/plant_py.cc +++ b/bindings/pydrake/multibody/plant_py.cc @@ -715,7 +715,10 @@ void DoScalarDependentDefinitions(py::module m, T) { py::arg("context"), py::arg("qdot"), cls_doc.MapQDotToVelocity.doc) .def("CalcRelativeTransform", &Class::CalcRelativeTransform, py::arg("context"), py::arg("frame_A"), py::arg("frame_B"), - cls_doc.CalcRelativeTransform.doc); + cls_doc.CalcRelativeTransform.doc) + .def("CalcRelativeRotationMatrix", &Class::CalcRelativeRotationMatrix, + py::arg("context"), py::arg("frame_A"), py::arg("frame_B"), + cls_doc.CalcRelativeRotationMatrix.doc); if constexpr (std::is_same_v) { cls // BR .def("MakeVelocityToQDotMap", &Class::MakeVelocityToQDotMap, diff --git a/bindings/pydrake/multibody/test/plant_test.py b/bindings/pydrake/multibody/test/plant_test.py index 7e61536eae7e..e9e21507a89c 100644 --- a/bindings/pydrake/multibody/test/plant_test.py +++ b/bindings/pydrake/multibody/test/plant_test.py @@ -1142,8 +1142,11 @@ def do_test_multibody_tree_kinematics(self, T, time_step): base = plant.GetBodyByName("base") base_frame = plant.GetFrameByName("base") X_WL = plant.CalcRelativeTransform( - context, frame_A=world_frame, frame_B=base_frame) + context=context, frame_A=world_frame, frame_B=base_frame) self.assertIsInstance(X_WL, RigidTransform) + R_WL = plant.CalcRelativeRotationMatrix( + context=context, frame_A=world_frame, frame_B=base_frame) + self.assertIsInstance(R_WL, RotationMatrix_[T]) free_bodies = plant.GetFloatingBaseBodies() self.assertEqual(len(free_bodies), 1) self.assertTrue(base.index() in free_bodies)