CoilCreator.cpp 2.2 KB

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