CoilCreator.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <cmath>
  2. #include "CoilCreator.hpp"
  3. namespace btInverseDynamics
  4. {
  5. CoilCreator::CoilCreator(int n) : m_num_bodies(n), m_parent(n)
  6. {
  7. for (int i = 0; i < m_num_bodies; i++)
  8. {
  9. m_parent[i] = i - 1;
  10. }
  11. // DH parameters (that's what's in the paper ...)
  12. const idScalar theta_DH = 0;
  13. const idScalar d_DH = 0.0;
  14. const idScalar a_DH = 1.0 / m_num_bodies;
  15. const idScalar alpha_DH = 5.0 * BT_ID_PI / m_num_bodies;
  16. getVecMatFromDH(theta_DH, d_DH, a_DH, alpha_DH, &m_parent_r_parent_body_ref,
  17. &m_body_T_parent_ref);
  18. // always z-axis
  19. m_body_axis_of_motion(0) = 0.0;
  20. m_body_axis_of_motion(1) = 0.0;
  21. m_body_axis_of_motion(2) = 1.0;
  22. m_mass = 1.0 / m_num_bodies;
  23. m_body_r_body_com(0) = 1.0 / (2.0 * m_num_bodies);
  24. m_body_r_body_com(1) = 0.0;
  25. m_body_r_body_com(2) = 0.0;
  26. m_body_I_body(0, 0) = 1e-4 / (2.0 * m_num_bodies);
  27. m_body_I_body(0, 1) = 0.0;
  28. m_body_I_body(0, 2) = 0.0;
  29. m_body_I_body(1, 0) = 0.0;
  30. m_body_I_body(1, 1) = (3e-4 + 4.0 / BT_ID_POW(m_num_bodies, 2)) / (12.0 * m_num_bodies);
  31. m_body_I_body(1, 2) = 0.0;
  32. m_body_I_body(2, 0) = 0.0;
  33. m_body_I_body(2, 1) = 0.0;
  34. m_body_I_body(2, 2) = m_body_I_body(1, 1);
  35. }
  36. CoilCreator::~CoilCreator() {}
  37. int CoilCreator::getNumBodies(int* num_bodies) const
  38. {
  39. *num_bodies = m_num_bodies;
  40. return 0;
  41. }
  42. int CoilCreator::getBody(int body_index, int* parent_index, JointType* joint_type,
  43. vec3* parent_r_parent_body_ref, mat33* body_T_parent_ref,
  44. vec3* body_axis_of_motion, idScalar* mass, vec3* body_r_body_com,
  45. mat33* body_I_body, int* user_int, void** user_ptr) const
  46. {
  47. if (body_index < 0 || body_index >= m_num_bodies)
  48. {
  49. bt_id_error_message("invalid body index %d\n", body_index);
  50. return -1;
  51. }
  52. *parent_index = m_parent[body_index];
  53. *joint_type = REVOLUTE;
  54. *parent_r_parent_body_ref = m_parent_r_parent_body_ref;
  55. *body_T_parent_ref = m_body_T_parent_ref;
  56. *body_axis_of_motion = m_body_axis_of_motion;
  57. *mass = m_mass;
  58. *body_r_body_com = m_body_r_body_com;
  59. *body_I_body = m_body_I_body;
  60. *user_int = 0;
  61. *user_ptr = 0;
  62. return 0;
  63. }
  64. } // namespace btInverseDynamics