jumpH5.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #include "jumpH5.h"
  2. void jumpH5::Process(int* right_pos, int* right_att, int right_zupt, int* left_pos, int* left_att, int left_zupt, int jump, int time_s, int rssi)
  3. {
  4. static int right_stand_count = 0;
  5. static int left_stand_count = 0;
  6. int right_pos_offset[3];
  7. int left_pos_offset[3];
  8. memset(H5_result, 0, 4 * sizeof(int));
  9. for (int i = 0; i < 3; i++)
  10. {
  11. right_pos_offset[i] = right_pos[i] - last_right_pos[i];
  12. left_pos_offset[i] = left_pos[i] - last_left_pos[i];
  13. }
  14. if (fabs(right_pos_offset[2]) < 2 && right_att[2] == 1 && right_att[0] != 1)
  15. {
  16. right_zupt = 1;
  17. }
  18. if (fabs(left_pos_offset[2]) < 2 && left_att[2] == 1 && left_att[0] != 1)
  19. {
  20. left_zupt = 1;
  21. }
  22. if ((right_zupt == 0 && left_zupt == 0) &&(fabs(right_pos_offset[2]) > 0 && fabs(left_pos_offset[2]) > 0))
  23. {
  24. report_tag = 1;
  25. }
  26. //当左右脚都不是贴地面,输出高度,同时统计时间
  27. if (report_tag == 1)
  28. {
  29. int jump_time = time_s - not_on_floor_time;
  30. if (time_s - not_on_floor_time < 0)
  31. {
  32. jump_time += 256;
  33. }
  34. int high = 0;
  35. if (abs(left_pos_offset[2]) < abs(right_pos_offset[2]))
  36. {
  37. high = left_pos_offset[2] > 0 ? left_pos_offset[2] : 0;
  38. }
  39. else
  40. {
  41. high = right_pos_offset[2] > 0 ? right_pos_offset[2] : 0;
  42. }
  43. std::cout << "空中持续时间: " << jump_time << "/ms" << ",高度为: "<< high << endl;
  44. H5_result[0] = 3; H5_result[1] = high; H5_result[2] = jump_time;
  45. }
  46. else
  47. {
  48. not_on_floor_time = time_s;
  49. }
  50. //添加一个计时器,用以探测所有触发点,来判断是否触底
  51. if (left_zupt == 1 && last_left_zupt == 0 && left_wait_time == 0)
  52. {
  53. left_wait_time = 5;
  54. memcpy(left_pos_wait, left_pos_offset, 3 * sizeof(int));
  55. }
  56. if (right_zupt == 1 && last_right_zupt == 0 && right_wait_time == 0)
  57. {
  58. right_wait_time = 5;
  59. memcpy(right_pos_wait, right_pos_offset, 3 * sizeof(int));
  60. }
  61. if ((left_wait_time > 0 && right_wait_time > 0) && report_tag == 1)
  62. {
  63. //证明双脚踏地, 暂时双脚踏地了,输出双个格子
  64. if (next_result_wait == 0)
  65. {
  66. std::cout << "dual foot on floor" << std::endl;
  67. next_result_wait = 5;
  68. int distance_rssi = 0;
  69. //利用rssi来判断距离,太近,近, 适中, 远,很远 的等级
  70. if (rssi < 20)
  71. {
  72. std::cout << "双脚接地 距离过近" << endl;
  73. distance_rssi = 0;
  74. }
  75. else if (rssi < 25)
  76. {
  77. std::cout << "双脚接地,距离稍微近" << endl;
  78. distance_rssi = 1;
  79. }
  80. else if (rssi < 30)
  81. {
  82. std::cout << "双脚接地,距离合适" << endl;
  83. distance_rssi = 2;
  84. }
  85. else if (rssi < 35)
  86. {
  87. std::cout << "双脚接地,距离稍微远" << endl;
  88. distance_rssi = 3;
  89. }
  90. else
  91. {
  92. std::cout << "双脚接地,距离过远" << endl;
  93. distance_rssi = 4;
  94. }
  95. H5_result[0] = 1; H5_result[1] = distance_rssi;
  96. }
  97. left_wait_time = 0;
  98. right_wait_time = 0;
  99. report_tag = 0;
  100. }
  101. else if (left_wait_time == 0 && left_zupt == 1 && right_zupt == 0 && report_tag == 1 )
  102. {
  103. if (next_result_wait == 0)
  104. {
  105. std::cout << "only left foot on floor" << std::endl;
  106. next_result_wait = 5;
  107. H5_result[0] = 2;
  108. H5_result[1] = 1;
  109. }
  110. report_tag = 0;
  111. }
  112. else if (right_wait_time == 0 && right_zupt == 1 && left_zupt == 0 && report_tag == 1)
  113. {
  114. if (next_result_wait == 0)
  115. {
  116. std::cout << "only right foot on floor" << std::endl;
  117. next_result_wait = 5;
  118. H5_result[0] = 2;
  119. H5_result[1] = 2;
  120. }
  121. report_tag = 0;
  122. }
  123. //计算偏移量, 检测到left_zupt
  124. if(left_zupt == 1)
  125. memcpy(last_left_pos, left_pos, 3 * sizeof(int));
  126. if (right_zupt == 1)
  127. memcpy(last_right_pos, right_pos, 3 * sizeof(int));
  128. if (left_wait_time > 0)
  129. {
  130. left_wait_time--;
  131. }
  132. if (right_wait_time > 0)
  133. {
  134. right_wait_time--;
  135. }
  136. if (next_result_wait > 0)
  137. {
  138. next_result_wait--;
  139. }
  140. last_right_zupt = right_zupt;
  141. last_left_zupt = left_zupt;
  142. }
  143. void jumpH5::getResult(int* result)
  144. {
  145. memcpy(result, H5_result, 4 * sizeof(int));
  146. }