Interaction.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #include "Interaction.h"
  2. Interaction::Interaction()
  3. {
  4. rotateTrajLeft = InertialTrajProcess();
  5. rotateTrajRight = InertialTrajProcess();
  6. same_zupt_count = 0;
  7. canEnter = 0;
  8. memset(left_last_pos, 0, 3 * sizeof(float));
  9. memset(right_last_pos, 0, 3 * sizeof(float));
  10. memset(left_last_pos_tmp, 0, 3 * sizeof(float));
  11. memset(right_last_pos_tmp, 0, 3 * sizeof(float));
  12. motion_state = -1;
  13. can_report_motion_state = 0;
  14. leftFootAction = SingleFootAction(LEFT_FOOT);
  15. rightFootAction = SingleFootAction(RIGHT_FOOT);
  16. time_interval = 0;
  17. }
  18. int Interaction::get_motion_state()
  19. {
  20. return motion_state;
  21. }
  22. void Interaction::Process(int* right_pos, int* right_att, int right_zupt, int right_press,
  23. int* left_pos, int* left_att, int left_zupt, int left_press, int jump, int down, int rssi)
  24. {
  25. int right_pos_org[3]; int left_pos_org[3];
  26. memcpy(right_pos_org, right_pos, 3 * sizeof(int));
  27. memcpy(left_pos_org, left_pos, 3 * sizeof(int));
  28. if (left_zupt)
  29. {
  30. rotateTrajLeft.ResetHeading(left_att[0]);
  31. }
  32. rotateTrajLeft.TrajRotate(left_pos_org);
  33. if (right_zupt)
  34. {
  35. rotateTrajRight.ResetHeading(right_att[0]);
  36. }
  37. rotateTrajRight.TrajRotate(right_pos_org);
  38. if (left_zupt)
  39. {
  40. memcpy(left_last_pos, left_pos_org, 3 * sizeof(int));
  41. }
  42. if (right_zupt)
  43. {
  44. memcpy(right_last_pos, right_pos_org, 3 * sizeof(int));
  45. }
  46. int left_pos_tmp[3];
  47. int right_pos_tmp[3];
  48. for (int i = 0; i < 3; i++)
  49. {
  50. left_pos_tmp[i] = left_pos[i] - left_last_pos[i];
  51. right_pos_tmp[i] = right_pos[i] - right_last_pos[i];
  52. }
  53. /*
  54. if (left_zupt == 0)
  55. {
  56. cout << "left_pos: " << left_pos_tmp[0] << " " << left_pos_tmp[1] << " " << left_pos_tmp[2] << " " << endl;
  57. }*/
  58. //统计暂停信号的数量
  59. if (left_att[2] * 0.0001f < STOP_ANGLE)
  60. {
  61. left_stop_signal_count ++;
  62. }
  63. else
  64. {
  65. left_stop_signal_count = 0;
  66. }
  67. if (right_att[2] * 0.0001f < STOP_ANGLE)
  68. {
  69. right_stop_signal_count ++;
  70. }
  71. else
  72. {
  73. right_stop_signal_count = 0;
  74. }
  75. //确认键估计
  76. if (left_zupt && right_zupt)
  77. {
  78. same_zupt_count++;
  79. }
  80. else
  81. {
  82. same_zupt_count = 0;
  83. }
  84. if (jump)
  85. {
  86. canEnter = 1;
  87. }
  88. leftFootAction.run(left_pos_tmp[0], left_pos_tmp[1], left_pos_tmp[2], left_zupt, rssi, left_att[2] * 0.0001f);
  89. rightFootAction.run(right_pos_tmp[0], right_pos_tmp[1], right_pos_tmp[2], right_zupt, rssi, right_att[2] * 0.0001f);
  90. int left_motion = leftFootAction.get_interation_state();
  91. int right_motion = rightFootAction.get_interation_state();
  92. //整合两个脚的交互命令
  93. //检测到双脚跳起来,先处理,并且屏蔽left_motion, right_motion
  94. //这里有些小问题,看看测试得怎么样
  95. if (left_motion != -1)
  96. {
  97. motion_state = left_motion;
  98. std::cout << "left_motion_state is " << left_motion << endl;
  99. }
  100. if (right_motion != -1)
  101. {
  102. motion_state = right_motion;
  103. std::cout << "right_motion_state is " << right_motion << " interval second: "<< time_interval<< endl;
  104. }
  105. if (left_motion == -1 && right_motion == -1)
  106. {
  107. motion_state = -1;
  108. }
  109. if (((right_zupt == 1 && right_zupt_last == 0)|| (left_zupt == 1 && left_zupt_last == 0)) && canEnter == 1)
  110. {
  111. motion_state = MOTION_STEP;
  112. std::cout << "debug : PRESS" << std::endl;
  113. canEnter = 0;
  114. }
  115. //增加时间间隔,避免太频繁的触发指令
  116. if(motion_state != -1)
  117. {
  118. if (time_interval < 30)
  119. motion_state = -1;
  120. else
  121. time_interval = 0;
  122. }
  123. if (motion_state == -1)
  124. {
  125. time_interval++;
  126. }
  127. memcpy(left_last_pos_tmp, left_pos_tmp, 3 * sizeof(int));
  128. memcpy(right_last_pos_tmp, right_pos_tmp, 3 * sizeof(int));
  129. left_zupt_last = left_zupt;
  130. right_zupt_last = right_zupt;
  131. }