BigFoot.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include "pub.h"
  2. #include "BigFoot.h"
  3. BigFoot::BigFoot()
  4. {
  5. memset(result, 0, 4 * sizeof(int));
  6. memset(left_min_acc, 0, 3 * sizeof(int));
  7. memset(left_max_acc, 0, 3 * sizeof(int));
  8. memset(right_min_acc, 0, 3 * sizeof(int));
  9. memset(right_max_acc, 0, 3 * sizeof(int));
  10. last_left_zupt = 1;
  11. last_right_zupt = 1;
  12. }
  13. int BigFoot::station_acc(int* max_acc, int* min_acc)
  14. {
  15. for (int i = 0; i < 3; i++)
  16. {
  17. if (max_acc[i] - min_acc[i] > 1024)
  18. {
  19. return 0;
  20. }
  21. }
  22. return 1;
  23. }
  24. void BigFoot::getResult(int* matrix)
  25. {
  26. memcpy(matrix, result, 4 * sizeof(int));
  27. }
  28. void BigFoot::Process(int* right_pos, int* right_att, int* right_acc, int right_zupt, int right_press,
  29. int* left_pos, int* left_att, int* left_acc, int left_zupt, int left_press,
  30. int jump, int down, int girl_shoes)
  31. {
  32. //需要用加速度过滤伪触地,如果期间是小于0.5g的则视为伪触地,过滤掉
  33. //station_acc 判断方法
  34. if (left_zupt && last_left_zupt == 0 && !station_acc(left_max_acc, left_min_acc))
  35. //if (left_zupt && last_left_zupt == 0 )
  36. {
  37. result[0] = 1;
  38. std::cout << "左脚踩了" << std::endl;
  39. }
  40. else
  41. {
  42. result[0] = 0;
  43. }
  44. if (right_zupt && last_right_zupt == 0 && !station_acc(right_max_acc, right_min_acc))
  45. {
  46. result[1] = 1;
  47. std::cout << "右脚踩了" << std::endl;
  48. }
  49. else
  50. {
  51. result[1] = 0;
  52. }
  53. last_left_zupt = left_zupt;
  54. last_right_zupt = right_zupt;
  55. if (left_zupt)
  56. {
  57. memcpy(left_min_acc, left_acc, 3 * sizeof(int));
  58. memcpy(left_max_acc, left_acc, 3 * sizeof(int));
  59. }
  60. else
  61. {
  62. for (int i = 0; i < 3; i++)
  63. {
  64. if (left_min_acc[i] > left_acc[i])
  65. {
  66. left_min_acc[i] = left_acc[i];
  67. }
  68. if (left_max_acc[i] < left_acc[i])
  69. {
  70. left_max_acc[i] = left_acc[i];
  71. }
  72. }
  73. }
  74. if (right_zupt)
  75. {
  76. memcpy(right_min_acc, right_acc, 3 * sizeof(int));
  77. memcpy(right_max_acc, right_acc, 3 * sizeof(int));
  78. }
  79. else
  80. {
  81. for (int i = 0; i < 3; i++)
  82. {
  83. if (right_min_acc[i] > right_acc[i])
  84. {
  85. right_min_acc[i] = right_acc[i];
  86. }
  87. if (right_max_acc[i] < right_acc[i])
  88. {
  89. right_max_acc[i] = right_acc[i];
  90. }
  91. }
  92. }
  93. }