MultiBodyTreeInitCache.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #ifndef MULTIBODYTREEINITCACHE_HPP_
  2. #define MULTIBODYTREEINITCACHE_HPP_
  3. #include "../IDConfig.hpp"
  4. #include "../IDMath.hpp"
  5. #include "../MultiBodyTree.hpp"
  6. namespace btInverseDynamics
  7. {
  8. /// Mass properties of a rigid body
  9. struct InertiaData
  10. {
  11. ID_DECLARE_ALIGNED_ALLOCATOR();
  12. /// mass
  13. idScalar m_mass;
  14. /// vector from body-fixed frame to center of mass,
  15. /// in body-fixed frame, multiplied by the mass
  16. vec3 m_body_pos_body_com;
  17. /// moment of inertia w.r.t. the origin of the body-fixed
  18. /// frame, represented in that frame
  19. mat33 m_body_I_body;
  20. };
  21. /// Joint properties
  22. struct JointData
  23. {
  24. ID_DECLARE_ALIGNED_ALLOCATOR();
  25. /// type of joint
  26. JointType m_type;
  27. /// index of parent body
  28. int m_parent;
  29. /// index of child body
  30. int m_child;
  31. /// vector from parent's body-fixed frame to child's body-fixed
  32. /// frame for q=0, written in the parent's body fixed frame
  33. vec3 m_parent_pos_parent_child_ref;
  34. /// Transform matrix converting vectors written in the parent's frame
  35. /// into vectors written in the child's frame for q=0
  36. /// ie, child_vector = child_T_parent_ref * parent_vector;
  37. mat33 m_child_T_parent_ref;
  38. /// Axis of motion for 1 degree-of-freedom joints,
  39. /// written in the child's frame
  40. /// For revolute joints, the q-value is positive for a positive
  41. /// rotation about this axis.
  42. /// For prismatic joints, the q-value is positive for a positive
  43. /// translation is this direction.
  44. vec3 m_child_axis_of_motion;
  45. };
  46. /// Data structure to store data passed by the user.
  47. /// This is used in MultiBodyTree::finalize to build internal data structures.
  48. class MultiBodyTree::InitCache
  49. {
  50. public:
  51. ID_DECLARE_ALIGNED_ALLOCATOR();
  52. /// constructor
  53. InitCache();
  54. ///\copydoc MultiBodyTree::addBody
  55. int addBody(const int body_index, const int parent_index, const JointType joint_type,
  56. const vec3 &parent_r_parent_body_ref, const mat33 &body_T_parent_ref,
  57. const vec3 &body_axis_of_motion, idScalar mass, const vec3 &body_r_body_com,
  58. const mat33 &body_I_body, const int user_int, void *user_ptr);
  59. /// build index arrays
  60. /// @return 0 on success, -1 on failure
  61. int buildIndexSets();
  62. /// @return number of degrees of freedom
  63. int numDoFs() const { return m_num_dofs; }
  64. /// @return number of bodies
  65. int numBodies() const { return m_inertias.size(); }
  66. /// get inertia data for index
  67. /// @param index of the body
  68. /// @param inertia pointer for return data
  69. /// @return 0 on success, -1 on failure
  70. int getInertiaData(const int index, InertiaData *inertia) const;
  71. /// get joint data for index
  72. /// @param index of the body
  73. /// @param joint pointer for return data
  74. /// @return 0 on success, -1 on failure
  75. int getJointData(const int index, JointData *joint) const;
  76. /// get parent index array (paren_index[i] is the index of the parent of i)
  77. /// @param parent_index pointer for return data
  78. void getParentIndexArray(idArray<int>::type *parent_index) { *parent_index = m_parent_index; }
  79. /// get user integer
  80. /// @param index body index
  81. /// @param user_int user integer
  82. /// @return 0 on success, -1 on failure
  83. int getUserInt(const int index, int *user_int) const;
  84. /// get user pointer
  85. /// @param index body index
  86. /// @param user_int user pointer
  87. /// @return 0 on success, -1 on failure
  88. int getUserPtr(const int index, void **user_ptr) const;
  89. private:
  90. // vector of bodies
  91. idArray<InertiaData>::type m_inertias;
  92. // vector of joints
  93. idArray<JointData>::type m_joints;
  94. // number of mechanical degrees of freedom
  95. int m_num_dofs;
  96. // parent index array
  97. idArray<int>::type m_parent_index;
  98. // user integers
  99. idArray<int>::type m_user_int;
  100. // user pointers
  101. idArray<void *>::type m_user_ptr;
  102. // index of root body (or -1 if not set)
  103. int m_root_index;
  104. };
  105. } // namespace btInverseDynamics
  106. #endif // MULTIBODYTREEINITCACHE_HPP_