Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pybind wrappers for BodyNode's getChildBodyNode() & getChildJoint() #1387

Merged
merged 1 commit into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions python/dartpy/dynamics/BodyNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,11 +866,21 @@ void BodyNode(py::module& m)
+[](const dart::dynamics::BodyNode* self) -> std::size_t {
return self->getNumChildBodyNodes();
})
.def(
"getChildBodyNode",
+[](dart::dynamics::BodyNode* self, std::size_t index) -> dart::dynamics::BodyNode* { return self->getChildBodyNode(index); },
::py::arg("index"),
::py::return_value_policy::reference_internal)
.def(
"getNumChildJoints",
+[](const dart::dynamics::BodyNode* self) -> std::size_t {
return self->getNumChildJoints();
})
.def(
"getChildJoint",
+[](dart::dynamics::BodyNode* self, std::size_t index) -> dart::dynamics::Joint* { return self->getChildJoint(index); },
::py::arg("index"),
::py::return_value_policy::reference_internal)
.def(
"getNumShapeNodes",
+[](const dart::dynamics::BodyNode* self) -> std::size_t {
Expand Down
23 changes: 22 additions & 1 deletion python/tests/unit/dynamics/test_body_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def test_basic():

for i in range(kr5.getNumBodyNodes()):
body = kr5.getBodyNode(i)
assert np.array_equal(np.array(body.getSpatialVelocity()), np.zeros(6)) is True
assert np.array_equal(
np.array(body.getSpatialVelocity()), np.zeros(6)) is True
shape_nodes = body.getShapeNodes()
for shape_node in shape_nodes:
print(shape_node)
Expand All @@ -24,5 +25,25 @@ def test_basic():
dynamics = shape_node.getDynamicsAspect()


def testGetChildPMethods():
urdfParser = dart.utils.DartLoader()
kr5 = urdfParser.parseSkeleton("dart://sample/urdf/KR5/KR5 sixx R650.urdf")
assert kr5 is not None

currentBodyNode = kr5.getRootBodyNode()
assert currentBodyNode is not None

for i in range(1, kr5.getNumBodyNodes()):
childBodyNode = currentBodyNode.getChildBodyNode(0)
childJoint = currentBodyNode.getChildJoint(0)

assert childBodyNode is not None
assert childJoint is not None
assert childBodyNode.getName() == kr5.getBodyNode(i).getName()
assert childJoint.getName() == kr5.getJoint(i).getName()

currentBodyNode = childBodyNode


if __name__ == "__main__":
pytest.main()