FootStep.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include "FootStep.h"
  2. FootStep::FootStep()
  3. {
  4. /*
  5. 初始化均为0
  6. */
  7. stepStatus = 0;
  8. stepFreq = 0;
  9. stepTag = 0;
  10. zuptCount = 0;
  11. lastZupt = 1;
  12. leaveFloorTime1 = 0;
  13. leaveFloorTime2 = 0;
  14. leaveTimeStatus = 1;
  15. catchFloorTime = 0;
  16. localTime = 0;
  17. last_time_stamp = 0;
  18. stepCount = 0;
  19. memset(last_pos, 0, 3 * sizeof(int));
  20. }
  21. void FootStep::stepCal(int timeStamp, int pos[3], int zupt)
  22. {
  23. //计算累计的时间
  24. static int stepFreqBuff[5];
  25. static int buffIndex;
  26. if (zupt)
  27. {
  28. memcpy(last_pos, pos, 3 * sizeof(int));
  29. }
  30. int pos_tmp[3];
  31. for (int i = 0; i < 3; i++)
  32. {
  33. pos_tmp[i] = pos[i] - last_pos[i];
  34. }
  35. int timeDistance;
  36. if (timeStamp - last_time_stamp < 0)
  37. {
  38. timeDistance = 256 + timeStamp - last_time_stamp;
  39. }
  40. else
  41. {
  42. timeDistance = timeStamp - last_time_stamp;
  43. }
  44. last_time_stamp = timeStamp;
  45. localTime += timeDistance;
  46. if (pos_tmp[0] * pos_tmp[0] + pos_tmp[1] * pos_tmp[1] + pos_tmp[2] * pos_tmp[2] > 0)
  47. {
  48. stepTag = 1;
  49. }
  50. if (lastZupt == 0 && zupt == 1 && stepTag == 1 )
  51. {
  52. int walkTime = 8 * (localTime - leaveFloorTime1);
  53. // 模块发过来的频率为40ms发一次,所以一秒能发25次,
  54. //所以计算步频的话一分钟除以walkTime 再除以一个2
  55. stepFreq = 60 * 1000 / walkTime;
  56. leaveFloorTime1 = localTime;
  57. stepTag = 0;
  58. stepCount++;
  59. }
  60. lastZupt = zupt;
  61. if (zupt == 1)
  62. zuptCount++;
  63. else
  64. zuptCount = 0;
  65. if (zuptCount > 50)
  66. {
  67. stepStatus = 0;
  68. stepFreq = 0;
  69. stepTag = 0;
  70. }
  71. }
  72. int FootStep::getStepFreq()
  73. {
  74. return stepFreq;
  75. }
  76. int FootStep::getStepStatus()
  77. {
  78. if (stepFreq == 0)
  79. return 0;
  80. else if (stepFreq > 130)
  81. return 2;
  82. else
  83. return 1;
  84. }
  85. int FootStep::getStepCount()
  86. {
  87. return stepCount;
  88. }