OriginTraj.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "OriginTraj.h"
  2. OriginTraj::OriginTraj()
  3. {
  4. start_traj = 0;
  5. left_zupt_count = 0;
  6. right_zupt_count = 0;
  7. leftRotate[0] = 1.0; leftRotate[1] = 0.0;
  8. leftRotate[2] = 0.0; leftRotate[3] = 1.0;
  9. rightRotate[0] = 1.0; rightRotate[1] = 0.0;
  10. rightRotate[2] = 0.0; rightRotate[3] = 1.0;
  11. memset(left_cur_pos, 0, 3 * sizeof(float));
  12. memset(right_cur_pos, 0, 3 * sizeof(float));
  13. memset(start_left_pos, 0, 3 * sizeof(float));
  14. memset(start_right_pos, 0, 3 * sizeof(float));
  15. }
  16. void OriginTraj::Process(int* right_pos, int* right_att, int right_zupt, int* left_pos, int* left_att, int left_zupt)
  17. {
  18. if (left_zupt)
  19. {
  20. left_zupt_count++;
  21. }
  22. else
  23. {
  24. left_zupt_count = 0;
  25. }
  26. if (right_zupt)
  27. {
  28. right_zupt_count++;
  29. }
  30. else
  31. {
  32. right_zupt_count = 0;
  33. }
  34. if (left_zupt_count > 50 && right_zupt_count > 50 && start_traj == 0)
  35. {
  36. float leftTheta = float(left_att[0]) * 0.0001f;
  37. float rightTheta = float(right_att[0]) * 0.0001f;
  38. leftRotate[0] = cos(leftTheta); leftRotate[1] = sin(leftTheta);
  39. leftRotate[2] = -sin(leftTheta); leftRotate[3] = cos(leftTheta);
  40. rightRotate[0] = cos(rightTheta); rightRotate[1] = sin(rightTheta);
  41. rightRotate[2] = -sin(rightTheta); rightRotate[3] = cos(rightTheta);
  42. start_traj = 1;
  43. for (int i = 0; i < 3; i++)
  44. {
  45. start_left_pos[i] = left_pos[i] * 0.01f;
  46. start_right_pos[i] = right_pos[i] * 0.01f;
  47. }
  48. std::cout << "CAN PLOT TRAJ" << std::endl;
  49. }
  50. if (start_traj == 1)
  51. {
  52. float left_pos_tmp[3];
  53. float right_pos_tmp[3];
  54. for (int i = 0; i < 3; i++)
  55. {
  56. left_pos_tmp[i] = left_pos[i] * 0.01f - start_left_pos[i];
  57. right_pos_tmp[i] = right_pos[i] * 0.01f - start_right_pos[i];
  58. }
  59. left_cur_pos[0] = leftRotate[0] * left_pos_tmp[0] + leftRotate[1] * left_pos_tmp[1] ;
  60. left_cur_pos[1] = leftRotate[2] * left_pos_tmp[0] + leftRotate[3] * left_pos_tmp[1] ;
  61. left_cur_pos[2] = left_pos_tmp[2];
  62. right_cur_pos[0] = rightRotate[0] * right_pos_tmp[0] + rightRotate[1] * right_pos_tmp[1];
  63. right_cur_pos[1] = rightRotate[2] * right_pos_tmp[0] + rightRotate[3] * right_pos_tmp[1];
  64. right_cur_pos[2] = right_pos_tmp[2];
  65. memcpy(left_pos_tmp, left_cur_pos, 3 * sizeof(float));
  66. memcpy(right_pos_tmp, right_cur_pos, 3 * sizeof(float));
  67. left_cur_pos[0] = 0.991444861 * left_pos_tmp[0] - 0.13052619 * left_pos_tmp[1];
  68. left_cur_pos[1] = 0.13052619 * left_pos_tmp[0] + 0.991444861 * left_pos_tmp[1];
  69. right_cur_pos[0] = 0.991444861 * right_pos_tmp[0] + 0.13052619 * right_pos_tmp[1];
  70. right_cur_pos[1] = -0.13052619 * right_pos_tmp[0] + 0.991444861 * right_pos_tmp[1];
  71. }
  72. }
  73. float OriginTraj::getGamePos(int left_or_right, int index)
  74. {
  75. if (index < 0 || index > 2)
  76. return -1;
  77. if (left_or_right == LEFT_FOOT)
  78. {
  79. return left_cur_pos[index];
  80. }
  81. else
  82. return right_cur_pos[index];
  83. }