forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bind PoseBundle, FrameVelocity, PoseAggregator, SpatialVector, Spatia…
…lVelocity (RobotLocomotion#8282) * Bind PoseBundle, FrameVelocity, PoseAggregator * multibody_tree_py: Make `math` an internal submodule to avoid solib shenanigans
- Loading branch information
1 parent
67080f6
commit 383a5aa
Showing
15 changed files
with
359 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "pybind11/eigen.h" | ||
#include "pybind11/eval.h" | ||
#include "pybind11/pybind11.h" | ||
|
||
#include "drake/bindings/pydrake/pydrake_pybind.h" | ||
#include "drake/bindings/pydrake/util/eigen_geometry_pybind.h" | ||
#include "drake/multibody/multibody_tree/math/spatial_force.h" | ||
#include "drake/multibody/multibody_tree/math/spatial_vector.h" | ||
#include "drake/multibody/multibody_tree/math/spatial_velocity.h" | ||
|
||
namespace drake { | ||
namespace pydrake { | ||
|
||
void init_math(py::module m) { | ||
// NOLINTNEXTLINE(build/namespaces): Emulate placement in namespace. | ||
using namespace drake::multibody; | ||
|
||
m.doc() = "MultibodyTree math functionality."; | ||
|
||
using T = double; | ||
|
||
py::class_<SpatialVector<SpatialVelocity, T>>(m, "SpatialVector") | ||
.def("rotational", | ||
[](const SpatialVector<SpatialVelocity, T>* self) | ||
-> const Vector3<T>& { return self->rotational(); }, | ||
py_reference_internal) | ||
.def("translational", | ||
[](const SpatialVector<SpatialVelocity, T>* self) | ||
-> const Vector3<T>& { return self->translational(); }, | ||
py_reference_internal); | ||
|
||
py::class_<SpatialVelocity<T>, SpatialVector<SpatialVelocity, T>>( | ||
m, "SpatialVelocity") | ||
.def(py::init()) | ||
.def(py::init<const Eigen::Ref<const Vector3<T>>&, | ||
const Eigen::Ref<const Vector3<T>>&>(), | ||
py::arg("w"), py::arg("v")); | ||
|
||
// TODO(jadecastro, eric.cousineau): Bind additional classes as necessary. | ||
} | ||
|
||
void init_all(py::module m) { | ||
// Not sure if relative imports will work in this context, so we will | ||
// manually spell it out. | ||
py::dict vars = m.attr("__dict__"); | ||
py::exec( | ||
"from pydrake.multibody.multibody_tree.math import *", | ||
py::globals(), vars); | ||
} | ||
|
||
PYBIND11_MODULE(multibody_tree, m) { | ||
m.doc() = "MultibodyTree functionality."; | ||
|
||
// N.B. At present, we cannot have `math` as a submodule here, and in | ||
// `pydrake`. The current solution is to manually define submodules. | ||
// See the dicussion in #8282 for more information. | ||
init_math(m.def_submodule("math")); | ||
init_all(m.def_submodule("all")); | ||
} | ||
|
||
} // namespace pydrake | ||
} // namespace drake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from pydrake.multibody.multibody_tree.math import ( | ||
SpatialVelocity, | ||
) | ||
|
||
import copy | ||
import unittest | ||
import numpy as np | ||
|
||
|
||
class TestMath(unittest.TestCase): | ||
def test_spatial_velocity(self): | ||
velocity = SpatialVelocity() | ||
# - Accessors. | ||
self.assertTrue(isinstance(velocity.rotational(), np.ndarray)) | ||
self.assertTrue(isinstance(velocity.translational(), np.ndarray)) | ||
self.assertEqual(velocity.rotational().shape, (3,)) | ||
self.assertEqual(velocity.translational().shape, (3,)) | ||
# - Fully-parameterized constructor. | ||
w = [0.1, 0.3, 0.5] | ||
v = [0., 1., 2.] | ||
velocity1 = SpatialVelocity(w=w, v=v) | ||
self.assertTrue(np.allclose(velocity1.rotational(), w)) | ||
self.assertTrue(np.allclose(velocity1.translational(), v)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.