Parasol Planning Library (PPL)
MultiBody.h
Go to the documentation of this file.
1 #ifndef PMPL_MULTI_BODY_H_
2 #define PMPL_MULTI_BODY_H_
3 
4 #include <memory>
5 #include <string>
6 #include <vector>
7 
8 #include "Geometry/Bodies/Body.h"
10 
11 class Boundary;
12 class Cfg;
13 class Connection;
14 class XMLNode;
15 
16 #ifdef DEBUG_BULLET_PROBLEMS
17 class btMultiBody;
18 #endif
19 
20 
24 enum class DofType {
25  Positional,
26  Rotational,
27  Joint
28 };
29 
30 
34 struct DofInfo final {
35 
38 
44  DofInfo(std::string&& _n, const DofType _type, const Range<double> _range) :
45  name(_n), type(_type), range(_range) {}
46 
50 
51  std::string name;
54 
56 
57 };
58 
59 
65 class MultiBody {
66 
67  public:
68 
69 #ifdef DEBUG_BULLET_PROBLEMS
74  btMultiBody* m_bullet{nullptr};
75 #endif
76 
79 
81  enum class Type {
82  Active,
83  Passive,
84  Internal
85  };
86 
87 
91 
94  MultiBody(const MultiBody::Type _type);
95 
97  MultiBody(XMLNode& _node);
98 
99  MultiBody(const MultiBody&);
100  MultiBody(MultiBody&&);
101 
103 
106  void InitializeDOFs(const Boundary* const _b);
107 
111 
112  MultiBody& operator=(const MultiBody&);
114 
118 
120  MultiBody::Type GetType() const noexcept;
121 
123  bool IsActive() const noexcept;
124 
126  bool IsPassive() const noexcept;
127 
129  bool IsInternal() const noexcept;
130 
135  bool IsComposite() const noexcept;
136 
138  size_t DOF() const noexcept;
139 
141  size_t PosDOF() const noexcept;
142 
144  size_t OrientationDOF() const noexcept;
145 
147  size_t JointDOF() const noexcept;
148 
150  const std::vector<double>& GetCurrentDOFs() const noexcept;
151 
153  std::vector<double> GetCurrentCfg() noexcept;
154 
158 
160  size_t GetNumBodies() const noexcept;
161 
163  const std::vector<Body>& GetBodies() const noexcept;
164 
167  std::vector<const Body*> GetEndEffectors() const noexcept;
168 
171  Body* GetBody(const size_t _i) noexcept;
172  const Body* GetBody(const size_t _i) const noexcept;
173 
177  size_t AddBody(Body&& _body);
178 
180  Body* GetBase() noexcept;
181  const Body* GetBase() const noexcept;
182 
185  void SetBaseBody(const size_t _index);
186 
188  Body::Type GetBaseType() const noexcept;
189 
191  Body::MovementType GetBaseMovementType() const noexcept;
192 
194  double GetWeight() const;
195 
199 
201  const Vector3d& GetCenterOfMass() const noexcept;
202 
204  double GetBoundingSphereRadius() const noexcept;
205 
209 
211  const std::vector<std::unique_ptr<Connection>>& GetJoints() const noexcept;
212 
215  Connection* GetJoint(const size_t _i) noexcept;
216 
218  const DofType& GetDOFType(const size_t _i) const noexcept;
219 
221  const std::vector<DofInfo>& GetDofInfo() const noexcept;
222 
226  void UpdateJointLimits() noexcept;
227 
231 
234  void Configure(const Cfg& _c);
235 
238  void Configure(const std::vector<double>& _v);
239 
245 
249 
253  void Read(std::istream& _is, CountingStreamBuffer& _cbs);
254 
257  void Write(std::ostream& _os) const;
258 
260 
261  private:
262 
265 
267  void SortJoints();
268 
271  void UpdateLinks();
272 
279  void FindMultiBodyInfo();
280 
284  Transformation GenerateBaseTransformation(const std::vector<double>& _v)
285  const;
286 
290 
291  Type m_multiBodyType{Type::Passive};
292 
293  std::vector<Body> m_bodies;
294 
295  double m_radius{0};
296 
297  size_t m_baseIndex{0};
298  Body* m_baseBody{nullptr};
299  Body::Type m_baseType;
300  Body::MovementType m_baseMovement;
301 
302  std::vector<std::unique_ptr<Connection>> m_joints;
303 
304  std::vector<DofInfo> m_dofInfo;
305  std::vector<double> m_currentDofs;
306 
308 };
309 
310 #endif
DofType
Types of movement that are supported.
Definition: MultiBody.h:24
@ Rotational
Rotational motion in S = [-1, 1].
@ Joint
Rotational motion in R = [min, max].
@ Positional
Translational motion R = [min, max].
Definition: Body.h:41
Type
The type of part this body represents within its owning multi body.
Definition: Body.h:49
MovementType
The type of movement this body can perform.
Definition: Body.h:57
Definition: Boundary.h:30
Definition: Cfg.h:38
Definition: Connection.h:35
Definition: CountingStreamBuffer.h:20
Definition: MultiBody.h:65
size_t GetNumBodies() const noexcept
Get the number of bodies in this multibody.
Definition: MultiBody.cpp:383
size_t AddBody(Body &&_body)
Definition: MultiBody.cpp:424
double GetWeight() const
Get the weight of the MultiBody.
Definition: MultiBody.cpp:483
std::vector< double > GetCurrentCfg() noexcept
Get the current configuration dofs (no velocity), as set by Configure().
Definition: MultiBody.cpp:325
double GetBoundingSphereRadius() const noexcept
Get the bounding sphere radius.
Definition: MultiBody.cpp:508
bool IsPassive() const noexcept
Is this MultiBody a non-active type?
Definition: MultiBody.cpp:259
const Vector3d & GetCenterOfMass() const noexcept
Get the center of mass.
Definition: MultiBody.cpp:495
void InitializeDOFs(const Boundary *const _b)
Definition: MultiBody.cpp:127
size_t DOF() const noexcept
Get the number of DOF for this multibody.
Definition: MultiBody.cpp:280
bool IsComposite() const noexcept
Definition: MultiBody.cpp:273
const std::vector< double > & GetCurrentDOFs() const noexcept
Get the current DOFs for this configuration, as set by Configure().
Definition: MultiBody.cpp:318
const DofType & GetDOFType(const size_t _i) const noexcept
Get the DOF type for a specific degree of freedom.
Definition: MultiBody.cpp:530
Body * GetBody(const size_t _i) noexcept
Definition: MultiBody.cpp:410
const std::vector< std::unique_ptr< Connection > > & GetJoints() const noexcept
Get the Connections in this multibody.
Definition: MultiBody.cpp:516
Body * GetBase() noexcept
Get the base body.
Definition: MultiBody.cpp:441
bool IsActive() const noexcept
Is this MultiBody an active type?
Definition: MultiBody.cpp:252
MultiBody(const MultiBody::Type _type)
Definition: MultiBody.cpp:58
const std::vector< DofInfo > & GetDofInfo() const noexcept
Get the DOF info for a specific degree of freedom.
Definition: MultiBody.cpp:537
MultiBody & operator=(const MultiBody &)
Copy.
Definition: MultiBody.cpp:184
Body::MovementType GetBaseMovementType() const noexcept
Get the movement type of the base body.
Definition: MultiBody.cpp:477
Type
The types of MultiBody that we can support.
Definition: MultiBody.h:81
@ Active
Movable object.
@ Internal
Static invisible object.
@ Passive
Static visible object.
void UpdateJointLimits() noexcept
Definition: MultiBody.cpp:544
void Configure(const Cfg &_c)
Definition: MultiBody.cpp:569
std::vector< const Body * > GetEndEffectors() const noexcept
Definition: MultiBody.cpp:397
void PushToNearestValidConfiguration()
Definition: MultiBody.cpp:612
size_t OrientationDOF() const noexcept
Get the number of orientational DOF for this multibody's base.
Definition: MultiBody.cpp:301
size_t PosDOF() const noexcept
Get the number of positional DOF for this multibody's base.
Definition: MultiBody.cpp:287
size_t JointDOF() const noexcept
Get the number of joint DOF for this multibody.
Definition: MultiBody.cpp:311
void Write(std::ostream &_os) const
Definition: MultiBody.cpp:707
const std::vector< Body > & GetBodies() const noexcept
Get all of the internal bodies.
Definition: MultiBody.cpp:390
void Read(std::istream &_is, CountingStreamBuffer &_cbs)
Definition: MultiBody.cpp:632
Connection * GetJoint(const size_t _i) noexcept
Definition: MultiBody.cpp:523
bool IsInternal() const noexcept
Is this MultiBody an internal type?
Definition: MultiBody.cpp:266
MultiBody::Type GetType() const noexcept
Get the type for this MultiBody.
Definition: MultiBody.cpp:245
void SetBaseBody(const size_t _index)
Definition: MultiBody.cpp:455
Body::Type GetBaseType() const noexcept
Get the body type of the base body.
Definition: MultiBody.cpp:470
Definition: XMLNode.h:27
Information of DOF values: name, minimum value, and maximum value.
Definition: MultiBody.h:34
DofInfo(std::string &&_n, const DofType _type, const Range< double > _range)
Definition: MultiBody.h:44
std::string name
DOF name.
Definition: MultiBody.h:51
DofType type
DOF type.
Definition: MultiBody.h:52
Range< double > range
Range of allowed values.
Definition: MultiBody.h:53