Drake
body.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <vector>
5 
12 
13 namespace drake {
14 namespace multibody {
15 
16 // Forward declaration for BodyFrame<T>.
17 template<typename T> class Body;
18 
54 template <typename T>
55 class BodyFrame : public Frame<T> {
56  public:
58 
60  const systems::Context<T>&) const final {
61  return Isometry3<T>::Identity();
62  }
63 
65  const systems::Context<T>&,
66  const Isometry3<T>& X_FQ) const final {
67  return X_FQ;
68  }
69 
70  private:
71  // Body<T> and BodyFrame<T> are natural allies. A BodyFrame object is created
72  // every time a Body object is created and they are associated with each
73  // other.
74  friend class Body<T>;
75 
76  // Only Body objects can create BodyFrame objects since Body is a friend of
77  // BodyFrame.
78  explicit BodyFrame(const Body<T>& body) : Frame<T>(body) {}
79 };
80 
81 // Forward declarations for Body<T>.
82 template<typename T> class MultibodyTree;
83 
85 // Internal implementation details. Users should not access implementations
86 // in this namespace.
87 namespace internal {
88 template <typename T>
89 // Attorney-Client idiom to grant MultibodyTree access to a selected set of
90 // private methods in Body.
91 // BodyAttorney serves as a "proxy" to the Body class but only providing an
92 // interface to a selected subset of methods that should be accessible to
93 // MultibodyTree. These methods are related to the construction and finalize
94 // stage of the multibody system.
95 class BodyAttorney {
96  private:
97  // MultibodyTree keeps a list of mutable pointers to each of the body frames
98  // in the system and therefore it needs mutable access.
99  // Notice this method is private and therefore users do not have access to it
100  // even in the rare event they'd attempt to peek into the "internal::"
101  // namespace.
102  static BodyFrame<T>& get_mutable_body_frame(Body<T>* body) {
103  return body->get_mutable_body_frame();
104  }
105  friend class MultibodyTree<T>;
106 };
107 } // namespace internal
109 
122 template <typename T>
123 class Body : public MultibodyTreeElement<Body<T>, BodyIndex> {
124  public:
126 
127 
128  Body() : body_frame_(*this) {}
129 
132  virtual int get_num_flexible_positions() const = 0;
133 
136  virtual int get_num_flexible_velocities() const = 0;
137 
139  const BodyFrame<T>& get_body_frame() const {
140  return body_frame_;
141  }
142 
146  return topology_.body_node;
147  }
148 
157  virtual SpatialInertia<T> CalcSpatialInertiaInBodyFrame(
158  const MultibodyTreeContext<T>& context) const = 0;
159 
160  private:
161  // Only friends of BodyAttorney (i.e. MultibodyTree) have access to a selected
162  // set of private Body methods.
163  friend class internal::BodyAttorney<T>;
164 
165  // Implementation for MultibodyTreeElement::DoSetTopology().
166  // At MultibodyTree::Finalize() time, each body retrieves its topology
167  // from the parent MultibodyTree.
168  void DoSetTopology(const MultibodyTreeTopology& tree_topology) final {
169  topology_ = tree_topology.get_body(this->get_index());
170  body_frame_.SetTopology(tree_topology);
171  }
172 
173  // MultibodyTree has access to the mutable BodyFrame through BodyAttorney.
174  BodyFrame<T>& get_mutable_body_frame() {
175  return body_frame_;
176  }
177 
178  // Body frame associated with this body.
179  BodyFrame<T> body_frame_;
180 
181  // The internal bookkeeping topology struct used by MultibodyTree.
182  BodyTopology topology_;
183 };
184 
185 } // namespace multibody
186 } // namespace drake
Eigen::Transform< Scalar, 3, Eigen::Isometry > Isometry3
An Isometry templated on scalar type.
Definition: eigen_types.h:98
MultibodyTreeContext is an object that contains all the information needed to uniquely determine the ...
Definition: multibody_tree_context.h:40
NOTE: The contents of this class are for the most part direct ports of drake/systems/plants//inverseK...
Definition: automotive_demo.cc:88
Data structure to store the topological information associated with a Body.
Definition: multibody_tree_topology.h:38
BodyFrame(const BodyFrame &)=delete
Context is an abstract base class template that represents all the inputs to a System: time...
Definition: query_handle.h:10
Body provides the general abstraction of a body with an API that makes no assumption about whether a ...
Definition: body.h:17
MultibodyTree provides a representation for a physical system consisting of a collection of interconn...
Definition: body.h:82
BodyNodeIndex get_node_index() const
Returns the index of the node in the underlying tree structure of the parent MultibodyTree to which t...
Definition: body.h:145
const BodyFrame< T > & get_body_frame() const
Returns a const reference to the associated BodyFrame.
Definition: body.h:139
A BodyFrame is a material Frame that serves as the unique reference frame for a Body.
Definition: body.h:55
Frame is an abstract class representing a material frame (also called a physical frame), meaning that it is associated with a material point of a Body.
Definition: frame.h:38
Isometry3< T > CalcPoseInBodyFrame(const systems::Context< T > &) const final
Returns the pose X_BF of this frame F in the body frame B associated with this frame.
Definition: body.h:59
Data structure to store the topological information associated with an entire MultibodyTree.
Definition: multibody_tree_topology.h:259
This file defines the topological structures which represent the logical connectivities between multi...
This class represents the physical concept of a Spatial Inertia.
Definition: spatial_inertia.h:87
#define DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(Classname)
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN deletes the special member functions for copy-construction, copy-assignment, move-construction, and move-assignment.
Definition: drake_copyable.h:35
Isometry3< T > CalcOffsetPoseInBody(const systems::Context< T > &, const Isometry3< T > &X_FQ) const final
Given the offset pose X_FQ of a frame Q in this frame F, this method computes the pose X_BQ of frame ...
Definition: body.h:64
Provides careful macros to selectively enable or disable the special member functions for copy-constr...