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

[dartpy] Add wrapper for convertToPositions() in class BallJoint #1408

Merged
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
* Added shadow technique: [#1348](https://github.com/dartsim/dart/pull/1348)
* Added findSolution and solveAndApply to InverseKinematics: [#1358](https://github.com/dartsim/dart/pull/1358)
* Added InteractiveFrame and ImGui APIs: [#1359](https://github.com/dartsim/dart/pull/1359)
* Added bindings for Joint::getTransformFrom{Parent|Child}BodyNode(): [#1377](https://github.com/dartsim/dart/pull/1377)
* Added bindings for BodyNode::getChild{BodyNode|Joint}(): [#1387](https://github.com/dartsim/dart/pull/1387)
* Added bindings for Inertia: [#1388](https://github.com/dartsim/dart/pull/1388)
* Added bindings for getting all BodyNodes from a Skeleton: [#1397](https://github.com/dartsim/dart/pull/1397)
* Added bindings for background color support in osg viewer: [#1398](https://github.com/dartsim/dart/pull/1398)
* Added bindings for BallJoint::convertToPositions(): [#1408](https://github.com/dartsim/dart/pull/1408)
* Fixed typos in Skeleton: [#1392](https://github.com/dartsim/dart/pull/1392)

* Build

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ The code doesn't need to be perfect right away, feel free to post work-in-progre
[pchorak](https://github.com/pchorak) | bug fixes
[acxz](https://github.com/acxz) | doxygen warning fix
[Addisu Taddese](https://github.com/azeey) | bug fix in ode collision detector
[Christoph Hinze](https://github.com/chhinze) | python bindings

You can find the complete contribution history in [here](https://github.com/dartsim/dart/graphs/contributors).

Expand Down
6 changes: 6 additions & 0 deletions python/dartpy/dynamics/BallJoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ void BallJoint(py::module& m)
return dart::dynamics::BallJoint::getStaticType();
},
::py::return_value_policy::reference_internal)
.def_static(
"convertToPositions",
+[](const Eigen::Matrix3d& _tf) -> Eigen::Vector3d {
return dart::dynamics::BallJoint::convertToPositions(_tf);
},
::py::arg("tf"))
.def_static(
"convertToTransform",
+[](const Eigen::Vector3d& _positions) -> Eigen::Isometry3d {
Expand Down
21 changes: 21 additions & 0 deletions python/tests/unit/dynamics/test_joint.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,26 @@ def test_access_to_parent_child_transforms():
assert np.allclose(childToJointTf.matrix(), storedChildTf.matrix())


def test_BallJoint_positions_conversion():
assert np.allclose(
dart.dynamics.BallJoint.convertToPositions(np.eye(3)),
np.zeros((1, 3))
)
assert np.allclose(
dart.dynamics.BallJoint.convertToPositions(
np.array([[0, 1, 0], [-1, 0, 0], [0, 0, 1]])),
np.array([0, 0, -np.pi/2])
)

for i in range(30):
ballJointPos = np.random.uniform(-np.pi/2, np.pi/2, 3)
assert np.allclose(
dart.dynamics.BallJoint.convertToPositions(
dart.dynamics.BallJoint.convertToRotation(ballJointPos)
),
ballJointPos
)


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