Skip to content

Commit

Permalink
MBT compile topological information (RobotLocomotion#6120)
Browse files Browse the repository at this point in the history
* Compiles BodyNodeTopology

* Updates multibody_tree_creation_tests.cc

* Adds unit tests for a complex tree topology

* Adds unit tests doc

* Adds more doc

* Addresses reviews

* Fixes gcc warning

* Addresses reviews

* Makes MBTTopology into a class

* Refactors multibody_tree_creation_tests to stop accessing private members of topology

* Makes MBTT::bodies_ private

* Makes MBTT::body_nodes_ private

* Makes MBTT::mobilizers_ private

* Makes MBTT::frames_ private

* Cleansup lint.

* Addresses reviews

* Get rid of copy-pasta
  • Loading branch information
amcastro-tri authored May 18, 2017
1 parent 7f2dee1 commit ce88092
Show file tree
Hide file tree
Showing 7 changed files with 564 additions and 101 deletions.
2 changes: 1 addition & 1 deletion drake/multibody/multibody_tree/body.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Body : public MultibodyTreeElement<Body<T>, BodyIndex> {
// At MultibodyTree::Finalize() time, each body retrieves its topology
// from the parent MultibodyTree.
void DoSetTopology(const MultibodyTreeTopology& tree_topology) final {
topology_ = tree_topology.bodies[this->get_index()];
topology_ = tree_topology.get_body(this->get_index());
body_frame_.SetTopology(tree_topology);
}

Expand Down
2 changes: 1 addition & 1 deletion drake/multibody/multibody_tree/mobilizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class Mobilizer : public MultibodyTreeElement<Mobilizer<T>, MobilizerIndex> {
// At MultibodyTree::Finalize() time, each mobilizer retrieves its topology
// from the parent MultibodyTree.
void DoSetTopology(const MultibodyTreeTopology& tree_topology) final {
topology_ = tree_topology.mobilizers[this->get_index()];
topology_ = tree_topology.get_mobilizer(this->get_index());
}

const Frame<T>& inboard_frame_;
Expand Down
7 changes: 4 additions & 3 deletions drake/multibody/multibody_tree/multibody_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ void MultibodyTree<T>::Finalize() {
"MultibodyTree.");
}

// Before performing any setup that depends on the scalar type <T>, compile
// all the type-T independent topological information.
topology_.Finalize();

// TODO(amcastro-tri): This is a brief list of operations to be added in
// subsequent PR's:
// - Finalize non-T dependent topological information.
// - Compute degrees of freedom, array sizes and any other information to
// allocate a context and request the required cache entries.
// - Setup computational structures (BodyNode based).
Expand All @@ -49,8 +52,6 @@ void MultibodyTree<T>::Finalize() {
for (const auto& mobilizer : owned_mobilizers_) {
mobilizer->SetTopology(topology_);
}

set_valid_topology();
}

// Explicitly instantiates on the most common scalar types.
Expand Down
11 changes: 4 additions & 7 deletions drake/multibody/multibody_tree/multibody_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class MultibodyTree {
const BodyType<T>& AddBody(std::unique_ptr<BodyType<T>> body) {
static_assert(std::is_convertible<BodyType<T>*, Body<T>*>::value,
"BodyType must be a sub-class of Body<T>.");
if (topology_.is_valid) {
if (topology_is_valid()) {
throw std::logic_error("This MultibodyTree is finalized already. "
"Therefore adding more bodies is not allowed. "
"See documentation for Finalize() for details.");
Expand Down Expand Up @@ -177,7 +177,7 @@ class MultibodyTree {
const FrameType<T>& AddFrame(std::unique_ptr<FrameType<T>> frame) {
static_assert(std::is_convertible<FrameType<T>*, Frame<T>*>::value,
"FrameType must be a sub-class of Frame<T>.");
if (topology_.is_valid) {
if (topology_is_valid()) {
throw std::logic_error("This MultibodyTree is finalized already. "
"Therefore adding more frames is not allowed. "
"See documentation for Finalize() for details.");
Expand Down Expand Up @@ -285,7 +285,7 @@ class MultibodyTree {
std::unique_ptr<MobilizerType<T>> mobilizer) {
static_assert(std::is_convertible<MobilizerType<T>*, Mobilizer<T>*>::value,
"MobilizerType must be a sub-class of mobilizer<T>.");
if (topology_.is_valid) {
if (topology_is_valid()) {
throw std::logic_error("This MultibodyTree is finalized already. "
"Therefore adding more bodies is not allowed. "
"See documentation for Finalize() for details.");
Expand Down Expand Up @@ -409,7 +409,7 @@ class MultibodyTree {
/// When a %MultibodyTree is instantiated, its topology remains invalid until
/// Finalize() is called, which validates the topology.
/// @see Finalize().
bool topology_is_valid() const { return topology_.is_valid; }
bool topology_is_valid() const { return topology_.is_valid(); }

/// Returns the topology information for this multibody tree. Users should not
/// need to call this method since MultibodyTreeTopology is an internal
Expand Down Expand Up @@ -440,9 +440,6 @@ class MultibodyTree {
// a method that verifies the state of the topology with a signature similar
// to RoadGeometry::CheckInvariants().

// Sets a flag indicate the topology is valid.
void set_valid_topology() { topology_.set_valid(); }

std::vector<std::unique_ptr<Body<T>>> owned_bodies_;
std::vector<std::unique_ptr<Frame<T>>> owned_frames_;
std::vector<std::unique_ptr<Mobilizer<T>>> owned_mobilizers_;
Expand Down
3 changes: 3 additions & 0 deletions drake/multibody/multibody_tree/multibody_tree_indexes.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ using BodyIndex = TypeSafeIndex<class BodyTag>;
/// Type used to identify mobilizers by index in a multibody tree system.
using MobilizerIndex = TypeSafeIndex<class MobilizerTag>;

/// Type used to identify tree nodes by index within a multibody tree system.
using BodyNodeIndex = TypeSafeIndex<class BodyNodeTag>;

/// For every MultibodyTree the **world** body _always_ has this unique index
/// and it is always zero.
// Note:
Expand Down
Loading

0 comments on commit ce88092

Please sign in to comment.