Skip to content

Commit

Permalink
Add python bindings to new methods and corresponding tests
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Pacheco <gabriel.fpacheco@gmail.com>
  • Loading branch information
gabrielfpacheco committed Feb 19, 2025
1 parent 40c0324 commit 38b52d4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 10 additions & 0 deletions python/src/gz/sim/Link.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ void defineSimLink(py::object module)
"Add a wrench expressed in world coordinates and applied to "
"the link at an offset from the link's origin. This wrench is applied "
"for one simulation step.")
.def("axis_aligned_box",
py::overload_cast<const EntityComponentManager &>
(&gz::sim::Link::AxisAlignedBox, py::const_),
py::arg("ecm"),
"Get the Link's axis-aligned box represented in the link frame.")
.def("world_axis_aligned_box",
py::overload_cast<const EntityComponentManager &>
(&gz::sim::Link::WorldAxisAlignedBox, py::const_),
py::arg("ecm"),
"Get the Link's axis-aligned box represented in the world frame.")
.def("__copy__",
[](const gz::sim::Link &self)
{
Expand Down
14 changes: 13 additions & 1 deletion python/test/link_TEST.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from gz_test_deps.common import set_verbosity
from gz_test_deps.sim import K_NULL_ENTITY, TestFixture, Link, Model, World, world_entity
from gz_test_deps.math import Inertiald, Matrix3d, Vector3d, Pose3d
from gz_test_deps.math import AxisAlignedBox, Inertiald, Matrix3d, Vector3d, Pose3d

class TestModel(unittest.TestCase):
post_iterations = 0
Expand Down Expand Up @@ -88,6 +88,18 @@ def on_pre_udpate_cb(_info, _ecm):
self.assertEqual(0, link.world_kinetic_energy(_ecm))
link.enable_velocity_checks(_ecm, False)
link.enable_acceleration_checks(_ecm, False)
# Axis Aligned Box Test
# Offset of 0.5 meters along z-axis
self.assertEqual(
AxisAlignedBox(Vector3d(-0.5, -0.5, 0), Vector3d(0.5, 0.5, 1)),
link.axis_aligned_box(_ecm)
)
# World Axis Aligned Box Test
# Same as above since the link is at the origin
self.assertEqual(
AxisAlignedBox(Vector3d(-0.5, -0.5, 0), Vector3d(0.5, 0.5, 1)),
link.world_axis_aligned_box(_ecm)
)


def on_udpate_cb(_info, _ecm):
Expand Down

0 comments on commit 38b52d4

Please sign in to comment.