SingleFootAction.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #include "SingleFootAction.h"
  2. void SingleFootAction::run(int x, int y, int z,int zupt, int rssi, float pitch)
  3. {
  4. report_siganl_listen(last_z);
  5. pause_signal_listen(pitch);
  6. direction_signal_listen(last_x, last_y, zupt, rssi);
  7. set_motion_signal(zupt);
  8. last_zupt = zupt;
  9. last_x = x; last_y = y; last_z = z;
  10. }
  11. int SingleFootAction::get_interation_state()
  12. {
  13. return interation_state;
  14. }
  15. void SingleFootAction::set_motion_signal(int zupt )
  16. {
  17. if (pause_signal_count >= 200)
  18. {
  19. if (pause_signal == 1)
  20. {
  21. interation_state = MOTION_STOP;
  22. }
  23. else
  24. {
  25. interation_state = -1;
  26. }
  27. }
  28. else
  29. {
  30. if (last_zupt == 0 && zupt == 1 && can_report_motion)
  31. {
  32. interation_state = direction_signal;
  33. can_report_motion = 0;
  34. }
  35. else
  36. {
  37. interation_state = -1;
  38. }
  39. }
  40. }
  41. void SingleFootAction::direction_signal_listen(int x, int y, int zupt, int rssi)
  42. {
  43. float x_offset = x;
  44. float y_offset = y;
  45. float len_offset = sqrt(x_offset * x_offset + y_offset * y_offset);
  46. if (last_zupt == 0 && zupt == 1)
  47. {
  48. if (left_or_right == RIGHT_FOOT)
  49. {
  50. std::cout << "debug "<<"x: " << x << " y: " << y << endl;
  51. }
  52. if (rssi < 30)
  53. {
  54. direction_signal = -1;
  55. }
  56. else if (len_offset < 15.f)
  57. {
  58. return;
  59. }
  60. else
  61. {
  62. float angle = atan2(y_offset, x_offset);
  63. if (left_or_right == LEFT_FOOT)
  64. {
  65. if (angle > PI * 3 / 4 || angle < -PI * 3 / 4)
  66. {
  67. direction_signal = MOTION_LEFT;
  68. }
  69. else if (angle < PI * 3 / 4 && angle >PI / 4)
  70. {
  71. direction_signal = MOTION_FRONT;
  72. }
  73. else if (angle > -PI * 3 / 4 && angle < -PI / 4)
  74. {
  75. direction_signal = MOTION_BACK;
  76. }
  77. else
  78. {
  79. direction_signal = -1;
  80. }
  81. }
  82. else
  83. {
  84. if (angle < PI / 4 && angle > -PI / 4)
  85. {
  86. direction_signal = MOTION_RIGHT;
  87. }
  88. else if (angle < PI * 3 / 4 && angle >PI / 4)
  89. {
  90. direction_signal = MOTION_FRONT;
  91. }
  92. else if (angle > -PI * 3 / 4 && angle < -PI / 4)
  93. {
  94. direction_signal = MOTION_BACK;
  95. }
  96. else
  97. {
  98. direction_signal = -1;
  99. }
  100. }
  101. }
  102. }
  103. }
  104. void SingleFootAction::report_siganl_listen(int z)
  105. {
  106. if (z > 1)
  107. {
  108. can_report_motion = 1;
  109. }
  110. }
  111. void SingleFootAction::pause_signal_listen(float pitch)
  112. {
  113. if (pitch < STOP_ANGLE)
  114. {
  115. pause_signal_count++;
  116. }
  117. else
  118. {
  119. pause_signal_count = 0;
  120. }
  121. if (pause_signal_count == 200)
  122. {
  123. pause_signal = 1;
  124. }
  125. else
  126. {
  127. pause_signal = 0;
  128. }
  129. }