H5.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include "H5.h"
  2. #include <string.h>
  3. //last_jump and now_jump need wait 200ms
  4. #define WAIT_TIME 10
  5. H5::H5()
  6. {
  7. memset(resultMatrix, -1, 4 * sizeof(int));
  8. last_left_zupt = 1;
  9. last_right_zupt = 1;
  10. CANCLE_DOWN = 0;
  11. CANCLE_JUMP = 0;
  12. valid_down_wait_time = 0;
  13. valid_jump_wait_time = 0;
  14. last_jump = 0;
  15. last_down = 0;
  16. }
  17. void H5::Process(int* right_pos, int* right_att, int* right_acc, int right_zupt, int right_press,
  18. int* left_pos, int* left_att, int* left_acc, int left_zupt, int left_press,
  19. int jump, int down, int rssi)
  20. {
  21. //»ñÈ¡´¥µØ
  22. if (last_left_zupt == 0 && left_zupt == 1)
  23. {
  24. resultMatrix[0] = MOTION_LEFT;
  25. }
  26. else
  27. {
  28. resultMatrix[0] = -1;
  29. }
  30. if (last_right_zupt == 0 && right_zupt == 1)
  31. {
  32. resultMatrix[1] = MOTION_RIGHT;
  33. }
  34. else
  35. {
  36. resultMatrix[1] = -1;
  37. }
  38. //filter down jump
  39. if (last_jump == 0 && jump == 1)
  40. {
  41. resultMatrix[2] = MOTION_JUMP;
  42. valid_jump_wait_time = WAIT_TIME;
  43. }
  44. else
  45. {
  46. resultMatrix[2] = -1;
  47. }
  48. //reset jump wait time when both foot isn't on the floor
  49. if ((valid_jump_wait_time > 0 && left_zupt == 0 && right_zupt == 0) || jump == 1)
  50. {
  51. valid_jump_wait_time = WAIT_TIME;
  52. }
  53. if (valid_jump_wait_time > 0)
  54. {
  55. CANCLE_JUMP == 1;
  56. valid_jump_wait_time--;
  57. }
  58. else
  59. {
  60. CANCLE_JUMP = 0;
  61. }
  62. //same process with jump
  63. if (last_down == 0 && down == 1 && CANCLE_DOWN == 0)
  64. {
  65. resultMatrix[3] = MOTION_DOWN;
  66. valid_down_wait_time = WAIT_TIME;
  67. }
  68. else
  69. {
  70. resultMatrix[3] = -1;
  71. }
  72. if ((valid_jump_wait_time > 0) || down == 1)
  73. {
  74. valid_down_wait_time = WAIT_TIME;
  75. }
  76. if (valid_down_wait_time > 0)
  77. {
  78. CANCLE_DOWN = 1;
  79. valid_down_wait_time--;
  80. }
  81. else
  82. {
  83. CANCLE_DOWN = 0;
  84. }
  85. last_left_zupt = left_zupt;
  86. last_right_zupt = right_zupt;
  87. last_jump = jump;
  88. last_down = down;
  89. }
  90. void H5::getResult(int* dec)
  91. {
  92. memcpy(dec, resultMatrix, 4 * sizeof(int));
  93. }